From nobody Tue Feb 10 11:55:51 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1623854629; cv=none; d=zohomail.com; s=zohoarc; b=jktyH8B1VOxsIVQWRUhKK1cL2ktgCrK+dUXiGoLUebT0V1w8GxxIEk2aaLzxhv0/BdgCTZZlf8dUuTebQbiKKx755XgGdxtdHqVdQzMiiskS0tzMv91xJ23wXoeWcc+GZ+GcIZkcN9+GZwqWviB1Vm60sWUFE1I3HZFDxWsZa40= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623854629; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=P1+HaOfv4X7DVCks8z7Jhaa8GAvQxlzVkg9j3S037W8=; b=OGVG9zXkouzRIs2vT2K2qj+BPDDf6oAU8TRw7tCiZmeiihfTHfu1q8P9Ireauf4d0LU5idL/xmpx98pM+dh7Jv+xU0DjPEuv8XH7ocFi8O17rpkqM2QA7RI6GbtBSaKjLlJtNkFt0dCcci68GbC9egmEKQyZ29Ka8aBVpOtC0VA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1623854629363375.3963700251297; Wed, 16 Jun 2021 07:43:49 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.143282.264146 (Exim 4.92) (envelope-from ) id 1ltWlS-0005o7-P6; Wed, 16 Jun 2021 14:43:34 +0000 Received: by outflank-mailman (output) from mailman id 143282.264146; Wed, 16 Jun 2021 14:43:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ltWlS-0005nt-Km; Wed, 16 Jun 2021 14:43:34 +0000 Received: by outflank-mailman (input) for mailman id 143282; Wed, 16 Jun 2021 14:43:33 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ltWlR-0005fp-7T for xen-devel@lists.xenproject.org; Wed, 16 Jun 2021 14:43:33 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ltWlQ-0004DK-36; Wed, 16 Jun 2021 14:43:32 +0000 Received: from 54-240-197-235.amazon.com ([54.240.197.235] helo=ufe34d9ed68d054.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ltWlP-0007D0-QY; Wed, 16 Jun 2021 14:43:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=P1+HaOfv4X7DVCks8z7Jhaa8GAvQxlzVkg9j3S037W8=; b=quBzH1JZOnInax6kNzeH3FNAI zbQZXo1G76WpD5d+HcsDZ6AHyMZ6J/2PCCik/5r6a0V2YUPwXGe2Em4vBSutgGFNH8nwsN3SdfjNM 7dWkknRc/yifzOYru3RRYEpUxPII6ICpxUPwHd6kYQZwMTHXkuhCBuz0b3D690WnDTrng=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: raphning@amazon.co.uk, doebel@amazon.de, Julien Grall , Ian Jackson , Wei Liu , Juergen Gross , Julien Grall Subject: [PATCH 03/10] tools/xenstore: Don't assume conn->in points to the LU request Date: Wed, 16 Jun 2021 15:43:17 +0100 Message-Id: <20210616144324.31652-4-julien@xen.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210616144324.31652-1-julien@xen.org> References: <20210616144324.31652-1-julien@xen.org> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Julien Grall call_delayed() is currently assuming that conn->in is NULL when handling delayed request. However, the connection is not paused. Therefore new request can be processed and conn->in may be non-NULL if we have only received a partial request. Furthermore, as we overwrite conn->in, the current partial request will not be transferred. This will result to corrupt the connection. Rather than updating conn->in, stash the LU request in lu_status and let each callback for delayed request to update conn->in when necessary. To keep a sane interface, the code to write the "OK" response the LU request is moved in xenstored_core.c. Fixes: c5ca1404b4 ("tools/xenstore: add support for delaying execution of a= xenstore request") Fixes: ed6eebf17d ("tools/xenstore: dump the xenstore state for live update= ") Signed-off-by: Julien Grall Reviewed-by: Juergen Gross ---- This is fixing bugs from two separate commits. I couldn't figure out how to split in two patches without breaking bisection. --- tools/xenstore/xenstored_control.c | 41 ++++++++++++++++++++++++++++-- tools/xenstore/xenstored_control.h | 3 +++ tools/xenstore/xenstored_core.c | 17 +++---------- 3 files changed, 46 insertions(+), 15 deletions(-) diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_= control.c index d08a2b961432..7acc2d134f9f 100644 --- a/tools/xenstore/xenstored_control.c +++ b/tools/xenstore/xenstored_control.c @@ -50,6 +50,9 @@ struct live_update { /* For verification the correct connection is acting. */ struct connection *conn; =20 + /* Pointer to the command used to request LU */ + struct buffered_data *in; + #ifdef __MINIOS__ void *kernel; unsigned int kernel_size; @@ -100,6 +103,7 @@ static const char *lu_begin(struct connection *conn) if (!lu_status) return "Allocation failure."; lu_status->conn =3D conn; + lu_status->in =3D conn->in; talloc_set_destructor(lu_status, lu_destroy); =20 return NULL; @@ -110,11 +114,34 @@ struct connection *lu_get_connection(void) return lu_status ? lu_status->conn : NULL; } =20 +unsigned int lu_write_response(FILE *fp) +{ + struct xsd_sockmsg msg; + + assert(lu_status); + + msg =3D lu_status->in->hdr.msg; + + msg.len =3D sizeof("OK"); + if (fp && fwrite(&msg, sizeof(msg), 1, fp) !=3D 1) + return 0; + if (fp && fwrite("OK", msg.len, 1, fp) !=3D 1) + return 0; + + return sizeof(msg) + msg.len; +} + #else struct connection *lu_get_connection(void) { return NULL; } + +unsigned int lu_write_response(FILE *fp) +{ + /* Unsupported */ + return 0; +} #endif =20 struct cmd_s { @@ -658,6 +685,8 @@ static bool do_lu_start(struct delayed_request *req) { time_t now =3D time(NULL); const char *ret; + struct buffered_data *saved_in; + struct connection *conn =3D lu_status->conn; =20 if (!lu_check_lu_allowed()) { if (now < lu_status->started_at + lu_status->timeout) @@ -668,8 +697,9 @@ static bool do_lu_start(struct delayed_request *req) } } =20 + assert(req->in =3D=3D lu_status->in); /* Dump out internal state, including "OK" for live update. */ - ret =3D lu_dump_state(req->in, lu_status->conn); + ret =3D lu_dump_state(req->in, conn); if (!ret) { /* Perform the activation of new binary. */ ret =3D lu_activate_binary(req->in); @@ -677,7 +707,14 @@ static bool do_lu_start(struct delayed_request *req) =20 /* We will reach this point only in case of failure. */ out: - send_reply(lu_status->conn, XS_CONTROL, ret, strlen(ret) + 1); + /* + * send_reply() will send the response for conn->in. Save the current + * conn->in and restore it afterwards. + */ + saved_in =3D conn->in; + conn->in =3D req->in; + send_reply(conn, XS_CONTROL, ret, strlen(ret) + 1); + conn->in =3D saved_in; talloc_free(lu_status); =20 return true; diff --git a/tools/xenstore/xenstored_control.h b/tools/xenstore/xenstored_= control.h index 6842b8d88760..27d7f19e4b7f 100644 --- a/tools/xenstore/xenstored_control.h +++ b/tools/xenstore/xenstored_control.h @@ -20,3 +20,6 @@ int do_control(struct connection *conn, struct buffered_d= ata *in); void lu_read_state(void); =20 struct connection *lu_get_connection(void); + +/* Write the "OK" response for the live-update command */ +unsigned int lu_write_response(FILE *fp); diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 607187361d84..41b26d7094c8 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -272,15 +272,10 @@ static int undelay_request(void *_req) =20 static void call_delayed(struct connection *conn, struct delayed_request *= req) { - assert(conn->in =3D=3D NULL); - conn->in =3D req->in; - if (req->func(req)) { undelay_request(req); talloc_set_destructor(req, NULL); } - - conn->in =3D NULL; } =20 int delay_request(struct connection *conn, struct buffered_data *in, @@ -2375,7 +2370,7 @@ const char *dump_state_buffered_data(FILE *fp, const = struct connection *c, struct buffered_data *out, *in =3D c->in; bool partial =3D true; =20 - if (in && c !=3D lu_get_connection()) { + if (in) { len =3D in->inhdr ? in->used : sizeof(in->hdr); if (fp && fwrite(&in->hdr, len, 1, fp) !=3D 1) return "Dump read data error"; @@ -2416,16 +2411,12 @@ const char *dump_state_buffered_data(FILE *fp, cons= t struct connection *c, =20 /* Add "OK" for live-update command. */ if (c =3D=3D lu_get_connection()) { - struct xsd_sockmsg msg =3D c->in->hdr.msg; + unsigned int rc =3D lu_write_response(fp); =20 - msg.len =3D sizeof("OK"); - if (fp && fwrite(&msg, sizeof(msg), 1, fp) !=3D 1) + if (!rc) return "Dump buffered data error"; - len +=3D sizeof(msg); - if (fp && fwrite("OK", msg.len, 1, fp) !=3D 1) =20 - return "Dump buffered data error"; - len +=3D msg.len; + len +=3D rc; } =20 if (sc) --=20 2.17.1