Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 9dd12ed

Browse files
JustinStittkees
authored andcommitted
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 e6584c3 ("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: KSPP/linux#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>
1 parent 39cd87c commit 9dd12ed

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

fs/pstore/blk.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ static int __register_pstore_blk(struct pstore_device_info *dev,
241241
/* get information of pstore/blk */
242242
int pstore_blk_get_config(struct pstore_blk_config *info)
243243
{
244-
strncpy(info->device, blkdev, 80);
244+
strscpy(info->device, blkdev);
245245
info->max_reason = max_reason;
246246
info->kmsg_size = check_size(kmsg_size, 4096);
247247
info->pmsg_size = check_size(pmsg_size, 4096);

0 commit comments

Comments
 (0)