Re: [PATCH V2 2/2] ocfs2: Fix uaf in ocfs2_read_blocks

From: Heming Zhao
Date: Tue Aug 20 2024 - 03:15:42 EST


On 8/20/24 14:55, Lizhi Xu wrote:
In the for-loop after the 'read_failure' label, the condition
'(bh == NULL) && flags includes OCFS2_BH_READAHEAD' is missing.
When this contidion is true, this for-loop will call ocfs2_set_buffer
_uptodate(ci, bh), which then triggers a NULL pointer access error.

Reported-and-suggested-by: Heming Zhao <heming.zhao@xxxxxxxx>
Signed-off-by: Lizhi Xu <lizhi.xu@xxxxxxxxxxxxx>
---
fs/ocfs2/buffer_head_io.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/fs/ocfs2/buffer_head_io.c b/fs/ocfs2/buffer_head_io.c
index e62c7e1de4eb..b4a76f45253d 100644
--- a/fs/ocfs2/buffer_head_io.c
+++ b/fs/ocfs2/buffer_head_io.c
@@ -384,6 +384,8 @@ int ocfs2_read_blocks(struct ocfs2_caching_info *ci, u64 block, int nr,
goto read_failure;
}
}
+ if (!bh)
+ continue;

If you like the style of the above two lines, put them after the
line "bh = bhs[i];", or the code below is more concise:
```
* completed. */
+ if (bh)
ocfs2_set_buffer_uptodate(ci, bh);
```

Thanks,
Heming
/* Always set the buffer in the cache, even if it was
* a forced read, or read-ahead which hasn't yet