public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ocfs2: zero-initialize recovery bitmap to prevent uninit-value in find_next_bit
@ 2026-02-09 16:13 Daniel Hodges
  2026-02-09 18:01 ` Jan Kara
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Hodges @ 2026-02-09 16:13 UTC (permalink / raw)
  To: Mark Fasheh, Joel Becker, Joseph Qi
  Cc: Jan Kara, ocfs2-devel, linux-kernel, Daniel Hodges,
	syzbot+7ea0b96c4ddb49fd1a70, stable

ocfs2_add_recovery_chunk() allocates a bitmap buffer of sb->s_blocksize
bytes using kmalloc() but only copies (ol_chunk_entries(sb) + 7) >> 3
bytes into it from the on-disk quota chunk. When the number of chunk
entries is not aligned to a long boundary (64 bits on 64-bit systems),
find_next_bit() reads uninitialized memory from the trailing bytes of
the last word in the bitmap.

Fix this by using kzalloc() to zero-initialize the entire bitmap
allocation, ensuring that any bits beyond the copied region are
clean zeros.

Reported-by: syzbot+7ea0b96c4ddb49fd1a70@syzkaller.appspotmail.com
Fixes: 2205363dce74 ("ocfs2: Implement quota recovery")
Cc: stable@vger.kernel.org
Signed-off-by: Daniel Hodges <git@danielhodges.dev>
---
 fs/ocfs2/quota_local.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/ocfs2/quota_local.c b/fs/ocfs2/quota_local.c
index de7f12858729..bd3eb098097f 100644
--- a/fs/ocfs2/quota_local.c
+++ b/fs/ocfs2/quota_local.c
@@ -302,7 +302,7 @@ static int ocfs2_add_recovery_chunk(struct super_block *sb,
 	if (!rc)
 		return -ENOMEM;
 	rc->rc_chunk = chunk;
-	rc->rc_bitmap = kmalloc(sb->s_blocksize, GFP_NOFS);
+	rc->rc_bitmap = kzalloc(sb->s_blocksize, GFP_NOFS);
 	if (!rc->rc_bitmap) {
 		kfree(rc);
 		return -ENOMEM;
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ocfs2: zero-initialize recovery bitmap to prevent uninit-value in find_next_bit
  2026-02-09 16:13 [PATCH] ocfs2: zero-initialize recovery bitmap to prevent uninit-value in find_next_bit Daniel Hodges
@ 2026-02-09 18:01 ` Jan Kara
  0 siblings, 0 replies; 2+ messages in thread
From: Jan Kara @ 2026-02-09 18:01 UTC (permalink / raw)
  To: Daniel Hodges
  Cc: Mark Fasheh, Joel Becker, Joseph Qi, Jan Kara, ocfs2-devel,
	linux-kernel, syzbot+7ea0b96c4ddb49fd1a70, stable

On Mon 09-02-26 11:13:47, Daniel Hodges wrote:
> ocfs2_add_recovery_chunk() allocates a bitmap buffer of sb->s_blocksize
> bytes using kmalloc() but only copies (ol_chunk_entries(sb) + 7) >> 3
> bytes into it from the on-disk quota chunk. When the number of chunk
> entries is not aligned to a long boundary (64 bits on 64-bit systems),
> find_next_bit() reads uninitialized memory from the trailing bytes of
> the last word in the bitmap.

OK, but AFAICS it does not impact the functionality in any way because we
properly use:

for_each_set_bit(bit, rchunk->rc_bitmap, ol_chunk_entries(sb))

so the uninitialized bits are actually never used. This would be good to
stress in the changelog. Since this isn't really a performance sensitive
code I agree with the fix to make the checker happy anyway but I wanted to
make sure... So feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> 
> Fix this by using kzalloc() to zero-initialize the entire bitmap
> allocation, ensuring that any bits beyond the copied region are
> clean zeros.
> 
> Reported-by: syzbot+7ea0b96c4ddb49fd1a70@syzkaller.appspotmail.com
> Fixes: 2205363dce74 ("ocfs2: Implement quota recovery")
> Cc: stable@vger.kernel.org
> Signed-off-by: Daniel Hodges <git@danielhodges.dev>
> ---
>  fs/ocfs2/quota_local.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/ocfs2/quota_local.c b/fs/ocfs2/quota_local.c
> index de7f12858729..bd3eb098097f 100644
> --- a/fs/ocfs2/quota_local.c
> +++ b/fs/ocfs2/quota_local.c
> @@ -302,7 +302,7 @@ static int ocfs2_add_recovery_chunk(struct super_block *sb,
>  	if (!rc)
>  		return -ENOMEM;
>  	rc->rc_chunk = chunk;
> -	rc->rc_bitmap = kmalloc(sb->s_blocksize, GFP_NOFS);
> +	rc->rc_bitmap = kzalloc(sb->s_blocksize, GFP_NOFS);
>  	if (!rc->rc_bitmap) {
>  		kfree(rc);
>  		return -ENOMEM;
> -- 
> 2.52.0
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-02-09 18:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-09 16:13 [PATCH] ocfs2: zero-initialize recovery bitmap to prevent uninit-value in find_next_bit Daniel Hodges
2026-02-09 18:01 ` Jan Kara

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox