Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp601300iog; Mon, 13 Jun 2022 08:56:17 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tCIkKR6EvhRD35tH41lmOraPVRkCqr73iMoygZPMXHMXZB9wAuC6ezY96Ne49vbd4Q0JIg X-Received: by 2002:a17:906:a245:b0:708:ce69:e38b with SMTP id bi5-20020a170906a24500b00708ce69e38bmr474738ejb.100.1655135777237; Mon, 13 Jun 2022 08:56:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655135777; cv=none; d=google.com; s=arc-20160816; b=NK1Z+sJCtE4kyu821JspqpdizQIgf7t45EOI56/jcYrZMAA2Pgb7OFUzzGpYdJMd1R hWN2pmBhB3GrS1YGWUQSY8xU9ezbvD8Ay2iPesQJH7aPGOsrRTgLTblIr9TxWc+XIrmg SyuapyPUVXzhwtWik8LJdO9So0P2ej9T6olPoeggQoG7aXS8HjJj9MlrsXk9THLPdiS1 Zs46yzJcH1ahs582Cy12vPyhMwKHeqS/zsWbjCKVHfrwiqD1LKVgI+eRepbc6WY6PfYM eTWogREOyU+PYnT7DWqA4ncvVT9tWYF81MVaSN7EiSseVLddxi+PjGanA/UTdlN6wv30 K61g== 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=5AOcHA8Mt8Aqt7MmEzwBBgYUt1NMFxIdv9xfUrewv8g=; b=FDSWvqy1T4ngwlzNEnv22Dd6gCRj6ZE7EHHNBcZsUWEXtVvnZ6d1TNwYEb39Axmyvd +N6dVDPdxwFXLUXQ9+Sp72Vdqnscm4WOLnOQ7gEJcLLNvBmkZz30/LqhS8HCiZzP+/cJ kISqIQfzJ77s8bn5RlQhCrqFgDitHutIYDW9tfia5xnNE05oJEtJhPsmnoAT9oKmdstd aXhlBewS0YN67t/Fp2roJGTFG0Zpop63boXEBd4AV47NGUapS+zWyZals5QPc6lV2HUF 2nU1ay24UZT/l98EP+V1pTS5m3vcWOiARss+B8FIW1FQvswbYZ3vrAPW6TiXR5C1rMax enWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=H631xtKv; 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 sb10-20020a1709076d8a00b006feb6e5da98si9031707ejc.625.2022.06.13.08.55.50; Mon, 13 Jun 2022 08:56:17 -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=H631xtKv; 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 S1346207AbiFMKj5 (ORCPT + 99 others); Mon, 13 Jun 2022 06:39:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344741AbiFMKhs (ORCPT ); Mon, 13 Jun 2022 06:37:48 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C358F12D35; Mon, 13 Jun 2022 03:22:54 -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 dfw.source.kernel.org (Postfix) with ESMTPS id D928660AE9; Mon, 13 Jun 2022 10:22:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E2E26C3411E; Mon, 13 Jun 2022 10:22:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655115773; bh=LZSVzGm+eApsXK45dI2BFu9jzJnYL96WdCNobNzk1qI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H631xtKvoT23BZAT9jH4NgqxSHDpSVVSyIs5dyIsaMZzzXaUj5XcANsxWjFTYhA9G tIqkOxvt+dOcOlJloRii0XTfMxSNWNoBpg4gk8NPHLszTSX/Yu78MdzY2Z2ILRy+GL v2TbcWQhwukKYKQNWXf3xPyYPs3aDSU6YfR5MHYc= 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 4.14 036/218] fs: jfs: fix possible NULL pointer dereference in dbFree() Date: Mon, 13 Jun 2022 12:08:14 +0200 Message-Id: <20220613094916.886990683@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094908.257446132@linuxfoundation.org> References: <20220613094908.257446132@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 6dac48e29d28..a07fbb60ac3c 100644 --- a/fs/jfs/jfs_dmap.c +++ b/fs/jfs/jfs_dmap.c @@ -398,7 +398,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