From patchwork Mon Oct 24 11:29:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8417 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp400295wru; Mon, 24 Oct 2022 04:46:50 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4OTNJ4PZ/BNOzEV6OrLVTcxE/pcA+TeS0ha2mQwWQi4RJOc6jq0u6YD3n8NzBQQKJb+jMj X-Received: by 2002:a05:6402:50c:b0:461:bc01:1828 with SMTP id m12-20020a056402050c00b00461bc011828mr5278976edv.64.1666612009936; Mon, 24 Oct 2022 04:46:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666612009; cv=none; d=google.com; s=arc-20160816; b=PgN9e5HwBW7kOLtL0tbcFy1zj2pIOiNspJco4d7uoDCEFo3yOnSqOUXESm6iN9+wDp bRfz8Xa1cv1B0ytmJSIlsNI0dO173zuG4Rm3C6J2ZMPBqJZusVhdoVX+6ltiaSxREqpc Rl5Faik7OV4lUdKJdkGxI/GAIO5gHmVUt4MreNxF3insqUSkFRWBYoNnea1d5FUvCHWB nZmORQTfiieMkwgjak7qKKLn1nqAQ+J3hb9DOxaYzfKRoclBj+bWdThfKIk+uhjDlgHT 7Y9miIoErYrzC3NBN4pdNoJ7iN4vGHRbIj+iPebv5w4UfrbVOWefs5H5X7HQRfXINmxY mjsg== 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=yVLIAp4s4dGK2vKGbYR0yt+fNeipvLJOvc54W21y4nc=; b=zSgk7yMShlJzyjrn1qUC1glF5Plh0G5nFLVe5AUNadkA5VUQV/E+H/2ahSslgG9OFv W0sbNrmhy474MqNx0LvKMgYEDAOtJxqH8PoifC/N0UcPeUBRRRgv2tItX0tuQzGcfuhR AecVZ4S+fNV9M9fRbnQDsy1qc3ivyLhkA9Lmb7uZbdNflPxnR0m+k0PY08ncp/on6+vV 1RM0z4QajJfHszBZyoGRbinuGAgowpNXW8rTNcCF2o1FhAPT52qGkTB6rvSoYT2K2Y3K lsqXqftSJ+DEOcemfEPhO1wGfCUxcPFWz4Lp8BGFn3jhWdOMaP5fFpx4NG17BwKLzQNo Su4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MN0orPqW; 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 z13-20020a05640240cd00b0045cf3759408si31531015edb.49.2022.10.24.04.46.25; Mon, 24 Oct 2022 04:46:49 -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=MN0orPqW; 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 S231553AbiJXLqB (ORCPT + 99 others); Mon, 24 Oct 2022 07:46:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231681AbiJXLoP (ORCPT ); Mon, 24 Oct 2022 07:44:15 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E09D3889; Mon, 24 Oct 2022 04:41:49 -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 0281461291; Mon, 24 Oct 2022 11:40:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DEE86C433C1; Mon, 24 Oct 2022 11:40:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666611615; bh=w8GcFL1jn5maqtpEMoRTTc6qRI1tWbmQU92truPDLkU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MN0orPqWWle+GY5iTbnr6w86mXPb+ZdYzUFL82jryVGCPHIMOk6tt7kL4RS7AIxWB eE3i8uC9W1l9Y+YfGFulUcIJyEqoPXufayKz1jBZPTWItR8KpRSUluSmOSi88+0IMZ L6LdyOQw/A8pBgrssgzVfvYnb4wDLwTogCVGoFA8= 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.9 018/159] fs: fix UAF/GPF bug in nilfs_mdt_destroy Date: Mon, 24 Oct 2022 13:29:32 +0200 Message-Id: <20221024112950.023006337@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112949.358278806@linuxfoundation.org> References: <20221024112949.358278806@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?1747569354622480590?= X-GMAIL-MSGID: =?utf-8?q?1747569354622480590?= 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 @@ -164,8 +164,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); @@ -192,11 +190,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);