Skip to content

Commit bbe70e4

Browse files
XidianGeneralgregkh
authored andcommitted
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>
1 parent 2fd60da commit bbe70e4

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎fs/kernfs/dir.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,17 @@ static int kernfs_path_from_node_locked(struct kernfs_node *kn_to,
137137
if (kn_from == kn_to)
138138
return strlcpy(buf, "/", buflen);
139139

140+
if (!buf)
141+
return -EINVAL;
142+
140143
common = kernfs_common_ancestor(kn_from, kn_to);
141144
if (WARN_ON(!common))
142145
return -EINVAL;
143146

144147
depth_to = kernfs_depth(common, kn_to);
145148
depth_from = kernfs_depth(common, kn_from);
146149

147-
if (buf)
148-
buf[0] = '\0';
150+
buf[0] = '\0';
149151

150152
for (i = 0; i < depth_from; i++)
151153
len += strlcpy(buf + len, parent_str,

0 commit comments

Comments
 (0)