From nobody Fri Dec 19 22:02:03 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 E0D34220982; Sun, 24 Mar 2024 23:11:25 +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=1711321887; cv=none; b=QEJvscS0+6s0ZkEy2yiMLsXmqpBuMuqMY/B7lRLt3tNS4POMVl+ddE5SPjEdHsb3kUjW8eHTCTymgMeuIaSqm2BiEA790KHbZNKTCkVpTNMdYrFP19KWSyYFyTxlLrLSWIiH/KEojxD3sW/CkbmP6Ou3tQeZnHtaTm1tTxcZlOQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711321887; c=relaxed/simple; bh=Ls2/MLqVo8XkIUPGIM99iciRPcSQ/fnqZvLaX8OkTtM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uln0zWygtHCeh11lskDxktvTJUJvYlED8NtKYMaY8I7Xv+kEaxFMMzlv0bQsuLUNuAzT8KKoEq64kx0JZGANkdfqgzcD0Mx5ShVfM+1fENLf1wv7M19rXjNn5/CvzhRBiRUFJvYP0fTfex/GkfA9HBNLvk/xLURvwJ9n24806XA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UqjgttIo; 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="UqjgttIo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A1A28C433C7; Sun, 24 Mar 2024 23:11:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711321885; bh=Ls2/MLqVo8XkIUPGIM99iciRPcSQ/fnqZvLaX8OkTtM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UqjgttIoWnSqjct5GhYHreXSuSx/e0zEu8Y0370eLwd9It0lYrVDG50cdSaLlfRqK EXNFAt4sUnlfFrq9UESJhc/Ck5vuLsn7gbsv+tI1EhKGtkFmVIwVZRYvy1RqLrijCc +s6/WR3hXz9iES1VwDn45VYaflOlGV/oSSw6q4mt5Zkl4+f6/qfc0+66ZRThwXQ/59 2tB9taqmi0qVcTki4wwWCtQrvK5oJU4/dwabcxuYd0goy0WlhV9M2QnPCu4eAue4cY bT5WYM3OvKmoUP5pw1Wubqib/CDhc4+RhDHCDw/T3wmqZvSE0osO0iSu36/SJoG8Qe hEGxevUQYPr8A== 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.6 613/638] ceph: stop copying to iter at EOF on sync reads Date: Sun, 24 Mar 2024 19:00:50 -0400 Message-ID: <20240324230116.1348576-614-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324230116.1348576-1-sashal@kernel.org> References: <20240324230116.1348576-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 b5f8038065d7c..bdd0a3b894b7b 100644 --- a/fs/ceph/file.c +++ b/fs/ceph/file.c @@ -1108,7 +1108,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 @@ -1137,15 +1142,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