From patchwork Mon Oct 24 11:29:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8742 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp427176wru; Mon, 24 Oct 2022 05:32:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7/rLj276VjUyB91ScyKFfMbmMFXPfCGqn6BOR0miNYHvhfvasCyp++TFN/Z8nOeGXFsZnU X-Received: by 2002:a05:6402:2947:b0:451:32a:2222 with SMTP id ed7-20020a056402294700b00451032a2222mr30171532edb.376.1666614777276; Mon, 24 Oct 2022 05:32:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666614777; cv=none; d=google.com; s=arc-20160816; b=ljdo/+YAnQWNdg9bQqV54pNzH2m9F9PNfvyypKfw1a9LiWR2IMsrwyaaCTH/d7ml1e S6tst6Wp+T1jjrlWBe+DvrRZhZzRZ+lJdlKwYe8wo9U6OEZkKwXyCJluql8swpR0OuWq wa02MPgu+dUTr+wg81ruIvCqdGEyFzN/pECQf7GyOct4TWWeBl0p+cxiMT2IqXYIQ1a8 sgAqn9YIYbg85GIfWNr58x7/143WYSWJfFGToHHtQU31nZpsWEevY1gd6tWhL0XPKNhV 2ii8pBH3iYtBARBDzYzVvt7u4rDF6H/xfEi2zHvm6BNpAuT2ftX0xNYJJXuqHRv3yJOJ BXEA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t11-20020a1709067c0b00b0078a3ef9f092si25462767ejo.998.2022.10.24.05.32.23; Mon, 24 Oct 2022 05:32:57 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747572256278891655?= X-GMAIL-MSGID: =?utf-8?q?1747572256278891655?= 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);