Skip to content

Commit cba58fc

Browse files
JustinStittkees
authored andcommitted
isdn: kcapi: replace deprecated strncpy with strscpy_pad
`strncpy` is deprecated for use on NUL-terminated destination strings [1] and as such we should prefer more robust and less ambiguous string interfaces. `buf` is used in this context as a data buffer with 64 bytes of memory to be occupied by capi_manufakturer. We see the caller capi20_get_manufacturer() passes data.manufacturer as its `buf` argument which is then later passed over to user space. Due to this, let's keep the NUL-padding that strncpy provided by using strscpy_pad so as to not leak any stack data. | cdev->errcode = capi20_get_manufacturer(data.contr, data.manufacturer); | if (cdev->errcode) | return -EIO; | | if (copy_to_user(argp, data.manufacturer, | sizeof(data.manufacturer))) | return -EFAULT; Perhaps this would also be a good instance to use `strtomem_pad` for but in my testing the compiler was not able to determine the size of `buf` -- even with all the hints. Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1] Link: KSPP#90 Cc: linux-hardening@vger.kernel.org Signed-off-by: Justin Stitt <justinstitt@google.com> Reviewed-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/r/20230922-strncpy-drivers-isdn-capi-kcapi-c-v1-1-55fcf8b075fb@google.com Signed-off-by: Kees Cook <keescook@chromium.org>
1 parent 5c80c4f commit cba58fc

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/isdn/capi/kcapi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,15 +732,15 @@ u16 capi20_get_manufacturer(u32 contr, u8 buf[CAPI_MANUFACTURER_LEN])
732732
u16 ret;
733733

734734
if (contr == 0) {
735-
strncpy(buf, capi_manufakturer, CAPI_MANUFACTURER_LEN);
735+
strscpy_pad(buf, capi_manufakturer, CAPI_MANUFACTURER_LEN);
736736
return CAPI_NOERROR;
737737
}
738738

739739
mutex_lock(&capi_controller_lock);
740740

741741
ctr = get_capi_ctr_by_nr(contr);
742742
if (ctr && ctr->state == CAPI_CTR_RUNNING) {
743-
strncpy(buf, ctr->manu, CAPI_MANUFACTURER_LEN);
743+
strscpy_pad(buf, ctr->manu, CAPI_MANUFACTURER_LEN);
744744
ret = CAPI_NOERROR;
745745
} else
746746
ret = CAPI_REGNOTINSTALLED;

0 commit comments

Comments
 (0)