linux/fs/pstore
Justin Stitt 9dd12ed95c pstore/blk: replace deprecated strncpy with strscpy
strncpy() is deprecated for use on NUL-terminated destination strings
[1] and as such we should prefer more robust and less ambiguous string
interfaces.

We know that info-device should be NUL-terminated based on its use with
strlen():
|	static int __init mtdpstore_init(void)
|	{
|		int ret;
|		struct mtdpstore_context *cxt = &oops_cxt;
|		struct pstore_blk_config *info = &cxt->info;
|
|		ret = pstore_blk_get_config(info);
|		if (unlikely(ret))
|			return ret;
|
|		if (strlen(info->device) == 0) {
|			pr_err("mtd device must be supplied (device name is empty)\n");
...

Considering the above, a suitable replacement is `strscpy` [2] due to
the fact that it guarantees NUL-termination on the destination buffer.

Note that this patch relies on the _new_ 2-argument version of strscpy()
introduced in Commit e6584c3964 ("string: Allow 2-argument strscpy()").

Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1]
Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2]
Link: https://github.com/KSPP/linux/issues/90
Cc:  <linux-hardening@vger.kernel.org>
Signed-off-by: Justin Stitt <justinstitt@google.com>
Link: https://lore.kernel.org/r/20240328-strncpy-fs-pstore-blk-c-v1-1-5748cdc22a53@google.com
Signed-off-by: Kees Cook <keescook@chromium.org>
2024-04-11 09:37:26 -07:00
..
blk.c pstore/blk: replace deprecated strncpy with strscpy 2024-04-11 09:37:26 -07:00
ftrace.c pstore/ftrace: Allow immediate recording 2021-11-18 10:29:52 -08:00
inode.c pstore: inode: Only d_invalidate() is needed 2024-02-22 10:37:21 -08:00
internal.h pstore: Move kmsg_bytes default into Kconfig 2020-12-01 12:09:17 -08:00
Kconfig pstore: Replace crypto API compression with zlib_deflate library calls 2023-07-17 16:08:58 -07:00
Makefile pstore/blk: Introduce backend for block devices 2020-05-30 10:34:03 -07:00
platform.c pstore/platform: Add check for kstrdup 2023-10-12 09:47:01 -07:00
pmsg.c pstore update for v6.4-rc1 2023-04-27 17:03:40 -07:00
ram_core.c pstore: ram_core: fix possible overflow in persistent_ram_init_ecc() 2023-12-08 14:15:00 -08:00
ram_internal.h pstore/ram: Set freed addresses to NULL 2022-10-19 09:25:39 -07:00
ram.c pstore/ram: Register to module device table 2024-02-22 10:37:21 -08:00
zone.c pstore/zone: Don't clear memory twice 2024-03-09 12:33:22 -08:00