Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2404685lqp; Sun, 24 Mar 2024 18:07:52 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUcUhJxKBpXwYN7128zdbcxcatAStINPZUMe/linM/XaZFKOhDfhlznlwWNJP8ff8t2zeM9533RhNaRdrSFDU4VDozNMlJbwhxyh+ajIQ== X-Google-Smtp-Source: AGHT+IEOl7m6XtlZbJTzIp5NOrcCQ4wbggxCMt7fb/L3teeZjDOgNbBTAQeVWa/nb/6ICi48J53E X-Received: by 2002:a05:620a:2406:b0:78a:3414:14ba with SMTP id d6-20020a05620a240600b0078a341414bamr7743554qkn.6.1711328871784; Sun, 24 Mar 2024 18:07:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711328871; cv=pass; d=google.com; s=arc-20160816; b=emUaMDljYT+bUQK1qkeuJ6jE1eKIRkWcQntEv25gcSJEUfZun01d989B8Hv2KWCRk7 Lk6ApzqRSiq6+Nl9tFN0Tho4hjwiQvV0IAiL+6yGH1YKJV5idPmM43hQs1c9ixuliobj kBiTxx7rgmwZi9P5eFYKaha/gHWIjOXRaK6sBNCoIb2Y3syABOyJ6iEWH2jxuIoBeq5Z DlPIh1vgsJT6l5eOEPh5WMGg227W9vx3tgy4hffOnqE5W+rP3e3txC+wc4QQBQvl9Wfo 3SNiPcSMDwMWQpd16aqdc7qA017vP1CKif4lYT0fcs/60rowJCqeIeCnvUP/y/bcUah2 xLxw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=TeBOQZ7OzlqIeO2x9HSGsKDHwUjYKbPzugFBfWtAPFg=; fh=yjxqQO4Uz8aug8AqGCwL2f7bZBnG98N3ofjFNeXcHE0=; b=AsoG1jw56uM3GIVPf0F141QJVtBSMAaOdzsUKYb3n9u9T03fD6oBL8Ca8IqXqUuvCm S4D6cZQxpvXhYP3oOb3ov/0SrsFMMuRq6IGShtu6iZ5lnhixRHJ8t6FnahfTzjraWibK nxmNYHDDZofGMYq3Gd9NQr1JxvC6qKDLAJMydctV+RZcANSfpXd5R7z8B2G8Rwqsq7eO vZnJwwR36zEi05NdiGqVaUI4W1PEaCTTmOcJmdqtBvudk+To3y19YRF8tAAE97f6aL3K THvmZZgmFqUqnrwg3Xd64YyoWeqKRS9WTknlzMeeZm10WuQWmpMkubuxKAsmN7buALMR RaPQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TPPK1lGb; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113578-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113578-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id vq18-20020a05620a559200b0078a22357ad8si4341081qkn.115.2024.03.24.18.07.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 18:07:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113578-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TPPK1lGb; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113578-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113578-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 73C811C24CAF for ; Mon, 25 Mar 2024 01:07:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CB2111C9878; Sun, 24 Mar 2024 22:46:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TPPK1lGb" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D5CEC1C985D; Sun, 24 Mar 2024 22:46:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320381; cv=none; b=WelaQrxWjXLyHY3SvdMYlApUsv+nuXiJ2/7m9c/yN/Z1b5nMfN7Gu20y+71GyyKVOTBcO6xJA6eeIsGoqX8I+oc81P+X3et2PfXQ30WaHKwXQnXnl0hOgL0+xRYTgLHLjdoHuuW4sRAtI6kT/WEY1urkQTyVAtAxrUJQ4wJfLDc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320381; c=relaxed/simple; bh=bF7GE1W3zXbp8SDL+EKrXe62S2HrG2hpuza1NbZUjCQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QtCBd1545FTDRtaW4MhxAIHkuWpe3TErg/49dEIVctJW12jVBZLhkj4CpHU3bBvdxyv0qn1p9PZYBBE8RkZJsdZKOlizlib7Rk4zqE2V9hXB2LwtkLpe9RhLE+ruGIWikYAsxupqxBkKmlfcsqQvNcstDVE7j95dtZvE+qy6x6s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TPPK1lGb; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 083C2C43399; Sun, 24 Mar 2024 22:46:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711320381; bh=bF7GE1W3zXbp8SDL+EKrXe62S2HrG2hpuza1NbZUjCQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TPPK1lGbYpZx/PegbJXqXG6KlGnf0tGQpfang8DzOFEBKuoD+MQJ3lOWlw/iiJYJk Onngxbxz9vgt5yTl6109ct1bMqXe5EjQ6YtIElmMMKXzv8sNJCtMAQWn9VlztljRE0 DP/s9kmaqyUVfY0lakHfhtRHKsqkbElokDwO+IqeWZpeywC1f8ZuLTuly6QRgDldXS nKZGfWuK8fEH5jithCW7zZw42RL53P7uc66JNFqFnrcYrtDxmGGJOFVvmaIziF/g2N VMJdfcvYaLByzlJOJx/vnfy22dTQsHuicKzW0kqRWRavSFePkBqy+6pBWb03hE/WWb WLIXtEyJNddxQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Xiubo Li , Frank Hsiao , Ilya Dryomov , Sasha Levin Subject: [PATCH 6.8 687/715] ceph: stop copying to iter at EOF on sync reads Date: Sun, 24 Mar 2024 18:34:26 -0400 Message-ID: <20240324223455.1342824-688-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Xiubo Li [ Upstream commit 1065da21e5df9d843d2c5165d5d576be000142a6 ] If EOF is encountered, ceph_sync_read() return value is adjusted down according to i_size, but the "to" iter is advanced by the actual number of bytes read. Then, when retrying, the remainder of the range may be skipped incorrectly. Ensure that the "to" iter is advanced only until EOF. [ idryomov: changelog ] Fixes: c3d8e0b5de48 ("ceph: return the real size read when it hits EOF") Reported-by: Frank Hsiao Signed-off-by: Xiubo Li Reviewed-by: Ilya Dryomov Tested-by: Frank Hsiao Signed-off-by: Ilya Dryomov Signed-off-by: Sasha Levin --- fs/ceph/file.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/fs/ceph/file.c b/fs/ceph/file.c index abe8028d95bf4..3d1cd079dbf16 100644 --- a/fs/ceph/file.c +++ b/fs/ceph/file.c @@ -1138,7 +1138,12 @@ ssize_t __ceph_sync_read(struct inode *inode, loff_t *ki_pos, } idx = 0; - left = ret > 0 ? ret : 0; + if (ret <= 0) + left = 0; + else if (off + ret > i_size) + left = i_size - off; + else + left = ret; while (left > 0) { size_t plen, copied; @@ -1167,15 +1172,13 @@ ssize_t __ceph_sync_read(struct inode *inode, loff_t *ki_pos, } if (ret > 0) { - if (off > *ki_pos) { - if (off >= i_size) { - *retry_op = CHECK_EOF; - ret = i_size - *ki_pos; - *ki_pos = i_size; - } else { - ret = off - *ki_pos; - *ki_pos = off; - } + if (off >= i_size) { + *retry_op = CHECK_EOF; + ret = i_size - *ki_pos; + *ki_pos = i_size; + } else { + ret = off - *ki_pos; + *ki_pos = off; } if (last_objver) -- 2.43.0