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.
Date: Mon, 27 Apr 2020 09:48:36 -0700 [thread overview]
Message-ID: <20200427164836.48765-1-her0gyugyu@gmail.com> (raw)
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/dir.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
index 9aec80b9d7c6..02fb5cc76e33 100644
--- a/fs/kernfs/dir.c
+++ b/fs/kernfs/dir.c
@@ -1133,15 +1133,16 @@ static int kernfs_iop_mkdir(struct inode *dir, struct dentry *dentry,
static int kernfs_iop_rmdir(struct inode *dir, struct dentry *dentry)
{
struct kernfs_node *kn = kernfs_dentry_node(dentry);
- struct kernfs_syscall_ops *scops = kernfs_root(kn)->syscall_ops;
+ struct kernfs_syscall_ops *scops;
int ret;
- if (!scops || !scops->rmdir)
- return -EPERM;
-
if (!kernfs_get_active(kn))
return -ENODEV;
+ scops = kernfs_root(kn)->syscall_ops;
+ if (!scops || !scops->rmdir)
+ return -EPERM;
+
ret = scops->rmdir(kn);
kernfs_put_active(kn);
@@ -1154,18 +1155,19 @@ static int kernfs_iop_rename(struct inode *old_dir, struct dentry *old_dentry,
{
struct kernfs_node *kn = kernfs_dentry_node(old_dentry);
struct kernfs_node *new_parent = new_dir->i_private;
- struct kernfs_syscall_ops *scops = kernfs_root(kn)->syscall_ops;
+ struct kernfs_syscall_ops *scops;
int ret;
if (flags)
return -EINVAL;
- if (!scops || !scops->rename)
- return -EPERM;
-
if (!kernfs_get_active(kn))
return -ENODEV;
+ scops = kernfs_root(kn)->syscall_ops;
+ if (!scops || !scops->rename)
+ return -EPERM;
+
if (!kernfs_get_active(new_parent)) {
kernfs_put_active(kn);
return -ENODEV;
--
2.17.1
next reply other threads:[~2020-04-27 16:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-27 16:48 youngjun [this message]
2020-04-27 17:31 ` [PATCH] kernfs: fix possibility of NULL pointer dereference Greg Kroah-Hartman
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=20200427164836.48765-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