From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA1BBCCA470 for ; Wed, 1 Jun 2022 14:06:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354378AbiFAOEz (ORCPT ); Wed, 1 Jun 2022 10:04:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354368AbiFAOEO (ORCPT ); Wed, 1 Jun 2022 10:04:14 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 706BAAB0DC; Wed, 1 Jun 2022 06:58:46 -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 5F6F7B81B43; Wed, 1 Jun 2022 13:58:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 14D88C3411D; Wed, 1 Jun 2022 13:58:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1654091891; bh=ma7wx71PH5A9um/tqLsM/4B68rrnnd9bIJDnMJSd77Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=axPqqM0Iqgq4obTT0HmwvCZx50zBMI/0zhC6ijd9aPAgb2/1rzOEW5WUiFhI+QvJB XsA1ehTvK882UKB2n2UCo1+lA7m5cTQYRLD59InNdjdoNrOnCBm9oDBJbwZJpM9V9C SjecrtL8f+E80g/xtd8FN7zmVozdf3P8eJ8Lu5U1h0OE6GcXqXckVIifxmiwtKYDja 4h+k1prGsrae1ul54IcnNlP3uXU9zgC5okMG41qv89EiGXGKZWdBZSwr4cqjYmLq55 F/kkA3b4CnCLNHh5ins6JS74gbL3uAShINdrz8tRlW4OW5PXNEy4WURYiEc8wux7na wfug0s9Zq61aA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Zixuan Fu , TOTE Robot , Dave Kleikamp , Sasha Levin , shaggy@kernel.org, jfs-discussion@lists.sourceforge.net Subject: [PATCH AUTOSEL 5.10 08/26] fs: jfs: fix possible NULL pointer dereference in dbFree() Date: Wed, 1 Jun 2022 09:57:41 -0400 Message-Id: <20220601135759.2004435-8-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220601135759.2004435-1-sashal@kernel.org> References: <20220601135759.2004435-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@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 e58ae29a223d..0ce17ea8fa8a 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