Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3086901rwb; Mon, 15 Aug 2022 17:48:36 -0700 (PDT) X-Google-Smtp-Source: AA6agR515Fy/PiraplRmSgSX6W/nvJJlaQoqP4D/xUVOn7bL+Z5KF60CSz4ZOSG7egZBBtTs92zB X-Received: by 2002:a17:907:a0c6:b0:730:f081:6e8e with SMTP id hw6-20020a170907a0c600b00730f0816e8emr11767529ejc.479.1660610915792; Mon, 15 Aug 2022 17:48:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660610915; cv=none; d=google.com; s=arc-20160816; b=ulP3S+Z7XGxCXwVCye8cgll05KTkYwK0l5J4lbm+xhogcNQ5v6bPyqhSlc9c4xt8vA D+VR67u3a9/QdaX/ix79UPNTH43rGGORDspcU1h+xCkJ6bSoJMsupB1if39e6jxo2Vby igROBjzZ+A+RDuR0nrgocMsPehvqoGC9EBgN1L9lypZM2fYGch/Fl+fXLVNvAVFzbNpB +qSyeyU+uJfRplWVV6K4lxBKXKuWSOVSWfvtk9ylLjLPnUY5yPOr+jS58yfr6p+XgKUF A9OgLGQIIJccr1r9O4dhxr8+rMbCMyD89+Oejs/9SYrhFJAQl36JTOVnToMqapK7lm54 PXVA== 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=bPPvoGh53PVrtW/hP50bjqTuU5BDdHdwVvs7yCsDTyE=; b=ecq7uozNbS0VJPbgjcifjewP43R+2+067e7yUSMKIOjSGfoE3N9oZqUvxx4NiLPw9x xb78IiHa11WJW5l+7l09+88Jo2QnH+zUQhbQWUPPi923V3s3AkN/mH7Q5D+UiLbwDrK0 1+5JhEVjwX0RrUlYdLurN/lKmEnzkZr8VQkj1ANEg7+Td3f4n0s7snF+7zKZ53/J1s3L NSk2EecP+wgPybHj3NEbjsB7Ht7jvt85M5Zhm+qPMUHfRkpWVBYEIf2QGW7kjT3S+suV 5vwkuMJMMLRgPkZKvT5RMtqhGCrMxb4Z74P2c18zq3AZGhXt9ZITmArg/+9HB2fmVVgK C8ZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Son1gWWK; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dz16-20020a0564021d5000b0043c00b8f130si9116956edb.229.2022.08.15.17.48.10; Mon, 15 Aug 2022 17:48:35 -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=Son1gWWK; 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 S1345852AbiHOXOv (ORCPT + 99 others); Mon, 15 Aug 2022 19:14:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233050AbiHOXNh (ORCPT ); Mon, 15 Aug 2022 19:13:37 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA17979ECB; Mon, 15 Aug 2022 13:01:03 -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 39A0F6068D; Mon, 15 Aug 2022 20:01:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42929C433C1; Mon, 15 Aug 2022 20:01:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660593662; bh=WT2HE1e9r+uBilfQpDAj/tBduX2W9ohkaAAS7aNFYyQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Son1gWWKIxbX7JOCUVBIhIkw3dMdulzbTOmcW6ZWrIipWNbTE3UQD4vv584OBSSzI 6Mh9EPc28+vLA96gQuSa1eXgr75AgT7Cw06aSdpUpCMeBhBZ6KFPgVsOpvLLDD4vSm pycYM/YKYCOMzMHVuNKM6HOFeWok1o1bdKP6BLiU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hongnan Li , Jeffle Xu , Gao Xiang , Chao Yu , Sasha Levin Subject: [PATCH 5.19 0304/1157] erofs: update ctx->pos for every emitted dirent Date: Mon, 15 Aug 2022 19:54:20 +0200 Message-Id: <20220815180451.814972870@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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,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 From: Hongnan Li [ Upstream commit ecce9212d0fd7a2d4a4998f0c4623a66887e14c8 ] erofs_readdir update ctx->pos after filling a batch of dentries and it may cause dir/files duplication for NFS readdirplus which depends on ctx->pos to fill dir correctly. So update ctx->pos for every emitted dirent in erofs_fill_dentries to fix it. Also fix the update of ctx->pos when the initial file position has exceeded nameoff. Fixes: 3e917cc305c6 ("erofs: make filesystem exportable") Signed-off-by: Hongnan Li Signed-off-by: Jeffle Xu Reviewed-by: Gao Xiang Reviewed-by: Chao Yu Link: https://lore.kernel.org/r/20220722082732.30935-1-jefflexu@linux.alibaba.com Signed-off-by: Gao Xiang Signed-off-by: Sasha Levin --- fs/erofs/dir.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/fs/erofs/dir.c b/fs/erofs/dir.c index 18e59821c597..47c85f1b80d8 100644 --- a/fs/erofs/dir.c +++ b/fs/erofs/dir.c @@ -22,10 +22,9 @@ static void debug_one_dentry(unsigned char d_type, const char *de_name, } static int erofs_fill_dentries(struct inode *dir, struct dir_context *ctx, - void *dentry_blk, unsigned int *ofs, + void *dentry_blk, struct erofs_dirent *de, unsigned int nameoff, unsigned int maxsize) { - struct erofs_dirent *de = dentry_blk + *ofs; const struct erofs_dirent *end = dentry_blk + nameoff; while (de < end) { @@ -59,9 +58,8 @@ static int erofs_fill_dentries(struct inode *dir, struct dir_context *ctx, /* stopped by some reason */ return 1; ++de; - *ofs += sizeof(struct erofs_dirent); + ctx->pos += sizeof(struct erofs_dirent); } - *ofs = maxsize; return 0; } @@ -95,7 +93,7 @@ static int erofs_readdir(struct file *f, struct dir_context *ctx) "invalid de[0].nameoff %u @ nid %llu", nameoff, EROFS_I(dir)->nid); err = -EFSCORRUPTED; - goto skip_this; + break; } maxsize = min_t(unsigned int, @@ -106,17 +104,17 @@ static int erofs_readdir(struct file *f, struct dir_context *ctx) initial = false; ofs = roundup(ofs, sizeof(struct erofs_dirent)); + ctx->pos = blknr_to_addr(i) + ofs; if (ofs >= nameoff) goto skip_this; } - err = erofs_fill_dentries(dir, ctx, de, &ofs, + err = erofs_fill_dentries(dir, ctx, de, (void *)de + ofs, nameoff, maxsize); -skip_this: - ctx->pos = blknr_to_addr(i) + ofs; - if (err) break; +skip_this: + ctx->pos = blknr_to_addr(i) + maxsize; ++i; ofs = 0; } -- 2.35.1