2020-09-21 19:16:53

by Alex Dewar

[permalink] [raw]
Subject: [PATCH] btrfs: Fix potential null pointer deref

In btrfs_destroy_inode(), the variable root may be NULL, but the check
for this takes place after its value has already been dereferenced to
access its fs_info member. Move the dereference operation to later in
the function.

Fixes: a6dbd429d8dd ("Btrfs: fix panic when trying to destroy a newly allocated")
Addresses-Coverity: CID 1497103: Null pointer dereferences (REVERSE_INULL)
Signed-off-by: Alex Dewar <[email protected]>
---
fs/btrfs/inode.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index a5dae53c1e27..8f230b7bfe65 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -8648,7 +8648,6 @@ void btrfs_destroy_inode(struct inode *vfs_inode)
struct btrfs_ordered_extent *ordered;
struct btrfs_inode *inode = BTRFS_I(vfs_inode);
struct btrfs_root *root = inode->root;
- struct btrfs_fs_info *fs_info = root->fs_info;

WARN_ON(!hlist_empty(&vfs_inode->i_dentry));
WARN_ON(vfs_inode->i_data.nrpages);
@@ -8673,7 +8672,7 @@ void btrfs_destroy_inode(struct inode *vfs_inode)
if (!ordered)
break;
else {
- btrfs_err(fs_info,
+ btrfs_err(root->fs_info,
"found ordered extent %llu %llu on inode cleanup",
ordered->file_offset, ordered->num_bytes);
btrfs_remove_ordered_extent(inode, ordered);
--
2.28.0


2020-09-21 19:18:33

by Josef Bacik

[permalink] [raw]
Subject: Re: [PATCH] btrfs: Fix potential null pointer deref

On 9/21/20 3:12 PM, Alex Dewar wrote:
> In btrfs_destroy_inode(), the variable root may be NULL, but the check
> for this takes place after its value has already been dereferenced to
> access its fs_info member. Move the dereference operation to later in
> the function.
>
> Fixes: a6dbd429d8dd ("Btrfs: fix panic when trying to destroy a newly allocated")
> Addresses-Coverity: CID 1497103: Null pointer dereferences (REVERSE_INULL)
> Signed-off-by: Alex Dewar <[email protected]>

Reviewed-by: Josef Bacik <[email protected]>

Thanks,

Josef

2020-09-24 14:17:18

by David Sterba

[permalink] [raw]
Subject: Re: [PATCH] btrfs: Fix potential null pointer deref

On Mon, Sep 21, 2020 at 08:12:44PM +0100, Alex Dewar wrote:
> In btrfs_destroy_inode(), the variable root may be NULL, but the check
> for this takes place after its value has already been dereferenced to
> access its fs_info member. Move the dereference operation to later in
> the function.
>
> Fixes: a6dbd429d8dd ("Btrfs: fix panic when trying to destroy a newly allocated")
> Addresses-Coverity: CID 1497103: Null pointer dereferences (REVERSE_INULL)
> Signed-off-by: Alex Dewar <[email protected]>

For some reason my replies did not get to linux-btrfs@, so for the
record the changes has been folded to the patch "btrfs: clean BTRFS_I
usage in btrfs_destroy_inode".