From patchwork Tue Nov 26 15:54:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13886135 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4EDCD3B9AC for ; Tue, 26 Nov 2024 15:55:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 578166B0088; Tue, 26 Nov 2024 10:54:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 524E06B008C; Tue, 26 Nov 2024 10:54:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3C62D6B0092; Tue, 26 Nov 2024 10:54:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 1C5966B0088 for ; Tue, 26 Nov 2024 10:54:59 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id C3706AEBA2 for ; Tue, 26 Nov 2024 15:54:58 +0000 (UTC) X-FDA: 82828694340.17.D802B6B Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf01.hostedemail.com (Postfix) with ESMTP id 79AC640003 for ; Tue, 26 Nov 2024 15:54:53 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=By05q8Qa; spf=pass (imf01.hostedemail.com: domain of cel@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cel@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732636494; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=+wG1gqRKTxVBichEZ6K667VeySnEED3AOvysGA+zHNY=; b=k5rBQ0e9OvqTTOosQitN01OroQ9oRlpw42Li4tyCOeVCyU8xo+tRxKusb7mP5HgAvLLDFp cLAXmHnX/8mWb1RMIw9wPl5sw3bu3MSjgEPFXrlmENjdnP/KmnqOSWLW2dSFlHQQcfPh8i lvpKmbeTDgeA2pKPbnHfVrrnpAOJMy4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732636494; a=rsa-sha256; cv=none; b=nKlo2UISzMwo3rgpO0ET/FdkAwMMoTqowUgjqgRYoHbpn7UIRKn1nfX+svNM6lZeqKJdAk UC9rmyRWogTR/E06k+45TFGf5M5hg3SOkQ0643OUuHhXOLgB51+iXxLM5xqd6mtC7xfMBi 89HLlLrAiaTBmUKZle9yFr8+8gDoHS0= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=By05q8Qa; spf=pass (imf01.hostedemail.com: domain of cel@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cel@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id D69E05C5931; Tue, 26 Nov 2024 15:54:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3B2F4C4CED2; Tue, 26 Nov 2024 15:54:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1732636496; bh=G5Isx5LWQiXPXi2iyTyoRug884HtfgCAxYAVKEyJLvo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=By05q8QaTXtyBsRr33oV31LREOAX2SwvLMusYu3wtZsr58fcPnb2O6q6OVj5NXrg5 K1HCHoPJ9iV1kyOupcUv9D6Ev255H5pDTnKE365/Boa7xD8q261E8HpblyqRdUFGXN 6S1Eq4+P6nDCAoOIubvwlhe7PAn+gCCxgqdSx96oVZgn4WfXaNavV4Y5a6wZ+Ef2mg vQCS0Sqr0O1LnmdolPkaIKmcFv9f/BtAUfjFLLQkVEtni3j0/8iy2pkb12EV9Fdy9h 2y+NhHSiEobBm0DiCwuxEhfElV5uaHugC2fdXausDp9XXrpmj9Ob5/PLxCqr1E2ofB FlWAyDTdmQJtA== From: cel@kernel.org To: Hugh Dickens , Christian Brauner , Al Viro Cc: , , yukuai3@huawei.com, yangerkun@huaweicloud.com, Chuck Lever Subject: [RFC PATCH v2 3/5] Revert "libfs: fix infinite directory reads for offset dir" Date: Tue, 26 Nov 2024 10:54:42 -0500 Message-ID: <20241126155444.2556-4-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241126155444.2556-1-cel@kernel.org> References: <20241126155444.2556-1-cel@kernel.org> MIME-Version: 1.0 X-Stat-Signature: e7y4ym5ysc77ewo68fpa9byeskm8xhg1 X-Rspam-User: X-Rspamd-Queue-Id: 79AC640003 X-Rspamd-Server: rspam02 X-HE-Tag: 1732636493-794237 X-HE-Meta: U2FsdGVkX1974lBPSZ67AccDR2/Gi9bIR9p6haUwa+gQnPMPADEsDmSvZN4QpGdmkHgkjyRcCXOmxpwes6RNAlMTohouiZCP4oIZB+/ZfCeGkb2KWpmN6U95w7+QGMPkSFZRWw9bJnMzrMymymrH5RyWhvExdf6DobiFb9BfPxYwx2Zw8sburO2DXo0m0Ca03+6Yb5mGSm8Jz7B2vK13lTwr6ixeHJsQnqBZsVeY7NCyTVBe4S6o6GEI1QoK9GBwHGWiqzVpD4M01Jgf56NuqhM/PvuLPJUSFk//YkKSKrqlDfnnqfblCCDmUF1o6PGV096lnQWeR/Pa5iEw2m9cJWX44CUvJ8aNUibfkYrcGIrTXCGvvc4kvr5aa8TtqZ0weluhPQAl873LaxciN9VqxeC6R0xE/xG28HHBjVFU0ZoFjHOWX5zbXBfYUFJiTS1lmatOl9lpXWIrJ1g2M7FQExfXrjNnp19H5nKY73TH423SWL8TbQ3Qw3uM0LyZEIGzvSsiD1bygMmuHw3ebTe+15IUWoT2C+PGeeoxUpWUD0V9buf2HgnUpGAfwxNoNx8Qqpz8lOAK5v0mbq17vMKnnyzV+lzCppJjuoITrtv5IsFK++zjfpD3qJ5hStUtpl/IOG6ARLjbw7/NX1U5G4sNFthE8ZavWID2tw4q2BfujjIaMatT27sVkDfxE0Yhw+yz9xN4tXCK/gZw0Baby8H3QNczC3XpPLdaDAyxnsM0oJXKswWmZvfWvZDnubHaCfZCyrhBhyMCEcQk1PVkEZWPXAqPtPv+bQ4QpQgI475tpkfjSkAH3tlyAW+Sg5yWD9t7SFHkErqivrFS79sKlKjsgF34oOxpjYzPOekqg3owEr4kpvIom3kfReM7MIC56xTkaJVvUKf/XO0x+VOuAQmHzjMbgUf5NrbRY2jUyV7VgpYEwY1WkcYt3rMW162QNdXifGiWDPNPr/sZpEBVrhb un+byfkk +SPpL/nRHC2sFBTLUKjUdg4Ak41ZJgdGOjYswaFSsyK8SqVFAappb/sFJYrSdZkSnJKoM9eqakaAX/vQUvXJ8mCK6GV2J1gL/ZRi54GhVFuEuS1Lj2uDTkJAuVp1mLanykj3hWS8rM7raZtsDXgbUcFx7gICikJBpQCVwr0iBDjHMTJaZwexbwXXOOLophuGafJ3QP64UsFneh791fJP7KhMpN5GHA2TGeGIEggyBgW/2FgU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Chuck Lever Using octx->next_offset to determine the newest entries works only because the offset value range is 63-bits. If an offset were to wrap, existing entries are no longer visible to readdir because offset_readdir() stops listing entries once an entry's offset is larger than octx->next_offset. Revert this fix for the infinite readdir loop bug to make room for a better fix. Signed-off-by: Chuck Lever --- fs/libfs.c | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index c88ed15437c7..e6c46b13fc71 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -453,14 +453,6 @@ void simple_offset_destroy(struct offset_ctx *octx) mtree_destroy(&octx->mt); } -static int offset_dir_open(struct inode *inode, struct file *file) -{ - struct offset_ctx *ctx = inode->i_op->get_offset_ctx(inode); - - file->private_data = (void *)ctx->next_offset; - return 0; -} - /** * offset_dir_llseek - Advance the read position of a directory descriptor * @file: an open directory whose position is to be updated @@ -474,9 +466,6 @@ static int offset_dir_open(struct inode *inode, struct file *file) */ static loff_t offset_dir_llseek(struct file *file, loff_t offset, int whence) { - struct inode *inode = file->f_inode; - struct offset_ctx *ctx = inode->i_op->get_offset_ctx(inode); - switch (whence) { case SEEK_CUR: offset += file->f_pos; @@ -490,8 +479,7 @@ static loff_t offset_dir_llseek(struct file *file, loff_t offset, int whence) } /* In this case, ->private_data is protected by f_pos_lock */ - if (!offset) - file->private_data = (void *)ctx->next_offset; + file->private_data = NULL; return vfs_setpos(file, offset, LONG_MAX); } @@ -522,7 +510,7 @@ static bool offset_dir_emit(struct dir_context *ctx, struct dentry *dentry) inode->i_ino, fs_umode_to_dtype(inode->i_mode)); } -static void offset_iterate_dir(struct inode *inode, struct dir_context *ctx, long last_index) +static void *offset_iterate_dir(struct inode *inode, struct dir_context *ctx) { struct offset_ctx *octx = inode->i_op->get_offset_ctx(inode); struct dentry *dentry; @@ -530,21 +518,17 @@ static void offset_iterate_dir(struct inode *inode, struct dir_context *ctx, lon while (true) { dentry = offset_find_next(octx, ctx->pos); if (!dentry) - return; - - if (dentry2offset(dentry) >= last_index) { - dput(dentry); - return; - } + return ERR_PTR(-ENOENT); if (!offset_dir_emit(ctx, dentry)) { dput(dentry); - return; + break; } ctx->pos = dentry2offset(dentry) + 1; dput(dentry); } + return NULL; } /** @@ -571,19 +555,22 @@ static void offset_iterate_dir(struct inode *inode, struct dir_context *ctx, lon static int offset_readdir(struct file *file, struct dir_context *ctx) { struct dentry *dir = file->f_path.dentry; - long last_index = (long)file->private_data; lockdep_assert_held(&d_inode(dir)->i_rwsem); if (!dir_emit_dots(file, ctx)) return 0; - offset_iterate_dir(d_inode(dir), ctx, last_index); + /* In this case, ->private_data is protected by f_pos_lock */ + if (ctx->pos == DIR_OFFSET_MIN) + file->private_data = NULL; + else if (file->private_data == ERR_PTR(-ENOENT)) + return 0; + file->private_data = offset_iterate_dir(d_inode(dir), ctx); return 0; } const struct file_operations simple_offset_dir_operations = { - .open = offset_dir_open, .llseek = offset_dir_llseek, .iterate_shared = offset_readdir, .read = generic_read_dir,