From nobody Fri Dec 19 18:53:59 2025 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TPPK1lGb" 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: quoted-printable Content-Type: text/plain; charset="utf-8" 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, } =20 idx =3D 0; - left =3D ret > 0 ? ret : 0; + if (ret <=3D 0) + left =3D 0; + else if (off + ret > i_size) + left =3D i_size - off; + else + left =3D ret; while (left > 0) { size_t plen, copied; =20 @@ -1167,15 +1172,13 @@ ssize_t __ceph_sync_read(struct inode *inode, loff_= t *ki_pos, } =20 if (ret > 0) { - if (off > *ki_pos) { - if (off >=3D i_size) { - *retry_op =3D CHECK_EOF; - ret =3D i_size - *ki_pos; - *ki_pos =3D i_size; - } else { - ret =3D off - *ki_pos; - *ki_pos =3D off; - } + if (off >=3D i_size) { + *retry_op =3D CHECK_EOF; + ret =3D i_size - *ki_pos; + *ki_pos =3D i_size; + } else { + ret =3D off - *ki_pos; + *ki_pos =3D off; } =20 if (last_objver) --=20 2.43.0