Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp6737717rwi; Mon, 24 Oct 2022 05:36:46 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6HLxvNfkfFIZ9Fz4K4LFshcaeVU+nuzJj7IXwvXHye/MconjrC+AZdVzvv/knG/cvJ7wME X-Received: by 2002:a05:6402:406:b0:458:a47:d14c with SMTP id q6-20020a056402040600b004580a47d14cmr30331448edv.41.1666615006440; Mon, 24 Oct 2022 05:36:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666615006; cv=none; d=google.com; s=arc-20160816; b=ium+B71K8lJb/mK317EeL7Cv4qx6mn4Ms1rlmVmDt/x1/rbhxE5loSrs3QBPsc2uvK pZxr1XdvXOa6OUnEXYxcYqDtzfQsG2Cjh7MU8EcCRuksVoF2yoiD7bdQ3zwYJnVrGn8f gNMtGEUMY5f9dLhjiLItJWyATSfmEU0pBx02xbVmpHdFV7gEQXfRMBO8joEFZ4f1As2r 9uC6dU+aQNYrtaMDDvv9A1qGTawK/AbEsw6k81WxVsC9Dmn4E6bJuosDnIzdSUbY6XV/ Mc4bUSJrksD0PO2j96isOHIHpbfqMritl3F+/KkE7EJeBMSzTudK9KGa4Bk8mv1+Kv7U 3h3A== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qa9-20020a170907868900b0078d23ac6981si28818302ejc.790.2022.10.24.05.36.21; Mon, 24 Oct 2022 05:36:46 -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 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 @@ -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);