qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: qemu-block@nongnu.org, qemu-s390x@nongnu.org,
	"David Woodhouse" <dwmw@amazon.co.uk>,
	"Paul Durrant" <paul@xen.org>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [PULL 03/10] hw/xen: prevent guest from binding loopback event channel to itself
Date: Tue,  1 Aug 2023 23:54:14 +0200	[thread overview]
Message-ID: <20230801215421.60133-4-philmd@linaro.org> (raw)
In-Reply-To: <20230801215421.60133-1-philmd@linaro.org>

From: David Woodhouse <dwmw@amazon.co.uk>

Fuzzing showed that a guest could bind an interdomain port to itself, by
guessing the next port to be allocated and putting that as the 'remote'
port number. By chance, that works because the newly-allocated port has
type EVTCHNSTAT_unbound. It shouldn't.

Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Reviewed-by: Paul Durrant <paul@xen.org>
Message-Id: <20230801175747.145906-4-dwmw2@infradead.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/i386/kvm/xen_evtchn.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/hw/i386/kvm/xen_evtchn.c b/hw/i386/kvm/xen_evtchn.c
index 0e9c108614..a731738411 100644
--- a/hw/i386/kvm/xen_evtchn.c
+++ b/hw/i386/kvm/xen_evtchn.c
@@ -1408,8 +1408,15 @@ int xen_evtchn_bind_interdomain_op(struct evtchn_bind_interdomain *interdomain)
         XenEvtchnPort *rp = &s->port_table[interdomain->remote_port];
         XenEvtchnPort *lp = &s->port_table[interdomain->local_port];
 
-        if (rp->type == EVTCHNSTAT_unbound && rp->type_val == 0) {
-            /* It's a match! */
+        /*
+         * The 'remote' port for loopback must be an unbound port allocated for
+         * communication with the local domain (as indicated by rp->type_val
+         * being zero, not PORT_INFO_TYPEVAL_REMOTE_QEMU), and must *not* be
+         * the port that was just allocated for the local end.
+         */
+        if (interdomain->local_port != interdomain->remote_port &&
+            rp->type == EVTCHNSTAT_unbound && rp->type_val == 0) {
+
             rp->type = EVTCHNSTAT_interdomain;
             rp->type_val = interdomain->local_port;
 
-- 
2.38.1



  parent reply	other threads:[~2023-08-01 21:56 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-01 21:54 [PULL 00/10] Misc fixes for 2023-08-01 Philippe Mathieu-Daudé
2023-08-01 21:54 ` [PULL 01/10] hw/xen: fix off-by-one in xen_evtchn_set_gsi() Philippe Mathieu-Daudé
2023-08-01 21:54 ` [PULL 02/10] i386/xen: consistent locking around Xen singleshot timers Philippe Mathieu-Daudé
2023-08-01 21:54 ` Philippe Mathieu-Daudé [this message]
2023-08-01 21:54 ` [PULL 04/10] ui/dbus: fix win32 compilation when !opengl Philippe Mathieu-Daudé
2023-08-01 21:54 ` [PULL 05/10] ui/dbus: fix clang compilation issue Philippe Mathieu-Daudé
2023-08-01 21:54 ` [PULL 06/10] misc: Fix some typos in documentation and comments Philippe Mathieu-Daudé
2023-08-01 21:54 ` [PULL 07/10] tests/migration: Add -fno-stack-protector Philippe Mathieu-Daudé
2023-08-01 21:54 ` [PULL 08/10] target/nios2: Pass semihosting arg to exit Philippe Mathieu-Daudé
2023-08-01 21:54 ` [PULL 09/10] target/nios2: Fix semihost lseek offset computation Philippe Mathieu-Daudé
2023-08-01 21:54 ` [PULL 10/10] target/m68k: " Philippe Mathieu-Daudé
2023-08-02 15:14 ` [PULL 00/10] Misc fixes for 2023-08-01 Richard Henderson

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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

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

  git send-email \
    --in-reply-to=20230801215421.60133-4-philmd@linaro.org \
    --to=philmd@linaro.org \
    --cc=dwmw@amazon.co.uk \
    --cc=paul@xen.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* 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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).