mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-28 07:13:34 +00:00
fs: kernfs: Fix possible null-pointer dereferences in kernfs_path_from_node_locked()
In kernfs_path_from_node_locked(), there is an if statement on line 147 to check whether buf is NULL: if (buf) When buf is NULL, it is used on line 151: len += strlcpy(buf + len, parent_str, ...) and line 158: len += strlcpy(buf + len, "/", ...) and line 160: len += strlcpy(buf + len, kn->name, ...) Thus, possible null-pointer dereferences may occur. To fix these possible bugs, buf is checked before being used. If it is NULL, -EINVAL is returned. These bugs are found by a static analysis tool STCheck written by us. Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com> Link: https://lore.kernel.org/r/20190724022242.27505-1-baijiaju1990@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
2fd60da46d
commit
bbe70e4e42
1 changed files with 4 additions and 2 deletions
|
@ -137,6 +137,9 @@ static int kernfs_path_from_node_locked(struct kernfs_node *kn_to,
|
||||||
if (kn_from == kn_to)
|
if (kn_from == kn_to)
|
||||||
return strlcpy(buf, "/", buflen);
|
return strlcpy(buf, "/", buflen);
|
||||||
|
|
||||||
|
if (!buf)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
common = kernfs_common_ancestor(kn_from, kn_to);
|
common = kernfs_common_ancestor(kn_from, kn_to);
|
||||||
if (WARN_ON(!common))
|
if (WARN_ON(!common))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
@ -144,7 +147,6 @@ static int kernfs_path_from_node_locked(struct kernfs_node *kn_to,
|
||||||
depth_to = kernfs_depth(common, kn_to);
|
depth_to = kernfs_depth(common, kn_to);
|
||||||
depth_from = kernfs_depth(common, kn_from);
|
depth_from = kernfs_depth(common, kn_from);
|
||||||
|
|
||||||
if (buf)
|
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
|
|
||||||
for (i = 0; i < depth_from; i++)
|
for (i = 0; i < depth_from; i++)
|
||||||
|
|
Loading…
Reference in a new issue