Received: by 2002:a05:6512:3d0e:0:0:0:0 with SMTP id d14csp41767lfv; Tue, 12 Apr 2022 16:28:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzU+tJoctCyb/INLHfcRSC4M4efgaV7kThTODi9UgEfLVH0MSNEF0ULxtrRbkzxcKllCL68 X-Received: by 2002:a05:6a00:1903:b0:4fa:fa9e:42e6 with SMTP id y3-20020a056a00190300b004fafa9e42e6mr40496611pfi.1.1649806101631; Tue, 12 Apr 2022 16:28:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649806101; cv=none; d=google.com; s=arc-20160816; b=NetAdpBt0U5sbEV+P1IQMLlwtVJypKMeDwlH/5/OrheV9TgyAkOsrbCRl+sIuBQJv6 DRzMhwNrwj9nAuopZoc6BQJrq9aPZOnpxxHsf+0mJPvKv+3YU0kzrZkKNmmxOIiLvp7E coYyF3qU6LpqtSdXQqfGGwbBC1Ql4wRwmTLeXbIHnMhWP4q9IsNqsYjZXZ5yGV+Vv6Vf 8aimlJ94REiaAZWS+PZ3Qk+pqCiV2copXYvE1BwEQNfdPmKKWg6pSTWK1h5HEhpGfFOU DEYVtV8TwMVRa5xWjUlzs9ujFVtS3MNn5S8adH7uPFnanwrpwO+516PWTjkqKhhHeLQZ IBtg== 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=t/qNF5PxstOslNIcFM4SLJoGF34VL0uKC2I+UX+SKv4=; b=I/ZVLqSNDOsRfnaVst31f3QsRAQRDmTgVt2Bockzkd/tGgZtnSx7ABr77A3b76+zr0 5Tspa8F+0KSQbl+2Z6l7ktoNTExX+mou9sVWYauSUJyuHbi8LKlTa73hqMLt+Co91t0T TxvfB7aVubdDOkKzaVR6nUz6UXo6e87uFp6KP8GMxIuWzjjh5nDTrWcC88+JDDc77gGc O9i3VHNgFzdfMscp5sBGWCTqVo2TRhIA/7M3VHB+Au/NEil+Sg/P4YVFu0Gly202UdtM oGUpuaw36f1TbZdvrACewIJ7qK1c8PRAM555B5+G5KpL4ac3ZuSraNZE/jsBRO0+OZis W0Hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gCt2JlVv; 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 i7-20020a628707000000b004fae310a83csi12594011pfe.151.2022.04.12.16.28.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 16:28:21 -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=gCt2JlVv; 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 160CA1AE191; Tue, 12 Apr 2022 14:20:51 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353807AbiDLHQJ (ORCPT + 99 others); Tue, 12 Apr 2022 03:16:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351714AbiDLHEC (ORCPT ); Tue, 12 Apr 2022 03:04:02 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E0414507E; Mon, 11 Apr 2022 23:47:21 -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 DD892B818C8; Tue, 12 Apr 2022 06:47:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4FB11C385A6; Tue, 12 Apr 2022 06:47:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649746038; bh=c+omZP6b97ce8PuNMw7NgKdL3P/XKwm+AoC4Zyoc8Sc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gCt2JlVvjNOY8uaOnPlBucpPwAt7uboWpf+lamYcC55hu3r4t/RbEmGsv4ntqs3Ag nC3kaBsXdqpqv/LwSJv8dM6KoJjjBD17SSHkxVB3lBiNqGfIL74trrwlUChuNi1iqQ Xf2dThzzUtLmo0jbszT8AKbzEIeTFvra9mlljJTw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, TCS Robot , Haimin Zhang , Dave Kleikamp , Sasha Levin Subject: [PATCH 5.15 136/277] jfs: prevent NULL deref in diFree Date: Tue, 12 Apr 2022 08:28:59 +0200 Message-Id: <20220412062945.971780604@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220412062942.022903016@linuxfoundation.org> References: <20220412062942.022903016@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=-2.0 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=no 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: Haimin Zhang [ Upstream commit a53046291020ec41e09181396c1e829287b48d47 ] Add validation check for JFS_IP(ipimap)->i_imap to prevent a NULL deref in diFree since diFree uses it without do any validations. When function jfs_mount calls diMount to initialize fileset inode allocation map, it can fail and JFS_IP(ipimap)->i_imap won't be initialized. Then it calls diFreeSpecial to close fileset inode allocation map inode and it will flow into jfs_evict_inode. Function jfs_evict_inode just validates JFS_SBI(inode->i_sb)->ipimap, then calls diFree. diFree use JFS_IP(ipimap)->i_imap directly, then it will cause a NULL deref. Reported-by: TCS Robot Signed-off-by: Haimin Zhang Signed-off-by: Dave Kleikamp Signed-off-by: Sasha Levin --- fs/jfs/inode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/jfs/inode.c b/fs/jfs/inode.c index 57ab424c05ff..072821b50ab9 100644 --- a/fs/jfs/inode.c +++ b/fs/jfs/inode.c @@ -146,12 +146,13 @@ void jfs_evict_inode(struct inode *inode) dquot_initialize(inode); if (JFS_IP(inode)->fileset == FILESYSTEM_I) { + struct inode *ipimap = JFS_SBI(inode->i_sb)->ipimap; truncate_inode_pages_final(&inode->i_data); if (test_cflag(COMMIT_Freewmap, inode)) jfs_free_zero_link(inode); - if (JFS_SBI(inode->i_sb)->ipimap) + if (ipimap && JFS_IP(ipimap)->i_imap) diFree(inode); /* -- 2.35.1