From patchwork Thu Oct 13 17:52:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 2241 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp412974wrs; Thu, 13 Oct 2022 11:12:04 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5ajmMEn4a+1F7FObILShRGvnEGuKFTvbSBZSJuYPsfw6OJ9BCB5Q6ldjk0DvgGV0BsaPln X-Received: by 2002:a63:50f:0:b0:46a:fa85:def3 with SMTP id 15-20020a63050f000000b0046afa85def3mr1024689pgf.16.1665684723691; Thu, 13 Oct 2022 11:12:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665684723; cv=none; d=google.com; s=arc-20160816; b=EQ/Y/vZ1tYThNwEJVc/i+hcZ7KBzycVMBsMGcrqITbpvJ5EJjBbUECv6clwMrxVF6Z ixSXLTLWuE3wm0zLv/ZyPWqKfmFqwdTV4n37LJuaUOXRWyjQ/so0fx1kxfSv5iLiDj4x xhRS8bQdjuJvfltSFW9n6PJW9wolx2OByBibGgizQOVscoqbb+h89u1VWaFiZQ2h9Mzd yD0HzJb27Ek3/BJ2lRElcYusH7auarJZefD3wSVofy1wQ6X1/xvEdGLnX641HqCC3BRn sFi3GSJ5Kt4/vAns4UYXkiLrt/imIROzMBjMvD5I+uR0n0IPZGd34ocIUxoanAsOrCUw rcdQ== 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=UjQTBvOtVq+AxELm6NjUHJ7pL4SvibdmkAaeDAmQ/aY=; b=lPvfUMECVFgdrEfzHeTUjok6ZX3kIWcJSdYXL4ZOBZ5hk4v1TvOiVIhmrV5oSctYpE SiSvmCTQlkXksaTlRvCxi27ME9YO2wlxyE0S/UMDvqqJXOzmVs3RNhQtB4qkVlbkleyn LGAzNmvErLCaP+CTqb856jblZIuKFvT71fCwGRcPNpBkMXRNzQDCS2QaGROxDdMyWqup hlT4CDUYLFNI9YXbadlZf9eCq1tHTzPFoH8Z+HwIhe43bekquOKL+XVVPpEg7eT9HpXa uUogqcqYZ7ZeedExOTH8kDg3QG8Y/fZ3LJFr6TBmRG3hQrbcT+u6cValW4ouf2dG3PxB xJ/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wIGOGCxn; 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 k10-20020a056a00168a00b0055fa098c388si24973pfc.259.2022.10.13.11.11.51; Thu, 13 Oct 2022 11:12:03 -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=wIGOGCxn; 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 S231378AbiJMSLj (ORCPT + 99 others); Thu, 13 Oct 2022 14:11:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231570AbiJMSKh (ORCPT ); Thu, 13 Oct 2022 14:10:37 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69AEDD4A06; Thu, 13 Oct 2022 11:08:06 -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 DA03B61923; Thu, 13 Oct 2022 17:56:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA73FC433C1; Thu, 13 Oct 2022 17:56:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1665683787; bh=wpfl8bySceEuUh9c9AHgHNK40GS5fUzjOFlyRY3tiPY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wIGOGCxnbvK+C5sx4G3ptwYIuPbsvZaJu98o42iKqi1dww9johJEkbNJbcYS+kJoZ fn1LrZuYYVduCKhysavk1pmiw+I460pjlwoscqjMgletf9X6EEbPaB4iSk26fWnnFf aeyn7m2Ty4vw7G2y8qne1XqHUGEyFcK/LyUD0MNw= 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.10 13/54] fs: fix UAF/GPF bug in nilfs_mdt_destroy Date: Thu, 13 Oct 2022 19:52:07 +0200 Message-Id: <20221013175147.691384882@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221013175147.337501757@linuxfoundation.org> References: <20221013175147.337501757@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?1746597024588293141?= X-GMAIL-MSGID: =?utf-8?q?1746597024588293141?= 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 @@ -168,8 +168,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); @@ -202,11 +200,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);