diff mbox series

btrfs: Fix potential null pointer deref

Message ID 20200921191243.27833-1-a.dewar@sussex.ac.uk (mailing list archive)
State New, archived
Headers show
Series btrfs: Fix potential null pointer deref | expand

Commit Message

Alex Dewar Sept. 21, 2020, 7:12 p.m. UTC
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 <a.dewar@sussex.ac.uk>
---
 fs/btrfs/inode.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Josef Bacik Sept. 21, 2020, 7:16 p.m. UTC | #1
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 <a.dewar@sussex.ac.uk>

Reviewed-by: Josef Bacik <josef@toxicpanda.com>

Thanks,

Josef
David Sterba Sept. 24, 2020, 2:11 p.m. UTC | #2
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 <a.dewar@sussex.ac.uk>

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".
diff mbox series

Patch

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);