]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
ceph: improve error handling and short/overflow-read logic in __ceph_sync_read()
authorAlex Markuze <amarkuze@redhat.com>
Wed, 27 Nov 2024 13:34:10 +0000 (15:34 +0200)
committerIlya Dryomov <idryomov@gmail.com>
Mon, 16 Dec 2024 22:25:43 +0000 (23:25 +0100)
commit9abee475803fab6ad59d4f4fc59c6a75374a7d9d
treeb347ee02f1bb4a89e2e64f7a0484de66cf118095
parent12eb22a5a609421b380c3c6ca887474fb2089b2c
ceph: improve error handling and short/overflow-read logic in __ceph_sync_read()

This patch refines the read logic in __ceph_sync_read() to ensure more
predictable and efficient behavior in various edge cases.

- Return early if the requested read length is zero or if the file size
  (`i_size`) is zero.
- Initialize the index variable (`idx`) where needed and reorder some
  code to ensure it is always set before use.
- Improve error handling by checking for negative return values earlier.
- Remove redundant encrypted file checks after failures. Only attempt
  filesystem-level decryption if the read succeeded.
- Simplify leftover calculations to correctly handle cases where the
  read extends beyond the end of the file or stops short.  This can be
  hit by continuously reading a file while, on another client, we keep
  truncating and writing new data into it.
- This resolves multiple issues caused by integer and consequent buffer
  overflow (`pages` array being accessed beyond `num_pages`):
  - https://tracker.ceph.com/issues/67524
  - https://tracker.ceph.com/issues/68980
  - https://tracker.ceph.com/issues/68981

Cc: stable@vger.kernel.org
Fixes: 1065da21e5df ("ceph: stop copying to iter at EOF on sync reads")
Reported-by: Luis Henriques (SUSE) <luis.henriques@linux.dev>
Signed-off-by: Alex Markuze <amarkuze@redhat.com>
Reviewed-by: Viacheslav Dubeyko <Slava.Dubeyko@ibm.com>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
fs/ceph/file.c