summaryrefslogtreecommitdiffstats
path: root/scripts/dtc/treesource.c
diff options
context:
space:
mode:
authorVivek Goyal <vgoyal@redhat.com>2021-09-17 09:13:23 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2021-09-19 22:24:49 -0400
commitb51593c4cd739dff7fc40bbed368572d98b19ae8 (patch)
tree434f93e808826013066d174613e5efcffe1740b0 /scripts/dtc/treesource.c
parente4e737bb5c170df6135a127739a9e6148ee3da82 (diff)
downloadlinux-b51593c4cd739dff7fc40bbed368572d98b19ae8.tar.bz2
init/do_mounts.c: Harden split_fs_names() against buffer overflow
split_fs_names() currently takes comma separate list of filesystems and converts it into individual filesystem strings. Pleaces these strings in the input buffer passed by caller and returns number of strings. If caller manages to pass input string bigger than buffer, then we can write beyond the buffer. Or if string just fits buffer, we will still write beyond the buffer as we append a '\0' byte at the end. Pass size of input buffer to split_fs_names() and put enough checks in place so such buffer overrun possibilities do not occur. This patch does few things. - Add a parameter "size" to split_fs_names(). This specifies size of input buffer. - Use strlcpy() (instead of strcpy()) so that we can't go beyond buffer size. If input string "names" is larger than passed in buffer, input string will be truncated to fit in buffer. - Stop appending extra '\0' character at the end and avoid one possibility of going beyond the input buffer size. - Do not use extra loop to count number of strings. - Previously if one passed "rootfstype=foo,,bar", split_fs_names() will return only 1 string "foo" (and "bar" will be truncated due to extra ,). After this patch, now split_fs_names() will return 3 strings ("foo", zero-sized-string, and "bar"). Callers of split_fs_names() have been modified to check for zero sized string and skip to next one. Reported-by: xu xin <xu.xin16@zte.com.cn> Signed-off-by: Vivek Goyal <vgoyal@redhat.com> Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'scripts/dtc/treesource.c')
0 files changed, 0 insertions, 0 deletions