Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp3807593pxb; Tue, 19 Apr 2022 10:11:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzF51Ux9wlxO2etOvglfq8VdVMpCN6StO6YHSNADoZ7BTDg3vToe5YLN+37kpd0OqdOKRo+ X-Received: by 2002:a17:906:81ca:b0:6e8:ad09:1951 with SMTP id e10-20020a17090681ca00b006e8ad091951mr13987797ejx.745.1650388288997; Tue, 19 Apr 2022 10:11:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650388288; cv=none; d=google.com; s=arc-20160816; b=zrljakpF+e2NtBjKO1gqC45rbDwS+4M5JwZ31ewqIr6R/fwgwHKY85pCIKo+BpBT7f PXNUF3zulqbVEGT4+LDJwyZuzv4wln9wTzvSJuqhURO1OA4CB9eejkjDyGz0cs2xralZ Hn3lvGycXX8btpgfZe8i9B87lfmLEAjEXw694meZk9VQKkoc05tBWic4J0zbqmHKoPRu 4B60w/wNt20F8rWM9YhSQ33WzO9/2tp0HECYg5VQYJoE4f4BGw8kVWkNGLPHeb7f3BdY FRvUhRfFAKwYVMK1RsIkiOnY7cpYrUHJCb+E7SStRYv5yJzZdxJviAJpWr4Vt/We4KLv PfdA== 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=yk1GenNmRRR4zb3oXgQLXR3JhdMFJ6KovLhXPOYquXU=; b=zP2ixMfaGxkpqlEpJo1J9lHCy+f1+IDreNi7QtU0arJ0JG/ePNkEtU7u5y8upHYynQ pYApVZuPPTTBaVxRVuLCswxZeW3MptHIrpe4V2TEdRgG3K1TTO/gE47uExEcVGPP2sSg NPtfQJaNTkaBjgVyCRZs5Rne+oE1ZDODCo2X2oRTacH+mbesA8+wIXAwZQTyyhxROfNa FLK48DKI7aFb9KX40m51bgaQBO/ZbAErszre8URNk3B3ZfWwCL9H+XQEprBZADQhxuKw 1E+hFs8NZ7OBIN8VdrfQ0lk2jXSRAVd67NKVt1LF40vPGselGoU1yMrHUKRZ86wGlXr+ ye3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JbChApY9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g9-20020a056402424900b00418c2b5bf0dsi9740064edb.495.2022.04.19.10.11.01; Tue, 19 Apr 2022 10:11:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=pass header.i=@linuxfoundation.org header.s=korg header.b=JbChApY9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243963AbiDRNuS (ORCPT + 99 others); Mon, 18 Apr 2022 09:50:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244553AbiDRNai (ORCPT ); Mon, 18 Apr 2022 09:30:38 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92DB1427F7; Mon, 18 Apr 2022 05:54:44 -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 4E6EDB80E44; Mon, 18 Apr 2022 12:54:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3EF2C385A7; Mon, 18 Apr 2022 12:54:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650286478; bh=ofJ4spLJs3LiYL83YZiZiU6lv3R1zdUaKtVleqjM0Us=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JbChApY9B5un/u/+BhCTWRhRbcptz0ATSFoYCaNSc3hsyJPbdgHgws84C4bNkxE4m e4gQ53L7xQnQjoVbBqdcAv8V1eVoBCGEep5rjZJtJ6ndWKKcllzr6QWvtcjjkNuMYh LIo4XOG9KHJX4TboR8jzc+tZfvUXSsfuESG9asnY= 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 4.14 147/284] jfs: fix divide error in dbNextAG Date: Mon, 18 Apr 2022 14:12:08 +0200 Message-Id: <20220418121215.766250246@linuxfoundation.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220418121210.689577360@linuxfoundation.org> References: <20220418121210.689577360@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=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,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-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 9ff510a489cb..6dac48e29d28 100644 --- a/fs/jfs/jfs_dmap.c +++ b/fs/jfs/jfs_dmap.c @@ -161,6 +161,7 @@ static const s8 budtab[256] = { * 0 - success * -ENOMEM - insufficient memory * -EIO - i/o error + * -EINVAL - wrong bmap data */ int dbMount(struct inode *ipbmap) { @@ -192,6 +193,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