Skip to contentSkip to conversation

btrfs: inode: Check if we get a valid inode before checking its mode.

PATCH In review Qu Wenruo 3 participants 3 messages Mar 29, 2019 Btrfs file system

lore
Share & tools
lore

Qu Wenruo

author
#0 lore raw

PATCH 1/1 btrfs: inode: Check if we get a valid inode before checking its mode.

We should check the inode validation before checking the imode.

As btrfs_iget() could return ERR_PTR(), unlike previous path, we need to verify the inode before checking the imode.

---
To David:

Please fold this into 9944a5b5d26e ("btrfs: inode: Verify inode mode to avoid NULL pointer dereference") of misc-next branch.

---
 fs/btrfs/inode.c | 2 ++
 1 file changed, 2 insertions(+)
fs/btrfs/inode.c +2 -0
index 3ee835cbb490..97f47dd295e8 100644
@@ -5776,6 +5776,8 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry)
 
 	if (location.type == BTRFS_INODE_ITEM_KEY) {
 		inode = btrfs_iget(dir->i_sb, &location, root, NULL);
+		if (IS_ERR(inode))
+			return inode;
 
 		/* Do extra check against inode mode with di_type */
 		if (btrfs_inode_type(inode) != di_type) {
Signature · 1 line
2.21.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Qu Wenruo

We should check the inode validation before checking the imode.

As btrfs_iget() could return ERR_PTR(), unlike previous path, we need to verify the inode before checking the imode.

Quoted 23 lines

---
To David:

Please fold this into 9944a5b5d26e ("btrfs: inode: Verify inode mode to avoid NULL pointer dereference") of misc-next branch.

---
 fs/btrfs/inode.c | 2 ++
 1 file changed, 2 insertions(+)
fs/btrfs/inode.c +2 -0
index 3ee835cbb490..97f47dd295e8 100644
@@ -5776,6 +5776,8 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry)
 
 	if (location.type == BTRFS_INODE_ITEM_KEY) {
 		inode = btrfs_iget(dir->i_sb, &location, root, NULL);
+		if (IS_ERR(inode))
+			return inode;
 
 		/* Do extra check against inode mode with di_type */
 		if (btrfs_inode_type(inode) != di_type) {
#2 lore raw
In reply to Qu Wenruo
Quoted 11 lines · Qu Wenruo

We should check the inode validation before checking the imode.

As btrfs_iget() could return ERR_PTR(), unlike previous path, we need to verify the inode before checking the imode.

---
To David:

Please fold this into 9944a5b5d26e ("btrfs: inode: Verify inode mode to avoid NULL pointer dereference") of misc-next branch.

Folded and branch pushed, thanks.