* [PATCH] kernfs: fix possibility of NULL pointer dereference.
@ 2020-04-27 16:48 youngjun
2020-04-27 17:31 ` Greg Kroah-Hartman
0 siblings, 1 reply; 2+ messages in thread
From: youngjun @ 2020-04-27 16:48 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: Tejun Heo, linux-kernel, youngjun
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] kernfs: fix possibility of NULL pointer dereference.
2020-04-27 16:48 [PATCH] kernfs: fix possibility of NULL pointer dereference youngjun
@ 2020-04-27 17:31 ` Greg Kroah-Hartman
0 siblings, 0 replies; 2+ messages in thread
From: Greg Kroah-Hartman @ 2020-04-27 17:31 UTC (permalink / raw)
To: youngjun; +Cc: Tejun Heo, linux-kernel
On Mon, Apr 27, 2020 at 09:48:36AM -0700, youngjun wrote:
> 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(-)
And how can this be triggered on a kernfs filesystem?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-04-27 17:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-27 16:48 [PATCH] kernfs: fix possibility of NULL pointer dereference youngjun
2020-04-27 17:31 ` Greg Kroah-Hartman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox