Skip to contentSkip to conversation

fs: kernfs: fix possible null pointer dereferences

PATCH In review youngjun 2 participants 2 messages Apr 30, 2020 – May 6, 2020 kernfs

lore
Share & tools
lore

youngjun

author
#0 lore raw

PATCH 1/1 fs: kernfs: fix possible null pointer dereferences

kernfs_path_from_node_locked checks buf is NULL.
But, two cases below are not covered.

if(!kn_to) <--- case1 (buf can be NULL)

	return strlcpy(buf, "(null)", buflen);

if(kn_from == kn_to) <--- case2 (buf can be NULL)

	return strlcpy(buf, "/", buflen);

if (!buf) <--- checked here.

	return -EINVAL;

buf NULL case needs to be checked first.

---
 fs/kernfs/dir.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/kernfs/dir.c +3 -3
index 02fb5cc76e33..d802cfceddba 100644
@@ -128,6 +128,9 @@ static int kernfs_path_from_node_locked(struct kernfs_node *kn_to,
 	size_t depth_from, depth_to, len = 0;
 	int i, j;
 
+	if (!buf)
+		return -EINVAL;
+
 	if (!kn_to)
 		return strlcpy(buf, "(null)", buflen);
 
@@ -137,9 +140,6 @@ static int kernfs_path_from_node_locked(struct kernfs_node *kn_to,
 	if (kn_from == kn_to)
 		return strlcpy(buf, "/", buflen);
 
-	if (!buf)
-		return -EINVAL;
-
 	common = kernfs_common_ancestor(kn_from, kn_to);
 	if (WARN_ON(!common))
 		return -EINVAL;
Signature · 1 line
2.17.1
#1 lore raw
Quoted 10 lines · youngjun

kernfs_path_from_node_locked checks buf is NULL.
But, two cases below are not covered.

if(!kn_to) <--- case1 (buf can be NULL)

	return strlcpy(buf, "(null)", buflen);

if(kn_from == kn_to) <--- case2 (buf can be NULL)

	return strlcpy(buf, "/", buflen);

if (!buf) <--- checked here.

Quoted 8 lines
	return -EINVAL;

buf NULL case needs to be checked first.

---
 fs/kernfs/dir.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

I have 3 patches here from you, with the same subject lines, yet they do different things.

I'm dropping them all, can you please resend a patch series of the remaining patches you wish us to review for kernfs?

thanks,

greg k-h