Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp964117pxb; Wed, 6 Apr 2022 05:28:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxUZ07h+95MrlXOmtdXc6bBx54I5oPOGd7EXA/vn5yAwnaA8BvblmUHC0W5swP3APjfplrp X-Received: by 2002:a17:90b:314b:b0:1c7:4a4f:6740 with SMTP id ip11-20020a17090b314b00b001c74a4f6740mr9683958pjb.145.1649248118090; Wed, 06 Apr 2022 05:28:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649248118; cv=none; d=google.com; s=arc-20160816; b=EUK0mwxcUWAsG7sbyjkX1119J3dLjG2X656DccLJhZ4b07/qRu7AMcX1JRwpo4pAUZ NkrWSyx/S0FoE/sI4pGB5KwdjO3zGHUyJzuL5WUkC4qty1Ks2M6AaiId47C/bbK2FtHF gZhb0a1HqZjsjUENo7+REdu3SwVgMy6IGhZPLY9peywFQGzhTdF3zJ29t3EbI8KAvSAS Rh8PPF39UwZJrlBLdPY2EM+iiILRXkISgvMl4a2z8dn6DNOCzIjY/HD9CSZ63dbHd0dV cYwAQjnCCFZ0Wm64IxhQPA9x5xUIGHUrneUqJ9fP3Ml4mcoEl+nvraejxEjfJgyoHz5L 43Pw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=jYoMAaMBRNhFHqP0+NWBTA6m3bPjOHHgLwgoDoN6JZE=; b=aKEzdKCt1ZFQcjEHS32bmBnX1eQXjhGEpEZxsGwVywj35Y03Wg5swvmo+Z8mnDyuLM U/BzsfD1al9J2kKUQuiMVVw/6VXhVpGyejqUT303Kk1sHm2Ouc8HcllupqQ+vf3tS7G0 8UVX+Bu/rEl3/kxOibfPv6JKNwHgFHym0lyAjX54CWbxg3pcB9FrGP545sPCCa42qLin S5ekjtoUEvCPRY452uW+d6aAf0SFA883Yy3Dy2qpAXBAljCGi3N1wVzLA0nL2s2dcw2a UWKLnPDD83zEYPil6DpkDzz1AtcUkbgLioYl75234WgvR/W+MH9yvpuy6Ie2Cc2JPZFu HVkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=loGaT7xd; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id a18-20020a170902ecd200b00156999258cdsi10877764plh.9.2022.04.06.05.28.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 05:28:38 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=loGaT7xd; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3DC8F6F69E0; Wed, 6 Apr 2022 04:39:27 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1453448AbiDEWdD (ORCPT + 99 others); Tue, 5 Apr 2022 18:33:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349529AbiDEJuE (ORCPT ); Tue, 5 Apr 2022 05:50:04 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E87381B4; Tue, 5 Apr 2022 02:48:06 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A4E57B817D3; Tue, 5 Apr 2022 09:48:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E91CC385A1; Tue, 5 Apr 2022 09:48:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649152084; bh=+ZIW8t4x0ThwpjfSahCA2lfR+DiLR6YdOj+9nIWr+Hs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=loGaT7xdkDFOg7Bzoa70i8sod4mOwAyfCB3zc76mt/jLJbyywFkSsaqMOG5P1Sh6O 9lWi6EzcRH7rSpQVAnN3+X7p1p5lhkczUPIWBfxm6Ui0KieihOmR29UJEyMs9ayxKy bgAF/1soWQFg6Qv+ovcviebh+v/vWY6Ep2Af2qJQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pavel Skripkin , Dave Kleikamp , Sasha Levin , syzbot+46f5c25af73eb8330eb6@syzkaller.appspotmail.com Subject: [PATCH 5.15 648/913] jfs: fix divide error in dbNextAG Date: Tue, 5 Apr 2022 09:28:30 +0200 Message-Id: <20220405070359.262982999@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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-kernel@vger.kernel.org From: Pavel Skripkin [ Upstream commit 2cc7cc01c15f57d056318c33705647f87dcd4aab ] Syzbot reported divide error in dbNextAG(). The problem was in missing validation check for malicious image. Syzbot crafted an image with bmp->db_numag equal to 0. There wasn't any validation checks, but dbNextAG() blindly use bmp->db_numag in divide expression Fix it by validating bmp->db_numag in dbMount() and return an error if image is malicious Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Reported-and-tested-by: syzbot+46f5c25af73eb8330eb6@syzkaller.appspotmail.com Signed-off-by: Pavel Skripkin Signed-off-by: Dave Kleikamp Signed-off-by: Sasha Levin --- fs/jfs/jfs_dmap.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/jfs/jfs_dmap.c b/fs/jfs/jfs_dmap.c index 91f4ec93dab1..d8502f4989d9 100644 --- a/fs/jfs/jfs_dmap.c +++ b/fs/jfs/jfs_dmap.c @@ -148,6 +148,7 @@ static const s8 budtab[256] = { * 0 - success * -ENOMEM - insufficient memory * -EIO - i/o error + * -EINVAL - wrong bmap data */ int dbMount(struct inode *ipbmap) { @@ -179,6 +180,12 @@ int dbMount(struct inode *ipbmap) bmp->db_nfree = le64_to_cpu(dbmp_le->dn_nfree); bmp->db_l2nbperpage = le32_to_cpu(dbmp_le->dn_l2nbperpage); bmp->db_numag = le32_to_cpu(dbmp_le->dn_numag); + if (!bmp->db_numag) { + release_metapage(mp); + kfree(bmp); + return -EINVAL; + } + bmp->db_maxlevel = le32_to_cpu(dbmp_le->dn_maxlevel); bmp->db_maxag = le32_to_cpu(dbmp_le->dn_maxag); bmp->db_agpref = le32_to_cpu(dbmp_le->dn_agpref); -- 2.34.1