Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp991863iob; Fri, 13 May 2022 18:52:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzyTQFAC22vhnQno8GVUmtrzU77Qo514kw2C4LaWYZDPlkqQT337sHTe/5ir7+Zb+h4UblW X-Received: by 2002:a05:600c:ad1:b0:38c:8bf6:7d6b with SMTP id c17-20020a05600c0ad100b0038c8bf67d6bmr7064231wmr.84.1652493146345; Fri, 13 May 2022 18:52:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652493146; cv=none; d=google.com; s=arc-20160816; b=jA/7z2Bv2gQVIi3V7TfQtXXFYYpbXTujEOwCW2D5yr/QC6//aGw7Ln/1IoZA7+bHuR KBm8h2nW9gho1B9Rk+6yiWM/evQ5Jlhgx/ZBPyjI1GpoTfYMNphXW87QrzyyX0XP8Ab/ F5NJ/GQ3xAsAY1Mp82RYLJshnBq0dgV/+SiQKKkRDpU59/XFBBZyQhMS6e6ipDhrrzks DiI2Amz6K0n6Uv5FTQcUwU3davFjBS4Xa0BfkFaA3RFY2hCbfU5wn/Pj76zY7rzN7sVc WdUVKbtlbj133BnQ4T/XP2J461ojT9jcU3wPVuMGrGeN7qx96CQM1UUJF1hZM+p3gGTF 8+hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=nzwrzMqDsYVJboGBB/IQbOMVhAxbj9pj1n5vlHGnylw=; b=NDwGIMM80vzYe33REimbJmX0hr3tQ782u6s3Hpcm4Qnhv0SKyme99yf0qRE/5fTjfu WQ07YWGG45xi4dHIChLdfe8iaAdA/PP/7KUMT+FeZJKJReg7ytnHAmZuJgkelvuZ+t+b vfTnBZ6wmtCTx02m7oXo8NspZK52EPm2o8Dv1UT5cd1KEvRXXXOkZIjkvgGfK1sw+9Ne xWKt+yclY4sE3Ih1bDP9erCepq/OK900JTgam1RJbo4C2WvpTeDiVy8HY5dyfde5TUIV pajT9E/sS2f3bIiaqpHsuL+5GVesa/6+XcgRis5El7QrNVFC+wFc8WVxCz6+OCCyCPgB 8/bQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mit.edu header.s=outgoing header.b=ieVe33Ui; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mit.edu Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id m14-20020a5d6a0e000000b00203e9019643si3321512wru.967.2022.05.13.18.52.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 18:52:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=fail header.i=@mit.edu header.s=outgoing header.b=ieVe33Ui; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mit.edu Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 368984525E8; Fri, 13 May 2022 17:16:16 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1384663AbiEMVxh (ORCPT + 99 others); Fri, 13 May 2022 17:53:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353675AbiEMVxg (ORCPT ); Fri, 13 May 2022 17:53:36 -0400 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29A1B25287; Fri, 13 May 2022 14:53:34 -0700 (PDT) Received: from cwcc.thunk.org (pool-108-7-220-252.bstnma.fios.verizon.net [108.7.220.252]) (authenticated bits=0) (User authenticated as tytso@ATHENA.MIT.EDU) by outgoing.mit.edu (8.14.7/8.12.4) with ESMTP id 24DLrDbu021205 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 May 2022 17:53:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mit.edu; s=outgoing; t=1652478795; bh=nzwrzMqDsYVJboGBB/IQbOMVhAxbj9pj1n5vlHGnylw=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=ieVe33UiwGpdgSON/uwfXPYir4W3Oz7bTC+JfZlX/rEvEp2rQsKhmy8Uk7gFfkfOo MvgU3tWKgQ3YiUA8ydrESBWT3rM5P2Rfw1MsOKFKAKIz11FQwxyCSqsE0n+eLGb/Kd czg0A89rkhT8HhatBnRCip122eX01NMi6mNjpLjX6PH4+D7/HmPoxbA+JhSaoZp+1+ ReWTjXlK7vCkaaw69bfBX3xA2NsvQKsqbCCoX5psKdVJgGRno1iihQYQ97q/wgmOr+ UCUq/q+ySAxGnwABVbfBq4AD6c5I/ozgsMMs1f8/1z7X7CoXxEA7G5W7JpAx8wVG0n y1m+9kzx4Cssw== Received: by cwcc.thunk.org (Postfix, from userid 15806) id 78F4615C3F2A; Fri, 13 May 2022 17:53:13 -0400 (EDT) Date: Fri, 13 May 2022 17:53:13 -0400 From: "Theodore Ts'o" To: Ye Bin Cc: adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, jack@suse.cz, lczerner@redhat.com Subject: Re: [PATCH -next] ext4: fix use-after-free in ext4_rename_dir_prepare Message-ID: References: <20220414025223.4113128-1-yebin10@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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-ext4@vger.kernel.org On Fri, May 13, 2022 at 05:13:47PM -0400, Theodore Ts'o wrote: > > I think we should be calling ext4_error_inode()? If the directory is > missing '.' or '..' below, the file system is corrupt, so we probably > should mark the file system as inconsistent, so that e2fsck can fix > the file system. I noticed one other problem; which is that by returning NULL and not setting retval, ext4_rename_dir_prepare() will end up returning uninitialized stack garbage as the "error code". So I'm going to be applying this commit with the following change: diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 50be41dc5831..b202626391ff 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -3471,8 +3471,9 @@ static struct buffer_head *ext4_get_first_dir_block(handle_t *handle, bh->b_size, 0) || le32_to_cpu(de->inode) != inode->i_ino || strcmp(".", de->name)) { - ext4_warning_inode(inode, "directory missing '.'"); + EXT4_ERROR_INODE(inode, "directory missing '.'"); brelse(bh); + *retval = -EFSCORRUPTED; return NULL; } offset = ext4_rec_len_from_disk(de->rec_len, @@ -3481,8 +3482,9 @@ static struct buffer_head *ext4_get_first_dir_block(handle_t *handle, if (ext4_check_dir_entry(inode, NULL, de, bh, bh->b_data, bh->b_size, offset) || le32_to_cpu(de->inode) == 0 || strcmp("..", de->name)) { - ext4_warning_inode(inode, "directory missing '..'"); + EXT4_ERROR_INODE(inode, "directory missing '..'"); brelse(bh); + *retval = -EFSCORRUPTED; return NULL; } *parent_de = de;