linux-stable/drivers/isdn/capi
Justin Stitt cba58fcbc4 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: https://github.com/KSPP/linux/issues/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>
2023-10-02 11:07:02 -07:00
..
capi.c tty: make tty_operations::write()'s count size_t 2023-08-11 21:12:46 +02:00
capiutil.c isystem: ship and use stdarg.h 2021-08-19 09:02:55 +09:00
kcapi.c isdn: kcapi: replace deprecated strncpy with strscpy_pad 2023-10-02 11:07:02 -07:00
kcapi.h isdn: capi: dead code removal 2019-12-11 09:12:38 +01:00
kcapi_proc.c proc: mandate ->proc_lseek in "struct proc_ops" 2021-05-06 19:24:11 -07:00
Kconfig isdn/capi: Replace HTTP links with HTTPS ones 2020-07-13 17:25:35 -07:00
Makefile isdn: capi: dead code removal 2019-12-11 09:12:38 +01:00