History

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.

Jia-Ju Bai committed 7 years ago

Commit bbe70e41 parent 2fd60da1 file · +4 −2Browse files

Unified · Split

fs/kernfs/dir.c+4−2
@@ -137,6 +137,9 @@ static int kernfs_path_from_node_locked(struct kernfs_node *kn_to, · 136 unmodified lines
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;
@@ -144,8 +147,7 @@ static int kernfs_path_from_node_locked(struct kernfs_node *kn_to, · 1 unmodified line
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,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t