Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp445551iog; Mon, 13 Jun 2022 06:08:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzeVQTmbGV2J6Lvez3jtxAtzLpEEFDiMQzQ73N4HDf3cnazeuVNJkvF8Bm3FUMsj0HNSqZB X-Received: by 2002:a05:6402:2812:b0:434:dcb3:c85 with SMTP id h18-20020a056402281200b00434dcb30c85mr10494823ede.1.1655125590652; Mon, 13 Jun 2022 06:06:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655125590; cv=none; d=google.com; s=arc-20160816; b=rbhr4KKTXeUTTq+6U1Y5bhmWeljLb1SQnR0TcD7HMxRIawcT1z/+LiCF3edlWvg0oc zGFV4yWHzFCtyTN+rEKBRi68ZtlVawGMCDxBtlbHBHRubAjZ7ZxBBGWBN8CNXtq/lFUs lm73Gdf/AugYtM8jledtxwbwqmKrMsgqxq4kPve4xvvDonxg/IbGBvfBKVdQ8LnmGeSL L5b7NAuTYdoMYOihrtSNrTwcjn6GDoArn06v4oVWXAw4D5xxyrUt5HYD7LrFTYIrGAjN 79+gas8wxrdSteItVeGhcjGbl8TsbgoVxRdaeZgGMrWLui7WmiWnIo0OWE9o9NUrz1M+ oCUA== 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=/fiFmwe4B/EfX+JRD/DsIglKMkHw4jeqVJQjwDewBuQ=; b=PmrPd0N0p1JL3IyAsstfjYevd5q6jDnNsuo5iyeeLcj+1pLfFRdIeVMigXxwnqwlaq RDvGWMDkjkm0Q+LhdAkK0CZkBU1IqjHltFFPkFnmh2IhgmElz+M2mQdUMglfRxpEam0D SCBewW94D678eJCR4B0QY26NEIO28qbZxyovg+kiynjcsp5zLYc1Q0uF/RqTLk4rL1KL Cxdhg8DISAt05VBF9U9xmKDLD0ouYJ8yZ8CWwO8IQpa/yJaRnGiiav9AgobfeOjuKzKe lB9M/HniFS6K/Nh+taKmTM8qM1zuxg/Ozpg0ofoWXfoMpitMPjMbGYgJKk5uJmIYiFqs b0tA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MP8DdSvu; 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 m10-20020a056402430a00b0042fb1fc374dsi9105787edc.399.2022.06.13.06.05.50; Mon, 13 Jun 2022 06:06:30 -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=MP8DdSvu; 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 S1351333AbiFMLFy (ORCPT + 99 others); Mon, 13 Jun 2022 07:05:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348995AbiFMK4p (ORCPT ); Mon, 13 Jun 2022 06:56:45 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97F712558F; Mon, 13 Jun 2022 03:32:09 -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 sin.source.kernel.org (Postfix) with ESMTPS id C36D4CE110D; Mon, 13 Jun 2022 10:32:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0706C3411E; Mon, 13 Jun 2022 10:32:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655116326; bh=Pee4iM1pwQZocsKFEr4FpnFl5ch4rnt8kPIrAq5CT90=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MP8DdSvu/akqLGqGrbc7hIuI7BvxmlsgJ9VRSjtF8hcFepldnmpYMi5UJQBbj+/1h LcbHXuhH2G5GId5yjzFO96mCgNZQihoP/5drQILZSoKXF5tWNUu3K12DvzqgOJhM2T HjOwRbwuDbS2PybaCnMxcgg4+6H5f0NBQcSLGA7Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, TOTE Robot , Zixuan Fu , Dave Kleikamp , Sasha Levin Subject: [PATCH 5.4 066/411] fs: jfs: fix possible NULL pointer dereference in dbFree() Date: Mon, 13 Jun 2022 12:05:39 +0200 Message-Id: <20220613094930.496548289@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094928.482772422@linuxfoundation.org> References: <20220613094928.482772422@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=-8.3 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: Zixuan Fu [ Upstream commit 0d4837fdb796f99369cf7691d33de1b856bcaf1f ] In our fault-injection testing, the variable "nblocks" in dbFree() can be zero when kmalloc_array() fails in dtSearch(). In this case, the variable "mp" in dbFree() would be NULL and then it is dereferenced in "write_metapage(mp)". The failure log is listed as follows: [ 13.824137] BUG: kernel NULL pointer dereference, address: 0000000000000020 ... [ 13.827416] RIP: 0010:dbFree+0x5f7/0x910 [jfs] [ 13.834341] Call Trace: [ 13.834540] [ 13.834713] txFreeMap+0x7b4/0xb10 [jfs] [ 13.835038] txUpdateMap+0x311/0x650 [jfs] [ 13.835375] jfs_lazycommit+0x5f2/0xc70 [jfs] [ 13.835726] ? sched_dynamic_update+0x1b0/0x1b0 [ 13.836092] kthread+0x3c2/0x4a0 [ 13.836355] ? txLockFree+0x160/0x160 [jfs] [ 13.836763] ? kthread_unuse_mm+0x160/0x160 [ 13.837106] ret_from_fork+0x1f/0x30 [ 13.837402] ... This patch adds a NULL check of "mp" before "write_metapage(mp)" is called. Reported-by: TOTE Robot Signed-off-by: Zixuan Fu Signed-off-by: Dave Kleikamp Signed-off-by: Sasha Levin --- fs/jfs/jfs_dmap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/jfs/jfs_dmap.c b/fs/jfs/jfs_dmap.c index 79f3440e204b..d3cb27487c70 100644 --- a/fs/jfs/jfs_dmap.c +++ b/fs/jfs/jfs_dmap.c @@ -385,7 +385,8 @@ int dbFree(struct inode *ip, s64 blkno, s64 nblocks) } /* write the last buffer. */ - write_metapage(mp); + if (mp) + write_metapage(mp); IREAD_UNLOCK(ipbmap); -- 2.35.1