Skip to content

Commit 7611b33

Browse files
azeemshaikh38Russell King (Oracle)
authored andcommitted
ARM: 9300/1: Replace all non-returning strlcpy with strscpy
strlcpy() reads the entire source buffer first. This read may exceed the destination size limit. This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated [1]. In an effort to remove strlcpy() completely [2], replace strlcpy() here with strscpy(). No return values were used, so direct replacement is safe. [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy [2] KSPP#89 [ardb: submitting to the patch tracker on behalf of Azeem] Signed-off-by: Azeem Shaikh <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Reviewed-by: Kees Cook <[email protected]> Signed-off-by: Ard Biesheuvel <[email protected]> Signed-off-by: Russell King (Oracle) <[email protected]>
1 parent ddbb7ea commit 7611b33

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

arch/arm/kernel/atags_parse.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ static int __init parse_tag_cmdline(const struct tag *tag)
127127
#elif defined(CONFIG_CMDLINE_FORCE)
128128
pr_warn("Ignoring tag cmdline (using the default kernel command line)\n");
129129
#else
130-
strlcpy(default_command_line, tag->u.cmdline.cmdline,
130+
strscpy(default_command_line, tag->u.cmdline.cmdline,
131131
COMMAND_LINE_SIZE);
132132
#endif
133133
return 0;
@@ -224,7 +224,7 @@ setup_machine_tags(void *atags_vaddr, unsigned int machine_nr)
224224
}
225225

226226
/* parse_early_param needs a boot_command_line */
227-
strlcpy(boot_command_line, from, COMMAND_LINE_SIZE);
227+
strscpy(boot_command_line, from, COMMAND_LINE_SIZE);
228228

229229
return mdesc;
230230
}

arch/arm/kernel/setup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,7 @@ void __init setup_arch(char **cmdline_p)
11421142
setup_initial_init_mm(_text, _etext, _edata, _end);
11431143

11441144
/* populate cmd_line too for later use, preserving boot_command_line */
1145-
strlcpy(cmd_line, boot_command_line, COMMAND_LINE_SIZE);
1145+
strscpy(cmd_line, boot_command_line, COMMAND_LINE_SIZE);
11461146
*cmdline_p = cmd_line;
11471147

11481148
early_fixmap_init();

arch/arm/kernel/vdso.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ static Elf32_Sym * __init find_symbol(struct elfinfo *lib, const char *symname)
135135

136136
if (lib->dynsym[i].st_name == 0)
137137
continue;
138-
strlcpy(name, lib->dynstr + lib->dynsym[i].st_name,
138+
strscpy(name, lib->dynstr + lib->dynsym[i].st_name,
139139
MAX_SYMNAME);
140140
c = strchr(name, '@');
141141
if (c)

0 commit comments

Comments
 (0)