linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Edward AD <twuufnxlz@gmail.com>
To: syzbot+4a2376bc62e59406c414@syzkaller.appspotmail.com
Cc: akpm@linux-foundation.org, hughd@google.com,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org, syzkaller-bugs@googlegroups.com
Subject: [PATCH] fs/hfsplus: expand s_vhdr_buf size to avoid slab oob
Date: Tue, 26 Sep 2023 18:24:55 +0800	[thread overview]
Message-ID: <20230926102454.992535-2-twuufnxlz@gmail.com> (raw)
In-Reply-To: <000000000000820e380606161640@google.com>

The memory allocated to s_vhdr_buf in the function hfsplus-read_wrapper is 
too small, resulting in a slab out of bounds issue when copying data with 
copy_page_from_iter_atomic.

When allocating memory to s_vhdr_buf, take the maximum value between 
hfsplus_min_io_size(sb) and PAGE_SIZE to avoid similar issues.

Reported-and-tested-by: syzbot+4a2376bc62e59406c414@syzkaller.appspotmail.com
Signed-off-by: Edward AD <twuufnxlz@gmail.com>
---
 fs/hfsplus/wrapper.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/fs/hfsplus/wrapper.c b/fs/hfsplus/wrapper.c
index 0b791adf02e5..56bee8dbe532 100644
--- a/fs/hfsplus/wrapper.c
+++ b/fs/hfsplus/wrapper.c
@@ -163,7 +163,7 @@ int hfsplus_read_wrapper(struct super_block *sb)
 	struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
 	struct hfsplus_wd wd;
 	sector_t part_start, part_size;
-	u32 blocksize;
+	u32 blocksize, bufsize;
 	int error = 0;
 
 	error = -EINVAL;
@@ -175,10 +175,11 @@ int hfsplus_read_wrapper(struct super_block *sb)
 		goto out;
 
 	error = -ENOMEM;
-	sbi->s_vhdr_buf = kmalloc(hfsplus_min_io_size(sb), GFP_KERNEL);
+	bufsize = max_t(u32, hfsplus_min_io_size(sb), PAGE_SIZE);
+	sbi->s_vhdr_buf = kmalloc(bufsize, GFP_KERNEL);
 	if (!sbi->s_vhdr_buf)
 		goto out;
-	sbi->s_backup_vhdr_buf = kmalloc(hfsplus_min_io_size(sb), GFP_KERNEL);
+	sbi->s_backup_vhdr_buf = kmalloc(bufsize, GFP_KERNEL);
 	if (!sbi->s_backup_vhdr_buf)
 		goto out_free_vhdr;
 
-- 
2.25.1



       reply	other threads:[~2023-09-26 10:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <000000000000820e380606161640@google.com>
2023-09-26 10:24 ` Edward AD [this message]
2024-07-04 14:05   ` Dmitry Vyukov
2025-05-04  9:52 ` [syzbot] [hfs?] [mm?] KASAN: slab-out-of-bounds Read in generic_perform_write syzbot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230926102454.992535-2-twuufnxlz@gmail.com \
    --to=twuufnxlz@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=hughd@google.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=syzbot+4a2376bc62e59406c414@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox