Skip to content

Commit b87c7cd

Browse files
committed
ext4: fix invalid free tracking in ext4_xattr_move_to_block()
In ext4_xattr_move_to_block(), the value of the extended attribute which we need to move to an external block may be allocated by kvmalloc() if the value is stored in an external inode. So at the end of the function the code tried to check if this was the case by testing entry->e_value_inum. However, at this point, the pointer to the xattr entry is no longer valid, because it was removed from the original location where it had been stored. So we could end up calling kvfree() on a pointer which was not allocated by kvmalloc(); or we could also potentially leak memory by not freeing the buffer when it should be freed. Fix this by storing whether it should be freed in a separate variable. Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Link: https://syzkaller.appspot.com/bug?id=5c2aee8256e30b55ccf57312c16d88417adbd5e1 Link: https://syzkaller.appspot.com/bug?id=41a6b5d4917c0412eb3b3c3c604965bed7d7420b Reported-by: [email protected] Reported-by: [email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 463808f commit b87c7cd

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

fs/ext4/xattr.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2614,6 +2614,7 @@ static int ext4_xattr_move_to_block(handle_t *handle, struct inode *inode,
26142614
.in_inode = !!entry->e_value_inum,
26152615
};
26162616
struct ext4_xattr_ibody_header *header = IHDR(inode, raw_inode);
2617+
int needs_kvfree = 0;
26172618
int error;
26182619

26192620
is = kzalloc(sizeof(struct ext4_xattr_ibody_find), GFP_NOFS);
@@ -2636,7 +2637,7 @@ static int ext4_xattr_move_to_block(handle_t *handle, struct inode *inode,
26362637
error = -ENOMEM;
26372638
goto out;
26382639
}
2639-
2640+
needs_kvfree = 1;
26402641
error = ext4_xattr_inode_get(inode, entry, buffer, value_size);
26412642
if (error)
26422643
goto out;
@@ -2675,7 +2676,7 @@ static int ext4_xattr_move_to_block(handle_t *handle, struct inode *inode,
26752676

26762677
out:
26772678
kfree(b_entry_name);
2678-
if (entry->e_value_inum && buffer)
2679+
if (needs_kvfree && buffer)
26792680
kvfree(buffer);
26802681
if (is)
26812682
brelse(is->iloc.bh);

0 commit comments

Comments
 (0)