Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1306514ybh; Thu, 12 Mar 2020 22:05:01 -0700 (PDT) X-Google-Smtp-Source: ADFU+vt5TOpU82Rw2GJI48SDL1hqjv4mqS0ZpxTXe7tOlPOgm9duP/hJkA5fH9ytiFHc3n18JJn/ X-Received: by 2002:a9d:4d97:: with SMTP id u23mr9689815otk.293.1584075901581; Thu, 12 Mar 2020 22:05:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584075901; cv=none; d=google.com; s=arc-20160816; b=nSWchI1QYYjg5o3LWPd3qPLUXCa94jINGyZau7aFXJqKhW5jMZuCWdkRZebG7KDj2z yLZ8C9QcydH3Nz4Rnb2rAyQ7DeP+aUMd5NzA4vZcDfMPqohjQHFJ/eC6ICFKgAPerLWw 24VH1Mk4qdS8zrLS/Z4pjJ2SUqYKmw0/c1mAufGRa6fLPLs99WNhw3J7E6MnIKh0bii4 Gxmj8yVSSRlgCvsBSRnVFGoIAsugxk9h1d9gERr3b1yXXseDXWDP0isQ6vE/EFGsb9GR B5k+sF6cHyqm4eO0lyOJdoyt9I7HIVQFCQ5j7ls+rTmXR3t9AT+i5CtYaVInQ4DAAptL cXBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=w2Qpb6EdCr1zPfWzkBWvG0P4h17u6DpkDKmfztLEAU0=; b=NVwyAvUbaBaL/MDyjCOlchY5NJJL6AvpAO7WKWBXOXAeVNxYUu9GBkpfRSQRYHnSax mvG64Df+NaGTIeMpGziiJTvCieJPkVyfbOCV+IYYhwHkBdO2s2M7vV6wIVSFWfZRImrG vpIaKiMrNw5ZzSX6q1rMLmikvnwyPg6JSw/Xa2qB7+6fLXh56qA75u3grDFJ+zrrDN3g ryg00QQC5e/nFgAsXFosz2JU2690vJT/XGBZDsyd+bPy8FlGiHZOo6nWyXizjIg8+hz8 8ri0/XOCFiVDpMS28+XvdIlpsjr8wF9jvgukw3deUPtbop/eCBupCr2UiJ/MbnGiCG1a Ir/w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 34si4110317otv.21.2020.03.12.22.04.47; Thu, 12 Mar 2020 22:05:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726365AbgCMFDr (ORCPT + 99 others); Fri, 13 Mar 2020 01:03:47 -0400 Received: from mail105.syd.optusnet.com.au ([211.29.132.249]:40324 "EHLO mail105.syd.optusnet.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725535AbgCMFDr (ORCPT ); Fri, 13 Mar 2020 01:03:47 -0400 Received: from dread.disaster.area (pa49-195-202-68.pa.nsw.optusnet.com.au [49.195.202.68]) by mail105.syd.optusnet.com.au (Postfix) with ESMTPS id 5275B3A4A4D; Fri, 13 Mar 2020 16:03:43 +1100 (AEDT) Received: from dave by dread.disaster.area with local (Exim 4.92.3) (envelope-from ) id 1jCcU1-0007GD-QW; Fri, 13 Mar 2020 16:03:41 +1100 Date: Fri, 13 Mar 2020 16:03:41 +1100 From: Dave Chinner To: Tommi Rantala Cc: Christoph Hellwig , "Darrick J. Wong" , linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] xfs: fix regression in "cleanup xfs_dir2_block_getdents" Message-ID: <20200313050341.GO10776@dread.disaster.area> References: <20200312085728.22187-1-tommi.t.rantala@nokia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200312085728.22187-1-tommi.t.rantala@nokia.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.3 cv=LYdCFQXi c=1 sm=1 tr=0 a=mqTaRPt+QsUAtUurwE173Q==:117 a=mqTaRPt+QsUAtUurwE173Q==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=kj9zAlcOel0A:10 a=SS2py6AdgQ4A:10 a=9qxNCY_qAAAA:8 a=VwQbUJbxAAAA:8 a=20KFwNOVAAAA:8 a=7-415B0cAAAA:8 a=k_IqvGaJn7LPgz7umq4A:9 a=6ka8if1nHYrFWHRd:21 a=7qgZNAMl8ypy7hTT:21 a=CjuIK1q_8ugA:10 a=A2X48xt2e1hG9NJDz63Y:22 a=AjGcO6oz07-iQ99wixmX:22 a=biEYGPWJfzWAr4FL6Ov7:22 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 12, 2020 at 10:57:28AM +0200, Tommi Rantala wrote: > Commit 263dde869bd09 ("xfs: cleanup xfs_dir2_block_getdents") introduced > a getdents regression, when it converted the pointer arithmetics to > offset calculations: offset is updated in the loop already for the next > iteration, but the updated offset value is used incorrectly in two > places, where we should have used the not-yet-updated value. > > This caused for example "git clean -ffdx" failures to cleanup certain > directory structures when running in a container. > > Fix the regression by making sure we use proper offset in the loop body. > Thanks to Christoph Hellwig for suggestion how to best fix the code. > > Cc: Christoph Hellwig > Fixes: 263dde869bd09 ("xfs: cleanup xfs_dir2_block_getdents") > Signed-off-by: Tommi Rantala Needs a "cc: stable@kernel.org" tag, right? > --- > fs/xfs/xfs_dir2_readdir.c | 12 +++++++----- > 1 file changed, 7 insertions(+), 5 deletions(-) > > diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c > index 0d3b640cf1cc..871ec22c9aee 100644 > --- a/fs/xfs/xfs_dir2_readdir.c > +++ b/fs/xfs/xfs_dir2_readdir.c > @@ -147,7 +147,7 @@ xfs_dir2_block_getdents( > xfs_off_t cook; > struct xfs_da_geometry *geo = args->geo; > int lock_mode; > - unsigned int offset; > + unsigned int offset, next_offset; > unsigned int end; > > /* > @@ -173,9 +173,10 @@ xfs_dir2_block_getdents( > * Loop over the data portion of the block. > * Each object is a real entry (dep) or an unused one (dup). > */ > - offset = geo->data_entry_offset; > end = xfs_dir3_data_end_offset(geo, bp->b_addr); > - while (offset < end) { > + for (offset = geo->data_entry_offset; > + offset < end; > + offset = next_offset) { > struct xfs_dir2_data_unused *dup = bp->b_addr + offset; > struct xfs_dir2_data_entry *dep = bp->b_addr + offset; > uint8_t filetype; > @@ -184,14 +185,15 @@ xfs_dir2_block_getdents( > * Unused, skip it. > */ > if (be16_to_cpu(dup->freetag) == XFS_DIR2_DATA_FREE_TAG) { > - offset += be16_to_cpu(dup->length); > + next_offset = offset + be16_to_cpu(dup->length); > continue; > } > > /* > * Bump pointer for the next iteration. > */ > - offset += xfs_dir2_data_entsize(dp->i_mount, dep->namelen); > + next_offset = offset + > + xfs_dir2_data_entsize(dp->i_mount, dep->namelen); Code looks fine, though. Reviewed-by: Dave Chinner -- Dave Chinner david@fromorbit.com