Skip to contentSkip to conversation

libceph: mon_client: bound get_version reply decode to front len

PATCH In review Ren Wei 2 participants 2 messages Jun 7 – Jun 29 1 message not in the archive Ceph common code (libceph)

lore
Share & tools
lore

Ren Wei

author
#1 lore raw

PATCH 1/1 libceph: mon_client: bound get_version reply decode to front len

In reply to a message not in the archive

From: Douya Le <[email protected]>

handle_get_version_reply() uses msg->front_alloc_len as the decode boundary for MON_GET_VERSION_REPLY. That is the size of the reused reply buffer, not the number of bytes actually received.

A truncated reply can therefore pass ceph_decode_need() and decode the second u64 from stale tail bytes left in the buffer by an earlier message, causing an uninitialized memory read.

Use msg->front.iov_len as the receive-side decode boundary, matching other libceph reply handlers and limiting decoding to the bytes that were actually read from the wire.

Fixes 513a8243d67f ("libceph: mon_get_version request infrastructure")
Assisted-by Codex:GPT-5.4
---
 net/ceph/mon_client.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ceph/mon_client.c +1 -1
index d2cdc8ee3155..fd3ebebe5f4c 100644
@@ -821,7 +821,7 @@ static void handle_get_version_reply(struct ceph_mon_client *monc,
 	struct ceph_mon_generic_request *req;
 	u64 tid = le64_to_cpu(msg->hdr.tid);
 	void *p = msg->front.iov_base;
-	void *end = p + msg->front_alloc_len;
+	void *const end = p + msg->front.iov_len;
 	u64 handle;
 
 	dout("%s msg %p tid %llu\n", __func__, msg, tid);
Signature · 1 line
2.47.3
maintainer Reviewed-by on v1 1/1
#2 lore raw
Quoted 40 lines · Ren Wei

From: Douya Le <[email protected]>

handle_get_version_reply() uses msg->front_alloc_len as the decode boundary for MON_GET_VERSION_REPLY.  That is the size of the reused reply buffer, not the number of bytes actually received.

A truncated reply can therefore pass ceph_decode_need() and decode the
second u64 from stale tail bytes left in the buffer by an earlier message, causing an uninitialized memory read.

Use msg->front.iov_len as the receive-side decode boundary, matching other libceph reply handlers and limiting decoding to the bytes that were actually read from the wire.

Fixes 513a8243d67f ("libceph: mon_get_version request

infrastructure")

---
 net/ceph/mon_client.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
net/ceph/mon_client.c +1 -1
index d2cdc8ee3155..fd3ebebe5f4c 100644
@@ -821,7 +821,7 @@ static void handle_get_version_reply(struct
 ceph_mon_client *monc,
  	struct ceph_mon_generic_request *req;
  	u64 tid = le64_to_cpu(msg->hdr.tid);
  	void *p = msg->front.iov_base;
-	void *end = p + msg->front_alloc_len;
+	void *const end = p + msg->front.iov_len;
  	u64 handle;
Quoted 2 lines


  dout("%s msg %p tid %llu\n", __func__, msg, tid);

Makes sense.

Thanks,
Slava.