Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp4537117rwr; Sun, 30 Apr 2023 09:15:17 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5jWoT3Tq9S08tIuKK2r4fcAwPbfpxEhuJMgDN3rU/r/JklsSDGSF2gWHMGZabPYAZjc8AD X-Received: by 2002:a05:6a00:2314:b0:63d:3765:dc8e with SMTP id h20-20020a056a00231400b0063d3765dc8emr15204706pfh.32.1682871316740; Sun, 30 Apr 2023 09:15:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682871316; cv=none; d=google.com; s=arc-20160816; b=wTNfqhsop0TgWAk6rBsxAbpDoPEOduXv3uIl3pw1BY6tdOoOXfzO3UBirIGbG2242l xvhIE4EOnmEvWhOChJAPwxpPT96Ck71kT92oib83NhztqN9WfKyqLxtsRqeRSIDGzX90 pXH1cYcxEj2NiOrd0qi0QKDOjeIhblA1OkOAVyHwCP3QVS31D6vabSybekIuLNehsx0w VPdV7GPA8o9dk578TgM5E0dBHt/LEyLTPFbo3vRcMJv1cXI7PD+ug2WS9aJLnnHTsUyl CtGji4GvA3Eb4rEA0wlfRsqATfwf+RVxljNavO7UtddMvksetM364Mx7Mb0jpu0QunlN tgZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WzpHreJGFcaaxgm7kWLsXwX4Tn7aNtKLigaC5RrlqhI=; b=VglehQJErQgIr2tsLvcR4ryKk3CARnUEJWNmiG88JyGTfPca3GYfknLe+9ZlY0r5tC OknzLebZKHgvexmOVoE3PcpluOo7RoLEptCAUSKh3iw5IGUmzQ1m2FJ11RWT7iRoPO8m az0+F8PSeE9YwKSugMTrmEJl3f8vDqhQplfdv+JtsYN1D43ztHy0Y+N1CbW0Atn0GDNb N/xLw6TEMcC2/9U1BLNCJ9cagArjT8VrNofrqh2WO1wryBh8P524GIb+6doykj3jxYLr zZ6g8Kdt/TJUnDOUOFV8NKGpOeiPmuCytd/+eu+4ADf9KPzT3LHvwIpgR+6sNTTvxv3o 5/5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mit.edu header.s=outgoing header.b=KswkmOfq; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mit.edu Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u185-20020a6279c2000000b006374bd74796si26638616pfc.379.2023.04.30.09.14.55; Sun, 30 Apr 2023 09:15:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@mit.edu header.s=outgoing header.b=KswkmOfq; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mit.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229452AbjD3PnY (ORCPT + 99 others); Sun, 30 Apr 2023 11:43:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229636AbjD3PnX (ORCPT ); Sun, 30 Apr 2023 11:43:23 -0400 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCB8319AF for ; Sun, 30 Apr 2023 08:43:21 -0700 (PDT) Received: from cwcc.thunk.org (pool-173-48-120-46.bstnma.fios.verizon.net [173.48.120.46]) (authenticated bits=0) (User authenticated as tytso@ATHENA.MIT.EDU) by outgoing.mit.edu (8.14.7/8.12.4) with ESMTP id 33UFhGbO021728 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 30 Apr 2023 11:43:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mit.edu; s=outgoing; t=1682869397; bh=WzpHreJGFcaaxgm7kWLsXwX4Tn7aNtKLigaC5RrlqhI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=KswkmOfqM3+RjnqFRQRzKHj1jqEiPlEkE8ApZHSf031ZWspYf6uBfTovdI/g3JXlK II8muqG6pZe97x5qTYTYiFqubLjAQOf8x4GqhYM/56yRt5CuvoVx6P7v4M3DrRynmQ BUsZ7NRdcg4FhHAce91JxVjGd5xKY2m49gf42/XuLDbzOHgnkV4jMzyJrkQn56lQta NTiBiqRFREAiuGiP2RtqlkT9XIMOiOXlrkm4F4pYqOz5E9MPf4m05GlS/syLjvFXF9 I/gDhFefDRom3IBhK46zky2SHspcM/QJuZ4b0I4Lsh4MAz+xzsOF+01KMdJyFEo5LQ p0yShq8Q1PClQ== Received: by cwcc.thunk.org (Postfix, from userid 15806) id 6341215C02E4; Sun, 30 Apr 2023 11:43:16 -0400 (EDT) From: "Theodore Ts'o" To: Ext4 Developers List Cc: syzbot+e2efa3efc15a1c9e95c3@syzkaller.appspotmail.com, "Theodore Ts'o" Subject: [PATCH 2/2] ext4: remove a BUG_ON in ext4_mb_release_group_pa() Date: Sun, 30 Apr 2023 11:43:11 -0400 Message-Id: <20230430154311.579720-3-tytso@mit.edu> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20230430154311.579720-1-tytso@mit.edu> References: <20230430154311.579720-1-tytso@mit.edu> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org If a malicious fuzzer overwrites the ext4 superblock while it is mounted such that the s_first_data_block is set to a very large number, the calculation of the block group can underflow, and trigger a BUG_ON check. Change this to be an ext4_warning so that we don't crash the kernel. Reported-by: syzbot+e2efa3efc15a1c9e95c3@syzkaller.appspotmail.com Link: https://syzkaller.appspot.com/bug?id=69b28112e098b070f639efb356393af3ffec4220 Signed-off-by: Theodore Ts'o --- fs/ext4/mballoc.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index dc13734f399d..9c7881a4ea75 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -5047,7 +5047,11 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b, trace_ext4_mb_release_group_pa(sb, pa); BUG_ON(pa->pa_deleted == 0); ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit); - BUG_ON(group != e4b->bd_group && pa->pa_len != 0); + if (unlikely(group != e4b->bd_group && pa->pa_len != 0)) { + ext4_warning(sb, "bad group: expected %u, group %u, pa_start %llu", + e4b->bd_group, group, pa->pa_pstart); + return 0; + } mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len); atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded); trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len); -- 2.31.0