From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 200012BD022 for ; Mon, 24 Aug 2026 14:31:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787581912; cv=none; b=NYCwwt5g3HL3FpjumQFCksUi97zE2CKjdRUosbDigmS0EhE0KGF9rBuk8KlqDQt1B3PZvjKEvo3D18Xr9gk7vATdXqI9yBkpehQ4j89m3xsiA1xsb/s0lZ313wjoV5ev9/yPvi1gMlhIcyAApQFC+MLuLuFs3IyFln+UTkx6CiM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787581912; c=relaxed/simple; bh=IuLiBBEZlusXU1gKfm9cL2SjwhV2C2bnuqkLUGdujCg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fA8CR6CdMvowk2PAyDyMZ4fTN5/Gq209F8sFLIjQMMB/+OkjK7vGFlYze3X+PavRIQFgEudZoY/wCrlfV2QMq+FZAcMpDbQvDYlPdjYNaQAh6IPHM/C/6b20Hsx6YzXczbPN/v9O4jcYguuqJ8nLnxcXIlO9J9aImH+aYVo7E1c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aHLgGmq2; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aHLgGmq2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3881E1F000E9; Mon, 24 Aug 2026 14:31:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787581910; bh=1z9HiI7zqL51b8ondIELkFrtmRMkxdgCXcHXw5rmGwo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=aHLgGmq2jTXvtuzMS9yrycAKQypJaNoFTGRpmQkNEgONWNrfHAFT/qn1Kat4t/XRv +bjs0eDNZk9FX3zDR+wRBVV8dsP+nITGbyUyMOtY+XbhYKsvR6TNZ2hMgoUiRzY90V xdxwPumnx8Rr5LD3iiY2E+o7F9htz5eiFgfdp+l6qxjGEK7V+xJJKgXjV6NXasrQwX RPEK1EkITLkb6qDs+mkoZu/OqraNxaoOqTOl3nPSgjnh8KTFDzGRLj1tHuDPMAKm1f w/vaC8wnE79RCsiFkqa9SoTtR7JX6SCSmzQtFLB2qh9EtFpjXIjng7ysAdKedn5JI3 wmiIqZYHMzSMA== From: Sasha Levin To: stable@vger.kernel.org Cc: Pavitra Jha , Viacheslav Dubeyko , Ilya Dryomov , Sasha Levin Subject: [PATCH 5.15.y] libceph: fix OOB read in decode_watchers() via missing bounds check Date: Mon, 24 Aug 2026 10:31:47 -0400 Message-ID: <20260824143147.3387960-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026082057-aviator-unglazed-0547@gregkh> References: <2026082057-aviator-unglazed-0547@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Pavitra Jha [ Upstream commit 00ead17c7de137a692edee59f2772e6af687e8eb ] 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: a4ed38d7a180 ("libceph: support for CEPH_OSD_OP_LIST_WATCHERS") Signed-off-by: Pavitra Jha Reviewed-by: Viacheslav Dubeyko Signed-off-by: Ilya Dryomov [ kept the tree's `kcalloc()` context line instead of upstream's `kzalloc_objs()` ] Signed-off-by: Sasha Levin --- net/ceph/osd_client.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c index 94edea03b0cb2..25f25e026d8b5 100644 --- a/net/ceph/osd_client.c +++ b/net/ceph/osd_client.c @@ -4995,7 +4995,7 @@ static int decode_watchers(void **p, void *end, if (ret) return ret; - *num_watchers = ceph_decode_32(p); + ceph_decode_32_safe(p, end, *num_watchers, bad); *watchers = kcalloc(*num_watchers, sizeof(**watchers), GFP_NOIO); if (!*watchers) return -ENOMEM; @@ -5009,6 +5009,9 @@ static int decode_watchers(void **p, void *end, } return 0; + +bad: + return -EINVAL; } /* -- 2.53.0