linux/net/ceph
Pavitra Jha 1c824e7c75 libceph: fix OOB read in decode_watchers() via missing bounds check
commit 00ead17c7d upstream.

ceph_start_decoding() validates that struct_len bytes remain in the
buffer after the encoding header, but accepts struct_len=0 as valid:
ceph_decode_need(p, end, 0, bad) always passes. When a malicious or
compromised OSD sends an obj_list_watch_response_t reply with
struct_len=0, ceph_start_decoding() returns success with p == end,
leaving zero bytes guaranteed for subsequent reads.

The immediately following ceph_decode_32(p) in decode_watchers() has
no preceding bounds check. With p == end this is a 4-byte read past
the validated buffer boundary. The garbage value is then passed
directly to kzalloc_objs() as the watcher count.

The sibling function decode_watcher() already uses the safe variants
(ceph_decode_copy_safe, ceph_decode_64_safe, ceph_decode_skip_32)
after its own ceph_start_decoding() call. decode_watchers() is the
only site that uses the bare variant, confirming an oversight.

Fix by replacing ceph_decode_32(p) with ceph_decode_32_safe(p, end,
*num_watchers, bad), consistent with the established pattern.

Attacker model: a malicious or compromised OSD in a multi-tenant Ceph
deployment (e.g. cloud) can trigger this against any kernel client
that calls CEPH_OSD_OP_LIST_WATCHERS, without any further privileges
beyond OSD session establishment.

[ idryomov: trim changelog ]

Cc: stable@vger.kernel.org
Fixes: a4ed38d7a1 ("libceph: support for CEPH_OSD_OP_LIST_WATCHERS")
Signed-off-by: Pavitra Jha <jhapavitra98@gmail.com>
Reviewed-by: Viacheslav Dubeyko <Slava.Dubeyko@ibm.com>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
[ kept the tree's `kcalloc()` context line instead of upstream's `kzalloc_objs()` ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
History 2026-08-27 14:28:20 +02:00
..
crush libceph: Fix potential out-of-bounds access in crush_decode() 2026-06-01 17:35:45 +02:00
armor.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
auth.c libceph: Fix slab-out-of-bounds access in auth message processing 2026-06-01 17:35:23 +02:00
auth_none.c libceph: kill ceph_none_authorizer::reply_buf 2021-06-28 23:49:25 +02:00
auth_none.h libceph: kill ceph_none_authorizer::reply_buf 2021-06-28 23:49:25 +02:00
auth_x.c libceph: refresh auth->authorizer_buf{,_len} after authorizer update 2026-08-19 17:14:03 +02:00
auth_x.h ceph: fix whitespace 2018-08-02 21:33:21 +02:00
auth_x_protocol.h libceph: fix some spelling mistakes 2021-06-28 23:49:25 +02:00
buffer.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
ceph_common.c libceph: remove debugfs files before client teardown 2026-08-19 17:14:03 +02:00
ceph_hash.c treewide: Use fallthrough pseudo-keyword 2020-08-23 17:36:59 -05:00
ceph_strings.c libceph: introduce connection modes and ms_mode option 2020-12-14 23:21:50 +01:00
cls_lock_client.c libceph: fix two unsafe bare decodes in decode_lockers() 2026-08-23 14:17:28 +02:00
crypto.c libceph: define and enforce CEPH_MAX_KEY_LEN 2026-03-04 07:20:19 -05:00
crypto.h libceph: define and enforce CEPH_MAX_KEY_LEN 2026-03-04 07:20:19 -05:00
debugfs.c libceph: fix potential use-after-free in have_mon_and_osd_map() 2025-12-07 06:09:36 +09:00
decode.c libceph: tolerate addrvecs with multiple entries of the same type 2026-08-23 14:17:16 +02:00
Kconfig libceph, ceph: implement msgr2.1 protocol (crc and secure modes) 2020-12-14 23:21:50 +01:00
Makefile libceph, ceph: implement msgr2.1 protocol (crc and secure modes) 2020-12-14 23:21:50 +01:00
messenger.c libceph: fix invalid accesses to ceph_connection_v1_info 2025-10-02 13:39:01 +02:00
messenger_v1.c use less confusing names for iov_iter direction initializers 2026-06-19 13:33:46 +02:00
messenger_v2.c use less confusing names for iov_iter direction initializers 2026-06-19 13:33:46 +02:00
mon_client.c libceph: Reject monmaps advertising zero monitors 2026-08-19 17:14:03 +02:00
msgpool.c libceph: preallocate message data items 2018-10-22 10:28:22 +02:00
osd_client.c libceph: fix OOB read in decode_watchers() via missing bounds check 2026-08-27 14:28:20 +02:00
osdmap.c libceph: bound pg_{temp,upmap,upmap_items} length to CEPH_PG_MAX_SIZE 2026-08-23 14:17:27 +02:00
pagelist.c libceph: introduce ceph_pagelist_alloc() 2018-10-22 10:28:21 +02:00
pagevec.c libceph: remove ceph_get_direct_page_vector() 2019-07-08 14:01:40 +02:00
snapshot.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 268 2019-06-05 17:30:29 +02:00
string_table.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
striper.c rbd: support for object-map and fast-diff 2019-07-08 14:01:45 +02:00