Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp987294rwe; Thu, 25 Aug 2022 13:02:05 -0700 (PDT) X-Google-Smtp-Source: AA6agR4TohIzN7x8C3b6ea7RJFOTarloDfwgVJFPJEay2qVLa94RNXG3rGBNqcGR74KJGjYj5U07 X-Received: by 2002:a17:907:7e8c:b0:73d:85ec:46c with SMTP id qb12-20020a1709077e8c00b0073d85ec046cmr3261505ejc.257.1661457724980; Thu, 25 Aug 2022 13:02:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661457724; cv=none; d=google.com; s=arc-20160816; b=NKchreA/FPCOSNRysMp6uOiZZ1ngZ0i7Xo8+pfe1z+82tzyy0xLjcxrcK+Jw9n08xz hsXnTXCOH6qWwhF/ynj+i2xUdy2maTblkNaKdVEgH8IrKukIjzLTjc3HFa9rHmhV8ei8 5SZVcFUSJ9kP9fv6N/qghkcobhDJd9L5fPmfQaATLwM0Bl1iUKhzB94EexYe3Vbo9Tal bAgWmqpSklV39c5Ebs6DUtbGa+yz9P+ZFAmnDVCMr9n7s3hwzxNIZpITCQnzQzXcB+ts ChA6paz7qEHt3wc3X/sGVTGV9uH/o4LbYHjTDFcwlkyOfQTg6vpHCFGCfOQP+7nlJCGV z9Jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=Ap4Qtw2eIhwBSwxTvZTataGItzndYtJsMROyxYNZcMA=; b=h6JZILeA96j82AV1Nalxj/22Of+zs8DHV/3u4LCNGl4WwICg3TOgNhxn7zP+qrjeH6 Kp45omELqsZIWGV6EunRiifcYXzLBRUFwJmgsggPTIKv+nou0qjTsLveTwjmKNDRBfEp gTkocgCf6sR2zHJ4lA7oeqUaSYR1h6thouKeW64hQXYVPs+ajD+77zkrATV7CH6FG41o ly46iT16qLv1rj+ZNbrYLzDNjYjGx4mJGTACYwjwQqze8qFfONji6PzrT0jOpJNj8JOW ZCJPvWMlkx5TrJPkXXU36TxFBkbHrGygnHHVKwMaPGcXzflLRiDATVwSZg+92SmJgueL hSDQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f21-20020a056402195500b004438278b0bbsi204052edz.317.2022.08.25.13.01.07; Thu, 25 Aug 2022 13:02:04 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243708AbiHYTpc (ORCPT + 99 others); Thu, 25 Aug 2022 15:45:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243733AbiHYTp3 (ORCPT ); Thu, 25 Aug 2022 15:45:29 -0400 Received: from sandeen.net (sandeen.net [63.231.237.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 16B4D3335E; Thu, 25 Aug 2022 12:45:27 -0700 (PDT) Received: from [10.0.0.146] (liberator.sandeen.net [10.0.0.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by sandeen.net (Postfix) with ESMTPSA id 4DADAEF8; Thu, 25 Aug 2022 14:43:51 -0500 (CDT) Message-ID: <4ccd8b01-24ae-87de-3cfa-bf99a8bb6b3b@sandeen.net> Date: Thu, 25 Aug 2022 14:45:25 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Subject: Re: [PATCH v2] fs: fix UAF/GPF bug in nilfs_mdt_destroy Content-Language: en-US To: Dongliang Mu , Alexander Viro Cc: Dongliang Mu , butt3rflyh4ck , Hao Sun , Jiacheng Xu , stable@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org References: <20220816040859.659129-1-dzm91@hust.edu.cn> From: Eric Sandeen In-Reply-To: <20220816040859.659129-1-dzm91@hust.edu.cn> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,NICE_REPLY_A, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 On 8/15/22 11:08 PM, Dongliang Mu wrote: > From: Dongliang Mu > > 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 > Signed-off-by: Dongliang Mu > Cc: Al Viro > Cc: stable@vger.kernel.org > --- > v1->v2: move security_inode_alloc at the very end according to Al Viro > other than initializing i_private before security_inode_alloc. > fs/inode.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/fs/inode.c b/fs/inode.c > index 6462276dfdf0..49d1eb91728c 100644 > --- a/fs/inode.c > +++ b/fs/inode.c > @@ -192,8 +192,6 @@ int inode_init_always(struct super_block *sb, struct inode *inode) > 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); > > @@ -228,6 +226,9 @@ int inode_init_always(struct super_block *sb, struct inode *inode) > inode->i_fsnotify_mask = 0; > #endif > inode->i_flctx = NULL; > + > + if (security_inode_alloc(inode)) > + goto out; Seems like the out: label could be removed, and simply return -ENOMEM directly here, but that's just a nitpick. -Eric > this_cpu_inc(nr_inodes); > > return 0;