fs: reiserfs: xattr: Fix null pointer derefernce in open_xa_root()
PATCH 1/1 fs: reiserfs: xattr: Fix null pointer derefernce in open_xa_root()
d_really_is_negative() checks for the dentry->d_inode whether it's NULL or not, but in open_xa_root(), when it checks 'privroot->d_inode', it doesn't check whether privroot is NULL or not, this leads to a null pointer dereference while calling it from open_xa_dir() while initializing xaroot.
- fs/reiserfs/xattr.c
The bug seems to get triggered at this line:
if (d_really_is_negative(privroot))
return ERR_PTR(-EOPNOTSUPP);
Fix it by adding a NULL check for privroot.
--- fs/reiserfs/xattr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/reiserfs/xattr.c +2 -1
@@ -121,8 +121,9 @@ static struct dentry *open_xa_root(struct super_block *sb, int flags)struct dentry *privroot =REISERFS_SB (sb)->priv_root;struct dentry *xaroot; -if (d_really_is_negative (privroot)) +if (!privroot ||d_really_is_negative (privroot)) {return ERR_PTR (-EOPNOTSUPP ); + }inode_lock_nested (d_inode (privroot),I_MUTEX_XATTR );
Signature · 1 line
2.28.0
Quoted 9 lines · Anmol Karn
d_really_is_negative()checks for thedentry->d_inodewhether it's NULL or not, but inopen_xa_root(), when it checks 'privroot->d_inode', it doesn't check whether privroot is NULL or not, this leads to a null pointer dereference while calling it fromopen_xa_dir()while initializing xaroot.-
fs/reiserfs/xattr.c
The bug seems to get triggered at this line:
Quoted 8 lines
if (
d_really_is_negative(privroot))return ERR_PTR(-EOPNOTSUPP);Fix it by adding a NULL check for privroot.
Reported-and-tested-by [email protected]Signed-off-by Anmol Karn <[email protected]>
Thanks for the patch! I've already fixed the problem myself (slightly differently) but I'll comment about your patch below for educational purposes :). See
https://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs.git/commit/?h=for_next&id=c2bb80b8bdd04dfe32364b78b61b6a47f717af52
fs/reiserfs/xattr.c static struct dentry *open_xa_root(struct super_block *sb, int flags) · line 125
Quoted 11 lines
fs/reiserfs/xattr.c +1
-1@@ -121,8 +121,9 @@ static struct dentry *open_xa_root(struct super_block *sb, int flags)struct dentry *privroot =REISERFS_SB (sb)->priv_root;struct dentry *xaroot; -if (d_really_is_negative (privroot)) +if (!privroot ||d_really_is_negative (privroot)) {return ERR_PTR (-EOPNOTSUPP );
I don't think EOPNOTSUPP is correct return code for !privroot case. AFAICS it would propagate out of reiserfs xattr code and would result in denying access to lookup_one_len() so xattr dir could never be initialized for such filesystem. So we need to return 0 (success, no xattrs present) in this case and because this is just a special case when we are initializing xattr dir and recurse back into xattr code, I've decided to perform this check directly in reiserfs_xattr_get().
fs/reiserfs/xattr.c static struct dentry *open_xa_root(struct super_block *sb, int flags) · line 126
Quoted 1 line
fs/reiserfs/xattr.c +1
-0+ }
There's no need for additional braces in this 'if'.
fs/reiserfs/xattr.c static struct dentry *open_xa_root(struct super_block *sb, int flags) · line 128
Quoted 2 lines
fs/reiserfs/xattr.c +0
-0inode_lock_nested (d_inode (privroot),I_MUTEX_XATTR );
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 16 lines · Jan Kara
Quoted 14 lines · Anmol Karn
d_really_is_negative()checks for thedentry->d_inodewhether it's NULL or not, but inopen_xa_root(), when it checks 'privroot->d_inode', it doesn't check whether privroot is NULL or not, this leads to a null pointer dereference while calling it fromopen_xa_dir()while initializing xaroot.-
fs/reiserfs/xattr.c
The bug seems to get triggered at this line:if (
d_really_is_negative(privroot))return ERR_PTR(-EOPNOTSUPP);Fix it by adding a NULL check for privroot.
Quoted 8 lines
Quoted 3 lines
Reported-and-tested-by [email protected]Signed-off-by Anmol Karn <[email protected]>Thanks for the patch! I've already fixed the problem myself (slightly differently) but I'll comment about your patch below for educational purposes :). See
https://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs.git/commit/?h=for_next&id=c2bb80b8bdd04dfe32364b78b61b6a47f717af52
Ah, no worries, I am glad that, the bug is fixed :). I will mark this as fixed on syzbot.
Quoted 9 lines
Quoted 9 lines
fs/reiserfs/xattr.c +0
-0@@ -121,8 +121,9 @@ static struct dentry *open_xa_root(struct super_block *sb, int flags)struct dentry *privroot =REISERFS_SB (sb)->priv_root;struct dentry *xaroot;
Quoted 11 lines
fs/reiserfs/xattr.c static struct dentry *open_xa_root(struct super_block *sb, int flags) · line 125
Quoted 3 lines
fs/reiserfs/xattr.c +1
-1-if (d_really_is_negative (privroot)) +if (!privroot ||d_really_is_negative (privroot)) {return ERR_PTR (-EOPNOTSUPP );I don't think EOPNOTSUPP is correct return code for !privroot case. AFAICS it would propagate out of reiserfs xattr code and would result in denying access to
lookup_one_len()so xattr dir could never be initialized for such filesystem. So we need to return 0 (success, no xattrs present) in this case and because this is just a special case when we are initializing xattr dir and recurse back into xattr code, I've decided to perform this check directly inreiserfs_xattr_get().
Thanks for the review and information, sir.
Quoted 11 lines
fs/reiserfs/xattr.c static struct dentry *open_xa_root(struct super_block *sb, int flags) · line 126
Quoted 2 lines
fs/reiserfs/xattr.c +1
-0+ }There's no need for additional braces in this 'if'.
fs/reiserfs/xattr.c static struct dentry *open_xa_root(struct super_block *sb, int flags) · line 128
Quoted 2 lines
fs/reiserfs/xattr.c +0
-0inode_lock_nested (d_inode (privroot),I_MUTEX_XATTR );Honza
--
Jan Kara <[email protected]>
SUSE Labs, CR
Anmol