Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp438480iog; Mon, 13 Jun 2022 06:02:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+wHGjtNP3jKpngF3VVBrn5+kXwmW8K54I/U6sCGx27UbscZxrwVzTdlPtdUiV205UDt8l X-Received: by 2002:a63:574d:0:b0:405:12c1:5b06 with SMTP id h13-20020a63574d000000b0040512c15b06mr11045998pgm.387.1655125260936; Mon, 13 Jun 2022 06:01:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655125260; cv=none; d=google.com; s=arc-20160816; b=0zz1FQsJoKVF7rGks7iWFCNt5aGNqklvBTUDP0S/AhZAYvj1+v+RZYPBWYOiI0Bw8P 1s8FPLYhEr/ADqVOtxiTdfx8xbG5k7+rh4QKLg+wWziYVsKfsoAdKxkFVUP+DNemhPLC 5i39kBEL49NCg63JmG26SRoIlr84Wk8WKML7Jl8wcXjcy3V7mAToxV2pPAtiFlvPqqF0 zU8CH2FgXqsTwls/DCTAzDIuWt/Jb6psuUVqEDN6af0MgXMN7G1QrUL8apeDLz+QGrKk JVvXbOmOeEZinCiLjrzAwgZeXAxeWIQjp5e8nxg+F7dXmvGbzC41EsdK8qTMqfGCXvPm y6/g== 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=eN4asmI96GyxselTGzAxv10vWNY5lRkj22BXKYDEvDrwV9tX4IKDOVcvF22OCI8y5S hUlz6lZ8JAKO1byYin1JiS3rPMoaF8GzhHVJCKMa4qTb60RL+/9LPFPbNY54ib/Y1vYu 2NxVmWuQs4Tw6uacA8if/54IfY0m2pw4fOVS2JHTwaovVhkoyq3cUPFDK1LIB8870Sbg vAmKNyeiyBASqbHdsU9MiCy6rCrBcGSlPkQ2sgIt+re33fHFYg8G+clS0jsm1CxgmOY9 Yt3LSOVIY+sX7q8+WCYV3MSTCoPqxXu+LkuYyXg0egce7/7N0kDaPMR5u/ZtqZwn8j1g Tghw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yandbVBh; 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 k8-20020a056a00134800b0051c6152700asi10453507pfu.136.2022.06.13.06.00.43; Mon, 13 Jun 2022 06:01:00 -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=yandbVBh; 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 S241381AbiFMKQ4 (ORCPT + 99 others); Mon, 13 Jun 2022 06:16:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241895AbiFMKQd (ORCPT ); Mon, 13 Jun 2022 06:16:33 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9485DF81; Mon, 13 Jun 2022 03:15:14 -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 13BD3CE116D; Mon, 13 Jun 2022 10:15:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DD773C34114; Mon, 13 Jun 2022 10:15:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655115308; bh=LZSVzGm+eApsXK45dI2BFu9jzJnYL96WdCNobNzk1qI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yandbVBhs3DMfyinrUDa5/s4uE6R8stXOSx9myXrWlTxtj4ZPcAarfBm6L4adRyWR UdTpui0IDY8Jr8gAFj6TWnTqgvj5PPOnfI0ljB6xLUSTE7WdW+p7G2ag8gvnE84a+j pAbJ0Lh2DKWHLEHMUD3e+T5qoElBtOgNjVNLEeeA= 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.9 027/167] fs: jfs: fix possible NULL pointer dereference in dbFree() Date: Mon, 13 Jun 2022 12:08:21 +0200 Message-Id: <20220613094847.160310293@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094840.720778945@linuxfoundation.org> References: <20220613094840.720778945@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