Skip to contentSkip to conversation

tools/xenstored: Correctly read the requests header from the stream

PATCH In review Julien Grall 2 participants 3 messages Jun 25, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/xenstored: Correctly read the requests header from the stream

From: Julien Grall <[email protected]>

Commit c0fe360f42 ("tools/xenstored: Extend restore code to handle multiple input buffer") extend the read_buffered_state() to support multiple input buffers. Unfortunately, the commit didn't go far enough and still used sc->data (start of the buffers) for retrieving the header. This would lead to read the wrong headers for second and follow-up commands.

Use data in place for sc->data for the source of the memcpy()s.

Fixes c0fe360f42 ("tools/xenstored: Extend restore code to handle multiple input buffer")

----

I unfortunately didn't spot the issue because I forgot to check whether the REQ ID of the responses were unique.

---
 tools/xenstore/xenstored_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/xenstore/xenstored_core.c +2 -2
index cf7297a96cb1..16c856730c55 100644
@@ -2717,11 +2717,11 @@ void read_state_buffered_data(const void *ctx, struct connection *conn,
 		len = sc->data_in_len - (data - sc->data);
 		if (len < sizeof(bdata->hdr)) {
 			bdata->inhdr = true;
-			memcpy(&bdata->hdr, sc->data, len);
+			memcpy(&bdata->hdr, data, len);
 			bdata->used = len;
 		} else {
 			bdata->inhdr = false;
-			memcpy(&bdata->hdr, sc->data, sizeof(bdata->hdr));
+			memcpy(&bdata->hdr, data, sizeof(bdata->hdr));
 			if (bdata->hdr.msg.len <= DEFAULT_BUFFER_SIZE)
 				bdata->buffer = bdata->default_buffer;
 			else
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Julien Grall

From: Julien Grall <[email protected]>

Commit c0fe360f42 ("tools/xenstored: Extend restore code to handle multiple input buffer") extend the read_buffered_state() to support multiple input buffers. Unfortunately, the commit didn't go far enough and still used sc->data (start of the buffers) for retrieving the header. This would lead to read the wrong headers for second and follow-up commands.

Quoted 5 lines

Use data in place for sc->data for the source of the memcpy()s.

Fixes c0fe360f42 ("tools/xenstored: Extend restore code to handle multiple input buffer")

Juergen

#2 lore raw

Hi,

Quoted 10 lines · Juergen Gross
Quoted 9 lines · Julien Grall

From: Julien Grall <[email protected]>

Commit c0fe360f42 ("tools/xenstored: Extend restore code to handle multiple input buffer") extend the read_buffered_state() to support multiple input buffers. Unfortunately, the commit didn't go far enough and still used sc->data (start of the buffers) for retrieving the header. This would lead to read the wrong headers for second and follow-up commands.

Quoted 7 lines
Quoted 5 lines

Use data in place for sc->data for the source of the memcpy()s.

Fixes c0fe360f42 ("tools/xenstored: Extend restore code to handle multiple input buffer")

Thank you! I have committed the patch.

Cheers,

Quoted 3 lines

Juergen

Signature · 1 line
Julien Grall