All of
 help / color / mirror / Atom feed
From: Julien Grall <>
Cc:, Julien Grall <>,
	Ian Jackson <>, Wei Liu <>,
	Juergen Gross <>
Subject: [PATCH] tools/xenstored: Don't assume errno will not be overwritten in lu_arch()
Date: Thu, 29 Jul 2021 12:06:47 +0100	[thread overview]
Message-ID: <> (raw)

From: Julien Grall <>

At the moment, do_control_lu() will set errno to 0 before calling
lu_arch() and then check errno. The expectation is nothing in lu_arch()
will change the value unless there is an error.

However, per errno(3), a function that succeeds is allowed to change
errno. In fact, syslog() will overwrite errno if the logs are rotated
at the time it is called.

To prevent any further issue, errno is now always set before
returning NULL.

Additionally, errno is only checked when returning NULL so the client
can see the error message if there is any.

Reported-by: Michael Kurth <>
Signed-off-by: Julien Grall <>
 tools/xenstore/xenstored_control.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_control.c
index 6b68b79faac7..6fcb42095b59 100644
--- a/tools/xenstore/xenstored_control.c
+++ b/tools/xenstore/xenstored_control.c
@@ -324,6 +324,7 @@ static const char *lu_binary_alloc(const void *ctx, struct connection *conn,
 	lu_status->kernel_size = size;
 	lu_status->kernel_off = 0;
+	errno = 0;
 	return NULL;
@@ -339,6 +340,7 @@ static const char *lu_binary_save(const void *ctx, struct connection *conn,
 	memcpy(lu_status->kernel + lu_status->kernel_off, data, size);
 	lu_status->kernel_off += size;
+	errno = 0;
 	return NULL;
@@ -798,9 +800,8 @@ static int do_control_lu(void *ctx, struct connection *conn,
 		if (!ret)
 			return errno;
 	} else {
-		errno = 0;
 		ret = lu_arch(ctx, conn, vec, num);
-		if (errno)
+		if (!ret && errno)
 			return errno;

             reply	other threads:[~2021-07-29 11:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-29 11:06 Julien Grall [this message]
2021-07-29 15:23 ` [PATCH] tools/xenstored: Don't assume errno will not be overwritten in lu_arch() Julien Grall
2021-07-30  8:40   ` Juergen Gross
2021-07-30 15:13     ` Julien Grall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.