From patchwork Thu Oct 13 17:52:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 2118 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp403977wrs; Thu, 13 Oct 2022 10:54:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM71ZZ31F5IiI36ByWZ9jxBDhVyTq3PZp+1n5fTLUxZ731nDDNug/ynmtsp2uMlGsEJg4qGU X-Received: by 2002:a17:903:2684:b0:17b:7568:ffea with SMTP id jf4-20020a170903268400b0017b7568ffeamr880389plb.128.1665683650959; Thu, 13 Oct 2022 10:54:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665683650; cv=none; d=google.com; s=arc-20160816; b=fLtufgNbw/0EtS562OKN89bCmI8vY50EsODVzlX0OhkfwV22MqbAwdOLs5Rf1fFuBn hEx6q+6HZBpY2jdBRmMzn0QDvowZHX7AKhRwQ+LyyE7plk4p3HdTlWhbn8kpc0xlCgw0 s+KqJGZZH1uFCbZrYgqr6HW7C0BqvreDZwaEGztkDFG52KMUbpOnaZ2n2a/ogKtcQwhJ iqnmLAzq4ljBubMqO32tSmRXb+FR3yK40Y+qDEZIKAb8n9rW1sxOvvogcpFB9YdWw1Vq AMAZgBrohKWSPIOKjHQif7Xr9DoqWYVecpR/G1Wrb/o4XrhBlcssDKGH1NwqNHtM04sM Q19Q== 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=Mkzgg/hojdaR12nkcibPKZKy4a+CO4C59Ld99lfyKqw=; b=OePgOVstO/9qSqoBeS5lpTtIDPdkA77KiCU8FJU52L9cEWSTEq61F2xzJTYQ5ww9P2 6QqvWgkn91mJpCtJBk2pF8Ac9DnPOXLYEWbxueIiE42DzZEntj/lji0U/rPVGN7itwXK 3eDVIWYffxGCCvMpFXvZ0pdhc67/4NExCjjuYr/d5XYC0jEIVVS33XrSPsyOCL2pM0lN fgWkrvFIwNyZoEAjWnHp0ZY/cmlzhRaNsIVBcnt59RTCGRFPdvSeBLNRBf6lXnC3gjuc n6IXCNtwCgQHvj609L1ZBxqBI3Hc7Kdu34DX9JbJ8JrnGaM6MtuqoL7DxAPMCEkwIXFH FMaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2bMnOxvV; 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 l7-20020a654c47000000b0045af77f7f19si22521pgr.400.2022.10.13.10.53.58; Thu, 13 Oct 2022 10:54:10 -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=2bMnOxvV; 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 S229766AbiJMRxT (ORCPT + 99 others); Thu, 13 Oct 2022 13:53:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229676AbiJMRxI (ORCPT ); Thu, 13 Oct 2022 13:53:08 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6874315200F; Thu, 13 Oct 2022 10:53:01 -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 dfw.source.kernel.org (Postfix) with ESMTPS id B269D618F9; Thu, 13 Oct 2022 17:52:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C48ACC43146; Thu, 13 Oct 2022 17:52:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1665683579; bh=LnlDADaOWtZSl9lwJTC4GMmlL/gmh302YmAW5WNpG48=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2bMnOxvVONjvGhnleM49h+KHvQzkqE2lAfTlvxsdp0bAyPMFwIN8f9hViqnUcdRLl 2XcBye3pjc2Q7cHJnkSz5pwvE+q4lOhQfOKZkXKEatc8HqI0DC2pBgVkFmv4qX2XS9 eM3w7yYSCqxxQo9XMn5GGZN5Awz0flGPGjRDB5jE= 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 5.4 03/38] fs: fix UAF/GPF bug in nilfs_mdt_destroy Date: Thu, 13 Oct 2022 19:52:04 +0200 Message-Id: <20221013175144.381807116@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221013175144.245431424@linuxfoundation.org> References: <20221013175144.245431424@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 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?1746595899865453324?= X-GMAIL-MSGID: =?utf-8?q?1746595899865453324?= 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 @@ -167,8 +167,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); @@ -199,11 +197,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);