ext4: fix use-after-free in dx_release()
PATCH 1/1 ext4: fix use-after-free in dx_release()
The buffer_head (frames[0].bh) and it's corresping page can be potentially free'd once brelse() is done inside the for loop but before the for loop exits in dx_release(). It can be free'd in another context, when the page cache is flushed via drop_caches_sysctl_handler(). This results into below data abort when accessing info->indirect_levels in dx_release().
Unable to handle kernel paging request at virtual address ffffffc17ac3e01e Call trace: dx_release+0x70/0x90 ext4_htree_fill_tree+0x2d4/0x300 ext4_readdir+0x244/0x6f8 iterate_dir+0xbc/0x160 SyS_getdents64+0x94/0x174
--- fs/ext4/namei.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/ext4/namei.c +3 -1
@@ -871,12 +871,14 @@ static void dx_release(struct dx_frame *frames) {struct dx_root_info *info;int i; +unsigned int indirect_levels;if (frames[0 ].bh ==NULL )return ; info = &((struct dx_root *)frames[0 ].bh->b_data)->info; -for (i =0 ; i <= info->indirect_levels; i++) { + indirect_levels = info->indirect_levels; +for (i =0 ; i <= indirect_levels; i++) {if (frames[i].bh ==NULL )break ;brelse (frames[i].bh);
Signature · 2 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.
Quoted 16 lines · Sahitya Tummala
The
buffer_head(frames[0].bh) and it's corresping page can be potentially free'd oncebrelse()is done inside the for loop but before the for loop exits indx_release(). It can be free'd in another context, when the page cache is flushed viadrop_caches_sysctl_handler(). This results into below data abort when accessinginfo->indirect_levelsindx_release().Unable to handle kernel paging request at virtual address ffffffc17ac3e01e Call trace: dx_release+0x70/0x90 ext4_htree_fill_tree+0x2d4/0x300 ext4_readdir+0x244/0x6f8 iterate_dir+0xbc/0x160 SyS_getdents64+0x94/0x174
Quoted 1 line
Signed-off-by Sahitya Tummala <[email protected]>
The patch looks reasonable, but there is a danger that it may be "optimized" back to the pre-patch form again. It probably makes sense to include a comment like:
/* save local copy, "info" may be freed after brelse() */
Looks fine otherwise.
Quoted 25 lines
---
fs/ext4/namei.c| 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)fs/ext4/namei.c +3
-2@@ -871,12 +871,14 @@ static void dx_release(struct dx_frame *frames) {struct dx_root_info *info;int i; +unsigned int indirect_levels;if (frames[0 ].bh ==NULL )return ; info = &((struct dx_root *)frames[0 ].bh->b_data)->info; -for (i =0 ; i <= info->indirect_levels; i++) { + indirect_levels = info->indirect_levels; +for (i =0 ; i <= indirect_levels; i++) {if (frames[i].bh ==NULL )break ;brelse (frames[i].bh); --
Quoted 3 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.
Cheers, Andreas
Quoted 17 lines · Andreas Dilger
Quoted 16 lines · Sahitya Tummala
The
buffer_head(frames[0].bh) and it's corresping page can be potentially free'd oncebrelse()is done inside the for loop but before the for loop exits indx_release(). It can be free'd in another context, when the page cache is flushed viadrop_caches_sysctl_handler(). This results into below data abort when accessinginfo->indirect_levelsindx_release().Unable to handle kernel paging request at virtual address ffffffc17ac3e01e Call trace: dx_release+0x70/0x90 ext4_htree_fill_tree+0x2d4/0x300 ext4_readdir+0x244/0x6f8 iterate_dir+0xbc/0x160 SyS_getdents64+0x94/0x174
Quoted 7 lines
Quoted 1 line
Signed-off-by Sahitya Tummala <[email protected]>The patch looks reasonable, but there is a danger that it may be "optimized" back to the pre-patch form again. It probably makes sense to include a comment like:
/* save local copy, "info" may be freed after brelse() */
Thanks for reviewing it. Sure, I will add the comment.
Quoted 41 lines
Looks fine otherwise.
Reviewed-by Andreas Dilger <[email protected]>Quoted 25 lines
---
fs/ext4/namei.c| 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)fs/ext4/namei.c +3
-2@@ -871,12 +871,14 @@ static void dx_release(struct dx_frame *frames) {struct dx_root_info *info;int i; +unsigned int indirect_levels;if (frames[0 ].bh ==NULL )return ; info = &((struct dx_root *)frames[0 ].bh->b_data)->info; -for (i =0 ; i <= info->indirect_levels; i++) { + indirect_levels = info->indirect_levels; +for (i =0 ; i <= indirect_levels; i++) {if (frames[i].bh ==NULL )break ;brelse (frames[i].bh); --Quoted 3 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.Cheers, Andreas
Signature · 3 lines
-- Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.