Skip to content

Commit ad5f0eb

Browse files
JustinStittakpm00
authored andcommitted
vmcore: replace strncpy with strscpy_pad
strncpy() is in the process of being replaced as it is deprecated [1]. We should move towards safer and less ambiguous string interfaces. Looking at vmcoredd_header's definition: | struct vmcoredd_header { | __u32 n_namesz; /* Name size */ | __u32 n_descsz; /* Content size */ | __u32 n_type; /* NT_VMCOREDD */ | __u8 name[8]; /* LINUX\0\0\0 */ | __u8 dump_name[VMCOREDD_MAX_NAME_BYTES]; /* Device dump's name */ | }; .. we see that @name wants to be NUL-padded. We're copying data->dump_name which is defined as: | char dump_name[VMCOREDD_MAX_NAME_BYTES]; /* Unique name of the dump */ .. which shares the same size as vdd_hdr->dump_name. Let's make sure we NUL-pad this as well. Use strscpy_pad() which NUL-terminates and NUL-pads its destination buffers. Specifically, use the new 2-argument version of strscpy_pad 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: KSPP#90 Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Justin Stitt <[email protected]> Acked-by: Baoquan He <[email protected]> Cc: Dave Young <[email protected]> Cc: Vivek Goyal <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 3cc98aa commit ad5f0eb

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

fs/proc/vmcore.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,9 +1370,8 @@ static void vmcoredd_write_header(void *buf, struct vmcoredd_data *data,
13701370
vdd_hdr->n_descsz = size + sizeof(vdd_hdr->dump_name);
13711371
vdd_hdr->n_type = NT_VMCOREDD;
13721372

1373-
strncpy((char *)vdd_hdr->name, VMCOREDD_NOTE_NAME,
1374-
sizeof(vdd_hdr->name));
1375-
memcpy(vdd_hdr->dump_name, data->dump_name, sizeof(vdd_hdr->dump_name));
1373+
strscpy_pad(vdd_hdr->name, VMCOREDD_NOTE_NAME);
1374+
strscpy_pad(vdd_hdr->dump_name, data->dump_name);
13761375
}
13771376

13781377
/**

0 commit comments

Comments
 (0)