Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp576251lqh; Tue, 7 May 2024 07:54:10 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW/f501Z62hKGP9FHV9JzsDIwdJE/+m9jGZLxB3iAsJtqcPhNJNl+9ipX1BPY+9LjJYxTZSB138VNfFCeq6DNgVCGiub+Ys7J7ziQ643Q== X-Google-Smtp-Source: AGHT+IHFByUcHSIF07wvA/N5iGlCdRVmV/CO/xkDe9LVMOLWuwKaGq5/8CUZljbd5MRoPCX+7drR X-Received: by 2002:a05:6359:4c9b:b0:192:5510:e3ee with SMTP id kk27-20020a0563594c9b00b001925510e3eemr3356748rwc.13.1715093649862; Tue, 07 May 2024 07:54:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715093649; cv=pass; d=google.com; s=arc-20160816; b=nST1SYtAhcJ6NGJWNAMolWragvZHvWSe1Zza4iIpbrDJfe4RzkGxchaCFAgLTGEqzU tbB299byr0yGpoFzIvR+HV60cz6srl636DY7QCKs13gVhcbgH9HEw3hfuKr48NQ0VG6t W7Os9fRULcIdxqGCsDYPegT4xul+qRywiilgvbRp8D2RmsIEv+Hrwt15pAxucTQg0To9 N334h961lKTrKF8/ig+EBNxsgM5vERlLzMTtZR0sVt8jrwVCD9tQoZOubhLCXG7h/Vih lBtaYb60UZm/bxn0dU4rvnEke0FkNsivj8u4hth2FOFOke8oueGVLPkhXtJoBZGIVnaJ LeRw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:dkim-signature:date; bh=VRyoFPGhxdjbkIozpMsjzFu89GHel68HSD+8ZqqtWG0=; fh=bSmKI5rQxXvuKTayig1ZCPc2vQ7f3g+DoAuKiZSDzNg=; b=qhcJTPAAVZfZh03TSIoYnyBn6oxm14/nYdZmYjVKO2vURVtRH4Rd3U4+k7C5r/jsrI pMDP9sHuwl21YYfd6gJzmhp1j74rBX73YzrFqNuxJjzcHIObsPsgBcB3q2IIwG5EbZ1B om8qfOD9PESYBHvU8QjmRDpWGmxhBjzv75ZDvy7++JfaZTO7PKqtTo2XMMV0iGHLNL8I x/9y+QL9KvXFvaiD6aSv3d4ehsPrxICc2cEpxuGm7XXt1vnM+DiS1l+AHakUj8HLYvsE vP069LPmazAd5YxFOzRWcH0uywZU9Js5mJFxhST2xybtQOx8qljAv+54s3qCKITcbaah f8CQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="Av4TfY/Z"; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-171545-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171545-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id v25-20020a634659000000b0062d55e4effdsi1018137pgk.540.2024.05.07.07.54.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 07:54:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-171545-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="Av4TfY/Z"; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-171545-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171545-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 1AC5F283915 for ; Tue, 7 May 2024 14:19:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DB584168B06; Tue, 7 May 2024 14:14:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Av4TfY/Z" Received: from out-176.mta0.migadu.com (out-176.mta0.migadu.com [91.218.175.176]) (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 AFBB316EBEC for ; Tue, 7 May 2024 14:14:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715091271; cv=none; b=S4FWCjNG7XbqBg/IoSPHv+HNj65EGjPUxilKjPElE1eiEP+t2QifHwQc85BDcbfG+m2rGRiMTi85vZ4oc9+fdtHI/RYVOx5r/Jzfyerbtr5Ubh4QNewI5SH2LjYWwVAM3K2uLQOopXKDOHPRKvkVmowZzjd3DC37u3l4YUCpl6Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715091271; c=relaxed/simple; bh=xdOHfuHS5StnxBHCTEJkYsqUj8aOzNvad/FTP0nEDaI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=NJVGYc3BmTGtVVbhXgxVB4mDxL73P+lB0Wrh+ia43GwAK2NXtOmQ3Bs9RRyqFrfJKFdx9yczidyXfSEMetAdA+49D4R8icp1tNwyOS2akBegXJdNUu80NcDKuP5vf4cZzMiVlFR6+PSIlYLjOPCRi7lXBcSq0tHoxnSK3dzsmas= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Av4TfY/Z; arc=none smtp.client-ip=91.218.175.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Date: Tue, 7 May 2024 10:14:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1715091266; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=VRyoFPGhxdjbkIozpMsjzFu89GHel68HSD+8ZqqtWG0=; b=Av4TfY/ZIvxNTOvtyyb+RY1VowrMG5yD4yAQcHHjk7mtfG2am+asc1aypyqQNNh+eMf+aj xCspfKfbcKl2rGkWluqfmHWGMr8QvxXmmwiZMFHvkmV/8gFSRz5PpHabzMG5RbsJ+WEO3c O7H1jBCxqPHp9aBvk8j2tctCqLmDgZg= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Kent Overstreet To: Edward Adam Davis Cc: syzbot+c48865e11e7e893ec4ab@syzkaller.appspotmail.com, bfoster@redhat.com, linux-bcachefs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com Subject: Re: [PATCH] bcachefs: fix oob in bch2_sb_clean_to_text Message-ID: References: <000000000000918c290617b914ba@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Migadu-Flow: FLOW_OUT On Tue, May 07, 2024 at 05:19:29PM +0800, Edward Adam Davis 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; + } + } + 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; + if (entry->type == BCH_JSET_ENTRY_btree_keys && !entry->u64s) continue;