mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] kernfs: fix possibility of NULL pointer dereference. (mount.c)
@ 2020-04-27 17:32 youngjun
  0 siblings, 0 replies; only message in thread
From: youngjun @ 2020-04-27 17:32 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Tejun Heo, linux-kernel, youngjun

mount.c also uses "kernfs_dentry_node".
When dentry is negative, "kernfs_dentry_node" returns NULL.
In this case, "kernfs_root" dereferences NULL pointer.

Signed-off-by: youngjun <her0gyugyu@gmail.com>
---
 fs/kernfs/mount.c | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/fs/kernfs/mount.c b/fs/kernfs/mount.c
index 9dc7e7a64e10..cd49cb936681 100644
--- a/fs/kernfs/mount.c
+++ b/fs/kernfs/mount.c
@@ -23,19 +23,33 @@ struct kmem_cache *kernfs_node_cache, *kernfs_iattrs_cache;
 
 static int kernfs_sop_show_options(struct seq_file *sf, struct dentry *dentry)
 {
-	struct kernfs_root *root = kernfs_root(kernfs_dentry_node(dentry));
-	struct kernfs_syscall_ops *scops = root->syscall_ops;
+	struct kernfs_node *node = kernfs_dentry_node(dentry);
+	struct kernfs_root *root;
+	struct kernfs_syscall_ops *scops;
+
+	if (node) {
+		root = kernfs_root(node);
+		scops = root->syscall_ops;
+	} else
+		return 0;
 
 	if (scops && scops->show_options)
 		return scops->show_options(sf, root);
+
 	return 0;
 }
 
 static int kernfs_sop_show_path(struct seq_file *sf, struct dentry *dentry)
 {
 	struct kernfs_node *node = kernfs_dentry_node(dentry);
-	struct kernfs_root *root = kernfs_root(node);
-	struct kernfs_syscall_ops *scops = root->syscall_ops;
+	struct kernfs_root *root;
+	struct kernfs_syscall_ops *scops;
+
+	if (node) {
+		root = kernfs_root(node);
+		scops = root->syscall_ops;
+	} else
+		return 0;
 
 	if (scops && scops->show_path)
 		return scops->show_path(sf, node, root);
@@ -138,6 +152,9 @@ static struct dentry *kernfs_get_parent_dentry(struct dentry *child)
 {
 	struct kernfs_node *kn = kernfs_dentry_node(child);
 
+	if (!kn)
+		return NULL;
+
 	return d_obtain_alias(kernfs_get_inode(child->d_sb, kn->parent));
 }
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-04-27 17:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-27 17:32 [PATCH] kernfs: fix possibility of NULL pointer dereference. (mount.c) youngjun

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®