Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp6813901rwi; Mon, 24 Oct 2022 06:29:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4ODX9v7G6rhg/KmFZyVHy4EkizEnTbs1XtA97yh4nXAGo0fIy8URK/rLCdl0Lmtvm6A1OK X-Received: by 2002:a17:907:7da2:b0:78e:25f8:8803 with SMTP id oz34-20020a1709077da200b0078e25f88803mr27306190ejc.723.1666618178895; Mon, 24 Oct 2022 06:29:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666618178; cv=none; d=google.com; s=arc-20160816; b=sl/o4OQBt9R+WrRgWC1thlhy/GhNaW0L9i/3v0mHj/F3SQd6WpV5gHadUXiJztm8W8 zEVZxi8t4b+UwFun9b2WPUWow8nk7Pl7V4YDRUIyCOiorMk6FGotRdEuY/DRfwh3bBJA LMN3JotVVVGi+Mp4l+NWTFZPqD5Tgse0VBYbHTeVT3o+fqUMVJ8ZT4+3yhftqoRSdhjc tozsmJ43E+62pPoL5g8JyCB++0TKB75Fo0vbA4uZ3/R8FzxhKyIASlBqeUKrSHBarUoG 9A1IIT0TOvyZ6r1nAd3I6EM2vS0jYMQ3Dm8+bcs79s2CtyFiawa7E/ioy6YsRO0BQrm0 Vb8Q== 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=cdEeemcQPWRYp52IVJQkTdS4ZBGC+i/9stMn/yqQ9IQ=; b=VlpsCBgyGkMsbSo21zGBNkC2V0t1bNtLd+nOvvpOpRyLWTT8Ki5F/lCgffPdYeYc1k pCkmpbqfWnmmZsSQqSEi8Q13iqJMzv0ikosMKSHdq4gSS0AM7E1IaFLK8q0g+WvcKWZn 1KWOL3Axmdp3YCWl8DQss+zFwO5gULYY6q/17pbj12qZS9AVWRIQ2YBIEynzbmOspT7n L0ifj1brbRVN6Y/0283Oe+rAlGhtFZrl6o8aXAOR1jCBHMpV/NLoqRoUZ1MNb0cfvjKt Z0mwzaAxM6f+95P5GYTXVXrknHEv5gw9QwkMjFzfB5MYdBT9xKXkpAZNiRxq7KHxJLUG jAcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nxaYOUH8; 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 hr2-20020a1709073f8200b007919b3ad78esi20279755ejc.495.2022.10.24.06.29.12; Mon, 24 Oct 2022 06:29:38 -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=nxaYOUH8; 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 S233730AbiJXM2K (ORCPT + 99 others); Mon, 24 Oct 2022 08:28:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233742AbiJXM1G (ORCPT ); Mon, 24 Oct 2022 08:27:06 -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 5D0A2857D0; Mon, 24 Oct 2022 05:01:24 -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 20225B81031; Mon, 24 Oct 2022 11:46:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 762D6C433D7; Mon, 24 Oct 2022 11:46:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666611977; bh=Cp7+DWlpUZah8k86BOmAXEwfQ215gZeltIl98Wd2g/c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nxaYOUH8vnpY3j2vEHT1rhGbpdubRHBUS/0zf8j7rUJN8ry1reXe+m0mhWTa0CPEQ aMEG/k6GnNm2qvr8Gs0t/ezEschSCDMJpF9QOC507UliCzYKMLMXqZkzxs6Zjq2gye c9lYrySmRChlJoa177CzaJBCzBDWFMOFWJNGpnj0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, butt3rflyh4ck , Hao Sun , Jiacheng Xu , "Christian Brauner (Microsoft)" , Dongliang Mu , Al Viro Subject: [PATCH 4.14 023/210] fs: fix UAF/GPF bug in nilfs_mdt_destroy Date: Mon, 24 Oct 2022 13:29:00 +0200 Message-Id: <20221024112957.719455844@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112956.797777597@linuxfoundation.org> References: <20221024112956.797777597@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.6 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 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: Dongliang Mu commit 2e488f13755ffbb60f307e991b27024716a33b29 upstream. In alloc_inode, inode_init_always() could return -ENOMEM if security_inode_alloc() fails, which causes inode->i_private uninitialized. Then nilfs_is_metadata_file_inode() returns true and nilfs_free_inode() wrongly calls nilfs_mdt_destroy(), which frees the uninitialized inode->i_private and leads to crashes(e.g., UAF/GPF). Fix this by moving security_inode_alloc just prior to this_cpu_inc(nr_inodes) Link: https://lkml.kernel.org/r/CAFcO6XOcf1Jj2SeGt=jJV59wmhESeSKpfR0omdFRq+J9nD1vfQ@mail.gmail.com Reported-by: butt3rflyh4ck Reported-by: Hao Sun Reported-by: Jiacheng Xu Reviewed-by: Christian Brauner (Microsoft) Signed-off-by: Dongliang Mu Cc: Al Viro Cc: stable@vger.kernel.org Signed-off-by: Al Viro Signed-off-by: Greg Kroah-Hartman --- fs/inode.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) --- a/fs/inode.c +++ b/fs/inode.c @@ -165,8 +165,6 @@ int inode_init_always(struct super_block inode->i_wb_frn_history = 0; #endif - if (security_inode_alloc(inode)) - goto out; spin_lock_init(&inode->i_lock); lockdep_set_class(&inode->i_lock, &sb->s_type->i_lock_key); @@ -194,11 +192,12 @@ int inode_init_always(struct super_block inode->i_fsnotify_mask = 0; #endif inode->i_flctx = NULL; + + if (unlikely(security_inode_alloc(inode))) + return -ENOMEM; this_cpu_inc(nr_inodes); return 0; -out: - return -ENOMEM; } EXPORT_SYMBOL(inode_init_always);