From patchwork Mon Oct 24 11:28:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8653 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp421617wru; Mon, 24 Oct 2022 05:20:54 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7L0mL4Tk8JzaOq1e8OzMKofyOd9we6ml3peiOzuSKW01E0yd7+r/0hXwSVzDOx+1GP/WMp X-Received: by 2002:a17:907:6d9b:b0:78d:f24b:e358 with SMTP id sb27-20020a1709076d9b00b0078df24be358mr27126333ejc.714.1666614054141; Mon, 24 Oct 2022 05:20:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666614054; cv=none; d=google.com; s=arc-20160816; b=XDNSi+Sz7ssoKuOXIktm5UYaTf61U7XV3Gok21Z/ZrxG07FqqNk21CLx0YfkKI9MYl +NdwOOiezzDKQuS3ViLKyLjCC+z8jfjXTYdcUHRpMgPWGf6U+RgYV8okDJZ/2e6c9ckn 7n+quaKPTDvZ+lD20oLGpyMVHZ7dhas2seXeWw49LeppL1heldqUcJXsSY+B9dpP7DrO i6L3aSvvd7amzUoQCVWc3Dr1WK602jI2A2ewrBPZ+uL1eZMpE17mN56B2NDgF7lStVn1 ue2q7zKtu4GoHWQxUO/+zJs1ujU3OtSuqYV7ovlGO7Bj6L/6utlAwMcWX7hzpQzhkzWd bNrg== 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=dBqRME20xtcxrraugAO1eimHq51Xs+0Q6Yxad/KNPck=; b=sSqtsmM+VY/wNgvyVper/5RxWAx8TKGlTDAHFRCXmC+QSW4K7ydq0494/MXs3bR1JV +Ro4IrDCtPSKrGQQ3xFQNyX92GYok0kIUEWDpdCPUhX29L76jrx19hHA9RH8OYVH6pWp dg2DBm71RyMESN8NmdxxGLQHqbbh6AKYk0T+tR0sSh/LsYs/EeEZxOqasd4nj4qnOhpi PRN7xENJ8/gQuBRlOoBQyERH6/smvCf5mHK8EU/uaYPpuzaWNVq+q3B0KFIc7K29O9yF uFAFVtBygu2BlAF/+r2TybMeXvYI/RJD7raroH70ZSdnKyNDpitaQA3+EkptmYuj3flo OK5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=f3pP83Nd; 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 s22-20020a056402037600b00461891a8138si5440521edw.446.2022.10.24.05.20.29; Mon, 24 Oct 2022 05:20:54 -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=f3pP83Nd; 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 S233105AbiJXMQR (ORCPT + 99 others); Mon, 24 Oct 2022 08:16:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233293AbiJXMOo (ORCPT ); Mon, 24 Oct 2022 08:14:44 -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 E58F67822C; Mon, 24 Oct 2022 04:55:41 -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 EA7E7612B9; Mon, 24 Oct 2022 11:55:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 083D2C433C1; Mon, 24 Oct 2022 11:55:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612518; bh=CKXWZAtQuVRe+X7bbPl5H9fJbh3N4z3sK9sltqAfEyI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f3pP83NdUfPLytgmptuPk5oyyGX49Hh48YhjTgnwjQH/JL7EKZGdK5UsVPf1ycLnY jfzxdeyN0sw04zyT7QnKqyQxbITjyM0EnOSBCfgcZx/be3x3+PJLSq6kpjpyycUy2W UBT4gieFnMjr72dGSGFHUG8CAOHArnK7wT1vrqJo= 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.19 004/229] fs: fix UAF/GPF bug in nilfs_mdt_destroy Date: Mon, 24 Oct 2022 13:28:43 +0200 Message-Id: <20221024112959.252205817@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112959.085534368@linuxfoundation.org> References: <20221024112959.085534368@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?1747571498520083615?= X-GMAIL-MSGID: =?utf-8?q?1747571498520083615?= 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 @@ -166,8 +166,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); @@ -195,11 +193,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);