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
137 if (kn_from == kn_to)137 if (kn_from == kn_to)
138 return strlcpy(buf, "/", buflen);138 return strlcpy(buf, "/", buflen);
139 139
140 if (!buf)
141 return -EINVAL;
142
140 common = kernfs_common_ancestor(kn_from, kn_to);143 common = kernfs_common_ancestor(kn_from, kn_to);
141 if (WARN_ON(!common))144 if (WARN_ON(!common))
142 return -EINVAL;145 return -EINVAL;
@@ -144,8 +147,7 @@ static int kernfs_path_from_node_locked(struct kernfs_node *kn_to, · 1 unmodified line
144 depth_to = kernfs_depth(common, kn_to);147 depth_to = kernfs_depth(common, kn_to);
145 depth_from = kernfs_depth(common, kn_from);148 depth_from = kernfs_depth(common, kn_from);
146 149
147 if (buf)150 buf[0] = '\0';
148 buf[0] = '\0';
149 151
150 for (i = 0; i < depth_from; i++)152 for (i = 0; i < depth_from; i++)
151 len += strlcpy(buf + len, parent_str,153 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