Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp450088pxb; Thu, 19 Aug 2021 03:35:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzK5dzTixvkAHdHYmwhx5IFYnGDavQo6KhzgYSVbHlCI7+GPbyxuYibD40/Ai/JCT8gyH4k X-Received: by 2002:a05:6402:5112:: with SMTP id m18mr15762102edd.47.1629369354810; Thu, 19 Aug 2021 03:35:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629369354; cv=none; d=google.com; s=arc-20160816; b=ZbcJ/LUd+hhC+EZtA5Q5r+W9uqsrPgejFSSAbsBaBcgCaZo1QKpwr+6ZGPBbyXwk6/ 1sFRZfGNcyDqI2gAYICfyLKHFf95xVIllOc4bunE/2o8KsPsuLo5rm4C759raDr7mCTA iEEpb0qz3Bcx+w3juuO9Qlob/kxZBW7O6Aqi01w4A/RGstlq1rAHbCHeXqxxq29gF6qZ QxwkwQobAegsre3nPFaxMdmWm1RyTunCv6/8W6RnN08PjqTu7T/NoPD29ncE2Db2FU0v cwbw3xy2QA2rd6q4TJYecTFnESxt2NBW60/pOg3uHu6qdUcrs4HcPflHEB4C7wFh8PYf ElOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:dkim-signature; bh=p1/YjMtunmntj17IgarF8r82HsoYyHTF0J/qAPFpnFw=; b=0wCJRTGp4styaa9yKEV0bDGLXQq8vEdjDYN90EKC4GUxrJ5wqZIM73zdRJFWy9grwC Pn42Vblk0Hwg6lD2xl5byVPmc5dZmyhKRYYxy6IU8z67v5WKm1HnlN2JLOjJ7T0GIGw0 A9ExYX1Ww6rS/qXUaA39ftAl3ZUpIrhOecsEOhS4kWLtJwTOqB0YjU3ZrXpWgHS7phOv qvsSiZyIIixVzfE4ElD232gMVkSdTflPctdgw3exBkLEJ0lqLNkqehzoRqaAReI2BALh kHdvjRpmVkXk+phzwwJuFerp7X29r3sF6EjmhP8TOmDs0J+IZ56zaTTTLqdcmlW8U5R5 Zl5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=tboh7SBN; dkim=neutral (no key) header.i=@suse.cz header.b=icC8cjY0; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w18si2974811ejv.669.2021.08.19.03.35.14; Thu, 19 Aug 2021 03:35:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=tboh7SBN; dkim=neutral (no key) header.i=@suse.cz header.b=icC8cjY0; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237697AbhHSKfm (ORCPT + 99 others); Thu, 19 Aug 2021 06:35:42 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:40604 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236149AbhHSKfl (ORCPT ); Thu, 19 Aug 2021 06:35:41 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 6708D2209B; Thu, 19 Aug 2021 10:35:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1629369304; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=p1/YjMtunmntj17IgarF8r82HsoYyHTF0J/qAPFpnFw=; b=tboh7SBNbEvFQy8ofVvQ/LHbFcEb2QdNW/t4oH7mU6XjQDcGU0Qxz39jCQr9UgFGeQwwlt kFJOZgZrYc0v3JtXz9FzhpBKI+rcje2ZS4gZj7LwFwUGt1zC+Zv7zltuxi5eaFB6fe6dwE /hgODNN/k9EQHMCcUn0ur/ir3XT7J38= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1629369304; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=p1/YjMtunmntj17IgarF8r82HsoYyHTF0J/qAPFpnFw=; b=icC8cjY07IHHsIct7uGGvl8SvNr/rociHdyu5uhEk8y0GEliX57wi0LK69XD9A/gOSNGHC X9q9hoELCZgyqpDA== Received: from quack2.suse.cz (unknown [10.100.224.230]) by relay2.suse.de (Postfix) with ESMTP id C3628A3BC7; Thu, 19 Aug 2021 10:34:46 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 30E6E1E0679; Thu, 19 Aug 2021 12:35:04 +0200 (CEST) Date: Thu, 19 Aug 2021 12:35:04 +0200 From: Jan Kara To: Zhang Yi Cc: linux-ext4@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, yukuai3@huawei.com Subject: Re: [PATCH v2 4/4] ext4: prevent getting empty inode buffer Message-ID: <20210819103504.GB32435@quack2.suse.cz> References: <20210819065704.1248402-1-yi.zhang@huawei.com> <20210819065704.1248402-5-yi.zhang@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210819065704.1248402-5-yi.zhang@huawei.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Thu 19-08-21 14:57:04, Zhang Yi wrote: > In ext4_get_inode_loc(), we may skip IO and get an zero && uptodate > inode buffer when the inode monopolize an inode block for performance > reason. For most cases, ext4_mark_iloc_dirty() will fill the inode > buffer to make it fine, but we could miss this call if something bad > happened. Finally, __ext4_get_inode_loc_noinmem() may probably get an > empty inode buffer and trigger ext4 error. > > For example, if we remove a nonexistent xattr on inode A, > ext4_xattr_set_handle() will return ENODATA before invoking > ext4_mark_iloc_dirty(), it will left an uptodate but zero buffer. We > will get checksum error message in ext4_iget() when getting inode again. > > EXT4-fs error (device sda): ext4_lookup:1784: inode #131074: comm cat: iget: checksum invalid > > Even worse, if we allocate another inode B at the same inode block, it > will corrupt the inode A on disk when write back inode B. > > So this patch postpone the init and mark buffer uptodate logic until > before filling correct inode data in ext4_do_update_inode() if skip read > I/O, ensure the buffer is real uptodate. > > Signed-off-by: Zhang Yi Looks good. Just some language fixes below. Feel free to add: Reviewed-by: Jan Kara > --- > fs/ext4/inode.c | 26 +++++++++++++++++++++++--- > 1 file changed, 23 insertions(+), 3 deletions(-) > > diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c > index d0d7a5295bf9..02d910c9d8f1 100644 > --- a/fs/ext4/inode.c > +++ b/fs/ext4/inode.c > @@ -4367,9 +4367,11 @@ static int __ext4_get_inode_loc(struct super_block *sb, unsigned long ino, > } > brelse(bitmap_bh); > if (i == start + inodes_per_block) { > - /* all other inodes are free, so skip I/O */ > - memset(bh->b_data, 0, bh->b_size); > - set_buffer_uptodate(bh); > + /* > + * All other inodes are free, skip I/O. Return > + * un-inited buffer (which is postponed until I'd repharse this sentence as: Return uninitialized buffer immediately, initialization is postponed until shortly before we fill inode contents. > + * before filling inode data) immediately. > + */ > unlock_buffer(bh); > goto has_buffer; > } > @@ -5026,6 +5028,24 @@ static int ext4_do_update_inode(handle_t *handle, > gid_t i_gid; > projid_t i_projid; > > + /* > + * If the buffer is not uptodate, it means all information of inode ^^^^^^^^ of the inode is > + * in memory and we got this buffer without reading the block. We > + * must be cautious that once we mark the buffer as uptodate, we > + * rely on filling in the correct inode data later in this function. > + * Otherwise if we getting the left falsepositive buffer when I'd rephrase this sentence as: Otherwise if we left uptodate buffer without copying proper inode contents, we could corrupt the inode on disk after allocating another inode in the same block. Honza -- Jan Kara SUSE Labs, CR