Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp202715lqo; Tue, 7 May 2024 17:58:25 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUj9qv8VJxcbbM4TZlz2JEVRHdYXfRXzmhCag8E2DQGgJv3/cMfna1H1rk8Fy8DBAhxUvXf/9EHzyhk3bL9JuOTxem3SXVu4FEUJHAZFg== X-Google-Smtp-Source: AGHT+IHJ4V9f8ncH32Mc0vSJxLkrnAUC+G1slEiW41vnK6yfd4te2VQdMfrOXT3Sb7MqCgH6O3S0 X-Received: by 2002:a05:6402:1016:b0:56e:7281:55eb with SMTP id 4fb4d7f45d1cf-57311032007mr3421087a12.9.1715129905195; Tue, 07 May 2024 17:58:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715129905; cv=pass; d=google.com; s=arc-20160816; b=RpkL1flXpvGVaEScQFXHOZoeAecDgblYExnkLs07aoPVJuqfBVcQbt2whbp86V1U1n EpP8VGX+t//9f6WQOEIx9izqsL0F1m5VjRbH16maBMkNvVjcPHAlPh2VoTMDad9KveX1 uUF+zwldQQDK0coq8KYJ4yA9M0DebCC1vOfIEbpRcmj8rbdihd1PZVAhdawypicX18cB Z7r/LHNsYinsRrbv9n7sn5JEb9oR7XGlCLMwCwKAL2NrovKhxnt0gR5KGOO3eWmCETHV pKvdHgW0IMYPJvsQZQwkmm2arq/yT62Y3/v8krtmxuCnklvCM1VlnllageQP5b8KaeJQ OL/g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:date :subject:cc:to:from:message-id:dkim-signature; bh=VFAZlXGZGtSQpeEGdXcNHn4HmDGOh8o9jDMv4pQ+wOk=; fh=RmKYhalX0OxqEiYy+BfB1a+8lZIwgUVFA8AMXFOf63Q=; b=qP3oreJp8LZlabNJli3+RaVWrPE/4zB9Q1Zbtxes7ao75jyKo8zslVXSlrdkdBcfiu /EQ/vcjQyVyBiUB1dBbsSFg/YXlXjWVII9FX23ibaiwGeEGWs4xrf7iJEnry5tqeEchD 7GrvOtm4B6PI22lH4w7M+alzFcGTSYZp7PWm3nHbyUrWAeK2TMQGhvY0Fvx4Wwf9PUCS xM63d5DrGEBkiUL89t7i+pRBG9iU7Q+sWjZ8ghB15ElV+BHbIYKr8+p2qvclQfihQLuf kn38+58yn14kJ9AeDEQac3V64+CX24raDY/n11HXjhSkvRfY1g/Eur72GZbOPWlnQGgA ZMKQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@qq.com header.s=s201512 header.b=kvxMcYpn; arc=pass (i=1 spf=pass spfdomain=qq.com dkim=pass dkdomain=qq.com dmarc=pass fromdomain=qq.com); spf=pass (google.com: domain of linux-kernel+bounces-172574-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172574-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=qq.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id f24-20020a50a6d8000000b005727ef21ecesi6373325edc.389.2024.05.07.17.58.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 17:58:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-172574-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@qq.com header.s=s201512 header.b=kvxMcYpn; arc=pass (i=1 spf=pass spfdomain=qq.com dkim=pass dkdomain=qq.com dmarc=pass fromdomain=qq.com); spf=pass (google.com: domain of linux-kernel+bounces-172574-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172574-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=qq.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id E7D071F230B5 for ; Wed, 8 May 2024 00:58:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F10F01C27; Wed, 8 May 2024 00:58:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=qq.com header.i=@qq.com header.b="kvxMcYpn" Received: from out162-62-58-211.mail.qq.com (out162-62-58-211.mail.qq.com [162.62.58.211]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 22723399; Wed, 8 May 2024 00:58:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.62.58.211 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715129894; cv=none; b=mCHW9Y3UoqNSSSzrrLueGJzX8zf3fTYa8s7CcayW8rMKH2kcbsI01N0iNM3pJh789sS5jsSwm69fJwLTyjEYNXeuamp7xwkWDNElx0HnjNp7qc4/Xaywc0OKIC3ccREGA6W7bJWNchOSw5vu8TooTazBiAHea5fW86LLVLIT2ME= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715129894; c=relaxed/simple; bh=zjO/qPZcafCTW43IRe3RvW2IfTQeDhHD2HqaG05cbp8=; h=Message-ID:From:To:Cc:Subject:Date:In-Reply-To:References: MIME-Version; b=QPiRQidEWPZiWhXpo+HXk0WVRUydIqAZ/CBomX80IOTLiX8mjTVS3berQ13rPd3wfDE0TSUhRNn8PYUPmhy++0v3hrAzuQn1MsLlIe+gxlmRiDtlV1ykMCweL9AUd5Q5FCMA/ie8mqPquTIFZMi+6BICXMaFY4w4mEh2/BpYM2Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=qq.com; spf=pass smtp.mailfrom=qq.com; dkim=pass (1024-bit key) header.d=qq.com header.i=@qq.com header.b=kvxMcYpn; arc=none smtp.client-ip=162.62.58.211 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=qq.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=qq.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1715129877; bh=VFAZlXGZGtSQpeEGdXcNHn4HmDGOh8o9jDMv4pQ+wOk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=kvxMcYpn4Sm3cpumepeJlH2fgkGZA9R/gkj9Ugv/PDOBRYzhgPho8W7NZ3bvFjXHn FqsTfcWYRTAQuaJf5Vs90JEr/a9Cmj+uVblzXXGbtbfEv/ueMZZB9Byj1xiWrZcTQH 2RVBy8WmFU70YkV4dy26tqg8e7ttbMyn7nwSwfOw= Received: from pek-lxu-l1.wrs.com ([111.198.228.153]) by newxmesmtplogicsvrszc5-2.qq.com (NewEsmtp) with SMTP id C6691693; Wed, 08 May 2024 08:49:38 +0800 X-QQ-mid: xmsmtpt1715129378t6bmvqgo1 Message-ID: X-QQ-XMAILINFO: MQ+wLuVvI2LQAFbobgONXpXt6X7weDy7PIUgvjt+Jrfn5G8s9PQyPiQL3OoV6D T9i50X8xTCRECO39v1VJXwlCA2ci74RCn0uX3AjuLyVWaWN0/mwyxDiRf4kc9615CkfQpS1E3U0w vN/WZZaOYbYgoP4IJ2VQwytzt7ZIsggV6vswxoVFZHGF8wWbtZXVobokwpJ+02eNwWKo4D2HsQ2b fmd1mZxfc7I7FjMAahln38gv3qaR5HdSgCNInyqvtkVK/yIKF7FyTWucaCtuXaQE5GeuYtqL5ieB PEZuPLoSR0Ri70EW9c60M1MqTJy+/UtrW7YJVTWvMVKchdBtVQW+LGYTeec+bA+lOGmqWm1mlYsm BvHToCPdBI9ZnCXQxHhZiq0LmMJYYJm1vc8iKGP0+zIYzq/viThTg16DXHqDFX+9TIZwq14Ah+FM Paj0bcnFLaGDaqbBF4AqLtmHyAjE82cMUei4DKrXc+m+MCzjCduuXxbMnMNPaMdfzZlflP4/0j0c BU6Ot86bF7M4O1e4g+dBPr1x7goICGiSKzXAn62sg2ctmHIgIHiKPpGQSRCHRvad62bN/p2shRVt 5RmcD2nhlHovJGw0dPXGaizeoSzzy+DDRQrHQRpBkbDExmH4xUzELgLAdaF4G4CIqcuz95jQcpzH EdZQKjm57Ezv2g3oOUn6zwaURCHE8ReeawPbdOdkUWlC495weLXxfsdPIuLIJiwl6TxAk5nZ+TTe Jc8pIWsERKBiU/w1RWy0D3Bd3lm5dXJE5Yj9CSUbL2+5cjtFjFbBtG1nKKiJRSXVRE6dKt1fxTkz 9reoCZpbuPyChrhymKUPE0dU1/8wq/s0BN3WvBxLAs4VBtlVfk83udZiUsg2nzEtVAyR9ArzcKMJ DAsQcNWMasWa7LDPhi1dxyO8nmps7JrKW8uZ+2FrMUeGrnr1ql5HTLo5JBiLt0A3bnB3UMkqDbar i2pJA7UyCGNmLq62J+ZA== X-QQ-XMRINFO: NyFYKkN4Ny6FSmKK/uo/jdU= From: Edward Adam Davis To: kent.overstreet@linux.dev Cc: bfoster@redhat.com, eadavis@qq.com, linux-bcachefs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, syzbot+c48865e11e7e893ec4ab@syzkaller.appspotmail.com, syzkaller-bugs@googlegroups.com Subject: Re: [PATCH] bcachefs: fix oob in bch2_sb_clean_to_text Date: Wed, 8 May 2024 08:49:39 +0800 X-OQ-MSGID: <20240508004938.3201113-2-eadavis@qq.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On Tue, 7 May 2024 10:14:22 -0400, Kent Overstreet wrote: > > When got too small clean field, entry will never equal vstruct_end(&clean->field), > > the dead loop resulted in out of bounds access. > > > > Fixes: 12bf93a429c9 ("bcachefs: Add .to_text() methods for all superblock sections") > > Fixes: a37ad1a3aba9 ("bcachefs: sb-clean.c") > > Reported-and-tested-by: syzbot+c48865e11e7e893ec4ab@syzkaller.appspotmail.com > > Signed-off-by: Edward Adam Davis > > I've already got a patch up for this - the validation was missing as > well. > > commit f39055220f6f98a180e3503fe05bbf9921c425c8 > Author: Kent Overstreet > Date: Sun May 5 22:28:00 2024 -0400 > > bcachefs: Add missing validation for superblock section clean > > We were forgetting to check for jset entries that overrun the end of the > section - both in validate and to_text(); to_text() needs to be safe for > types that fail to validate. > > Reported-by: syzbot+c48865e11e7e893ec4ab@syzkaller.appspotmail.com > Signed-off-by: Kent Overstreet > > diff --git a/fs/bcachefs/sb-clean.c b/fs/bcachefs/sb-clean.c > index 35ca3f138de6..194e55b11137 100644 > --- a/fs/bcachefs/sb-clean.c > +++ b/fs/bcachefs/sb-clean.c > @@ -278,6 +278,17 @@ static int bch2_sb_clean_validate(struct bch_sb *sb, > return -BCH_ERR_invalid_sb_clean; > } > > + for (struct jset_entry *entry = clean->start; > + entry != vstruct_end(&clean->field); > + entry = vstruct_next(entry)) { > + if ((void *) vstruct_next(entry) > vstruct_end(&clean->field)) { > + prt_str(err, "entry type "); > + bch2_prt_jset_entry_type(err, le16_to_cpu(entry->type)); > + prt_str(err, " overruns end of section"); > + return -BCH_ERR_invalid_sb_clean; > + } > + } > + The original judgment here is sufficient, there is no need to add this section of inspection. > return 0; > } > > @@ -295,6 +306,9 @@ static void bch2_sb_clean_to_text(struct printbuf *out, struct bch_sb *sb, > for (entry = clean->start; > entry != vstruct_end(&clean->field); > entry = vstruct_next(entry)) { > + if ((void *) vstruct_next(entry) > vstruct_end(&clean->field)) > + break; > + The same check has already been done in bch2_sb_clean_validate(), so it is unnecessary to redo it here. > if (entry->type == BCH_JSET_ENTRY_btree_keys && > !entry->u64s) > continue;