ovl: Fix use inode directly in rcu-walk mode
PATCH 1/1 ovl: Fix use inode directly in rcu-walk mode
syzkaller reported a null-ptr-deref error:
https://syzkaller.appspot.com/bug?id=bb281e89381b9ed55728c274447a575e69a96c35
ovl_dentry_revalidate_common() can be called in rcu-walk mode. As document said, "in rcu-walk mode, d_parent and d_inode should not be used without care". Check inode here to protect access under rcu-walk mode.
--- fs/overlayfs/super.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
fs/overlayfs/super.c +9 -1
@@ -139,11 +139,19 @@ static int ovl_dentry_revalidate_common(struct dentry *dentry, unsigned int flags, bool weak) {struct ovl_entry *oe = dentry->d_fsdata; +struct inode *inode;struct dentry *upper;unsigned int i;int ret =1 ; - upper =ovl_dentry_upper (dentry); +if (flags &LOOKUP_RCU ) { + inode =d_inode_rcu (dentry); +if (!inode) +return -ECHILD ; + upper =ovl_upperdentry_dereference (OVL_I (inode)); + }else + upper =ovl_dentry_upper (dentry); +if (upper) ret =ovl_revalidate_real (upper, flags, weak);
Signature · 1 line
2.17.1
Miklos Szeredi
maintainerQuoted 11 lines · Chen Zhongjin
syzkaller reported a null-ptr-deref error:
https://syzkaller.appspot.com/bug?id=bb281e89381b9ed55728c274447a575e69a96c35
ovl_dentry_revalidate_common()can be called in rcu-walk mode. As document said, "in rcu-walk mode,d_parentandd_inodeshould not be used without care". Check inode here to protect access under rcu-walk mode.Fixes bccece1ead36 ("ovl: allow remote upper")Reported-by [email protected]Signed-off-by Chen Zhongjin <[email protected]>
Hi,
Thanks for the quick analysis and patch.
I simplified the patch a bit without changing the attribution.
Thanks,
Miklos
----
From: Chen Zhongjin <[email protected]>
Subject: ovl: fix use inode directly in rcu-walk mode
ovl_dentry_revalidate_common() can be called in rcu-walk mode. As document said, "in rcu-walk mode, d_parent and d_inode should not be used without care".
Check inode here to protect access under rcu-walk mode.
--- fs/overlayfs/super.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
fs/overlayfs/super.c +6 -1
@@ -139,11 +139,16 @@ static int ovl_dentry_revalidate_common( unsigned int flags, bool weak) {struct ovl_entry *oe = dentry->d_fsdata; +struct inode *inode =d_inode_rcu (dentry);struct dentry *upper;unsigned int i;int ret =1 ; - upper =ovl_dentry_upper (dentry); +/* Careful in RCU mode */ +if (!inode) +return -ECHILD ; + + upper =ovl_i_dentry_upper (inode);if (upper) ret =ovl_revalidate_real (upper, flags, weak);
Quoted 50 lines · Miklos Szeredi
Quoted 11 lines · Chen Zhongjin
syzkaller reported a null-ptr-deref error:
https://syzkaller.appspot.com/bug?id=bb281e89381b9ed55728c274447a575e69a96c35
ovl_dentry_revalidate_common()can be called in rcu-walk mode. As document said, "in rcu-walk mode,d_parentandd_inodeshould not be used without care". Check inode here to protect access under rcu-walk mode.Fixes bccece1ead36 ("ovl: allow remote upper")Reported-by [email protected]Signed-off-by Chen Zhongjin <[email protected]>Hi,
Thanks for the quick analysis and patch.
I simplified the patch a bit without changing the attribution.
Thanks,
Miklos----
From: Chen Zhongjin <[email protected]>
Subject: ovl: fix use inode directly in rcu-walk mode
ovl_dentry_revalidate_common()can be called in rcu-walk mode. As document said, "in rcu-walk mode,d_parentandd_inodeshould not be used without care".Check inode here to protect access under rcu-walk mode.
Fixes bccece1ead36 ("ovl: allow remote upper")Reported-by [email protected]Signed-off-by Chen Zhongjin <[email protected]>Cc <[email protected]> # v5.7Signed-off-by Miklos Szeredi <[email protected]>--- fs/overlayfs/super.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)fs/overlayfs/super.c +1
-0@@ -139,11 +139,16 @@ static int ovl_dentry_revalidate_common( unsigned int flags, bool weak) {struct ovl_entry *oe = dentry->d_fsdata; +struct inode *inode =d_inode_rcu (dentry);struct dentry *upper;unsigned int i;int ret =1 ;
fs/overlayfs/super.c static int ovl_dentry_revalidate_common( · line 154
Quoted 10 lines
fs/overlayfs/super.c +5
-1- upper =ovl_dentry_upper (dentry); +/* Careful in RCU mode */ +if (!inode) +return -ECHILD ; + + upper =ovl_i_dentry_upper (inode);if (upper) ret =ovl_revalidate_real (upper, flags, weak);
Thanks for review! LGTM
Best,
Chen