mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: youngjun <her0gyugyu@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Tejun Heo <tj@kernel.org>,
	linux-kernel@vger.kernel.org, youngjun <her0gyugyu@gmail.com>
Subject: [PATCH] kernfs: fix possibility of NULL pointer dereference. (mount.c)
Date: Mon, 27 Apr 2020 10:32:02 -0700	[thread overview]
Message-ID: <20200427173202.49626-1-her0gyugyu@gmail.com> (raw)

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


                 reply	other threads:[~2020-04-27 17:32 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200427173202.49626-1-her0gyugyu@gmail.com \
    --to=her0gyugyu@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®