Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2155823iof; Tue, 7 Jun 2022 21:37:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxvpWHxXDam1a3rbgvahxhuMKByoBrWaFAMicLmgiD2fGyTYlP+IaqDyhXYoTG1rl30fyWz X-Received: by 2002:a17:902:db0a:b0:167:466e:b72c with SMTP id m10-20020a170902db0a00b00167466eb72cmr26309462plx.172.1654663048793; Tue, 07 Jun 2022 21:37:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654663048; cv=none; d=google.com; s=arc-20160816; b=aQJOgNQhtT7GGfZvvidUlCf49r5oAh4LYILA8QPw1YQw1MhtU2Xb+wpuF9Syv0c9W7 RwFzdO7uFdiJN662wbnLJv/shj2uHv7lqfTh9m1I0YedTDPxWS3CR6PqNgbs+ZTynjg3 GZQEZ9ki7FDATgtgFSoEBfMZ4ICSdGQyUYVlWJHU+UuclXu2MgAFHi0gOqVaZzI/8ph+ iaKcjRM4oSJg9XfM5gGJuZDPXTM9RMTju4U4iIDpqMfUOTXUm0PiVbZZ9qRtHo/Msj7b 2FF47pFrUdyWDijq87kzx231xWLXPgP1QAvgFFRlkCRsY2WgVvPHSLozlAGVO9a9KUhu gh/w== 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=NBAPCz/LPCfU6khmJqUlpn4HJlBE5V3eCtdMRZSnKmY=; b=dVNdnO/W1aqsjvaxDD5foYmSrFeSGE/jgs/fgOgi32E+jNe3/FhJCwFlAskY5bqQ5b yRDedFXVdsPLp3BnzKn7GMoe4XBwyvVcZtV0SYV0rghwaeDmB1Ihjte4u2/Dq3EfQf7q TzrQaYnhT8Bjh255a96ezx8m+6FKHbem13QadBldXOGWlLkouSjOZxgpcz0TVQXbDAde NTml5CN1fnNZVdm0x2ZblsY7/pEGtMgVwRQT+gZQcYkFuLSDBCmx382Roq3o4AE4jAls dnxyZ/a2nn5Dyfr5r4xvuvP4u63a0SPijY3BtI4AX89EBXu6wetPHVF1uv8AXdISlBvR GrxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=p5Bc4d2W; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id q18-20020a056a00151200b0051c1fbd5d08si10881335pfu.307.2022.06.07.21.37.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 21:37:28 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=p5Bc4d2W; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4A0D5435196; Tue, 7 Jun 2022 21:08:40 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347048AbiFGRcr (ORCPT + 99 others); Tue, 7 Jun 2022 13:32:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346470AbiFGRZL (ORCPT ); Tue, 7 Jun 2022 13:25:11 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D06291059CD; Tue, 7 Jun 2022 10:22:49 -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 7EDEEB822B3; Tue, 7 Jun 2022 17:22:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C9A3EC385A5; Tue, 7 Jun 2022 17:22:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654622567; bh=ma7wx71PH5A9um/tqLsM/4B68rrnnd9bIJDnMJSd77Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p5Bc4d2WFYeHMI/tlX0D+y6Xse9MI1yYdYfKMF3JYIKJMkJvaH6YZSYPHujAd0i9J QgP+iGOO+jelqYRy4ru2SUIblUByQ3koYmo3e9aLNgkobt5rQ03V8/zBOeu4gzCfff IfxomYsv2yZTS/Zu3ZoPcke/qlE/RG/uAkbGGrQg= 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.10 104/452] fs: jfs: fix possible NULL pointer dereference in dbFree() Date: Tue, 7 Jun 2022 18:59:21 +0200 Message-Id: <20220607164911.656168253@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607164908.521895282@linuxfoundation.org> References: <20220607164908.521895282@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=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 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