lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240821025737.1785348-1-lizhi.xu@windriver.com>
Date: Wed, 21 Aug 2024 10:57:37 +0800
From: Lizhi Xu <lizhi.xu@...driver.com>
To: <lizhi.xu@...driver.com>
CC: <kent.overstreet@...ux.dev>, <linux-bcachefs@...r.kernel.org>,
        <linux-kernel@...r.kernel.org>,
        <syzbot+47ecc948aadfb2ab3efc@...kaller.appspotmail.com>,
        <syzkaller-bugs@...glegroups.com>
Subject: [PATCH V3] bcachefs: Add journal v2 entry nr value check

When the nr value of a signle entry or their sum overflows, it will
cause the value of ja->nr to be incorrect, this will result in the
allocated memory to ja->buckets being too small, leading to out of
bounds access in bch2_dev_journal_init.

Reported-by: syzbot+47ecc948aadfb2ab3efc@...kaller.appspotmail.com
Signed-off-by: Lizhi Xu <lizhi.xu@...driver.com>
---
 fs/bcachefs/journal_sb.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/fs/bcachefs/journal_sb.c b/fs/bcachefs/journal_sb.c
index db80e506e3ab..230ed99130e4 100644
--- a/fs/bcachefs/journal_sb.c
+++ b/fs/bcachefs/journal_sb.c
@@ -107,6 +107,7 @@ static int bch2_sb_journal_v2_validate(struct bch_sb *sb, struct bch_sb_field *f
 	unsigned nr;
 	unsigned i;
 	struct u64_range *b;
+	u64 total_nr = 0, entry_nr;
 
 	nr = bch2_sb_field_journal_v2_nr_entries(journal);
 	if (!nr)
@@ -117,8 +118,21 @@ static int bch2_sb_journal_v2_validate(struct bch_sb *sb, struct bch_sb_field *f
 		return -BCH_ERR_ENOMEM_sb_journal_v2_validate;
 
 	for (i = 0; i < nr; i++) {
+		entry_nr = le64_to_cpu(journal->d[i].nr);
+		if (entry_nr > UINT_MAX) {
+			prt_printf(err, "Journal v2 entry d[%u] nr %llu overflow\n",
+				i, entry_nr);
+			goto err;
+		}
+		total_nr += entry_nr;
 		b[i].start = le64_to_cpu(journal->d[i].start);
-		b[i].end = b[i].start + le64_to_cpu(journal->d[i].nr);
+		b[i].end = b[i].start + entry_nr;
+	}
+
+	if (total_nr > UINT_MAX) {
+		prt_printf(err, "Sum of journal v2 entries nr %llu overflow\n",
+				total_nr);
+		goto err;
 	}
 
 	sort(b, nr, sizeof(*b), u64_range_cmp, NULL);
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ