Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1305248rwi; Thu, 13 Oct 2022 11:46:23 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6fofpxEK/DpCoqth15G10IYB8CxKNFf+vJKN3cWN7B7Ktjej1zm7xZvdxsGMe86BhevI1B X-Received: by 2002:a65:6e47:0:b0:438:c2f0:c0eb with SMTP id be7-20020a656e47000000b00438c2f0c0ebmr1127677pgb.236.1665686782781; Thu, 13 Oct 2022 11:46:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665686782; cv=none; d=google.com; s=arc-20160816; b=EOku3eCMPdjaCl7P9nlZmsTDIIXGS2vV7JPCAUSGOH8RlSzslHMXOKBxA+7L0okc55 7DEFt4SISMForVHDyn+Nvpt8RkrltC4S8JIe82CvAc/WbnNVPSku+o8o8MXUYTulU+pO V0EOHpz4zDDWNQ8R7UUZRTqkDzBgVr85zHLb/Co12jVRmPpPZNGsmwVDuIBhfyjSS2Fi W1kC0RVn1SwxA+6pHl9X986NU5ISO/f8G07L6PwKVrDjnw1VD0wh06DDv1oCxMNYSZhf 4cX3d5NRwKvS/SjaO+7ifLqnBgeF/Sd8xJaI1zyakDNVuws2brA3cJ8Htqc5nHVn9ynO I8rQ== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mu10-20020a17090b388a00b001fdcbf875e7si4823007pjb.35.2022.10.13.11.46.10; Thu, 13 Oct 2022 11:46:22 -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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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);