Skip to contentSkip to conversation

vsock01, CVE-2021-26708: Add reproducer for race condition

PATCH New Richard Palethorpe 3 participants 3 messages Jul 2, 2021 – Jul 6, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vsock01, CVE-2021-26708: Add reproducer for race condition

Also as this is the first VSOCK test, add the necessary bits to lapi and configure.

---
 configure.ac                        |   1 +
 include/lapi/vm_sockets.h           |  14 +++
 runtest/cve                         |   1 +
 testcases/network/.gitignore        |   1 +
 testcases/network/sockets/Makefile  |   1 +
 testcases/network/sockets/vsock01.c | 129 ++++++++++++++++++++++++++++
 6 files changed, 147 insertions(+)
 create mode 100644 include/lapi/vm_sockets.h
 create mode 100644 testcases/network/sockets/vsock01.c
configure.ac +1 -0
index eb675b367..1a43ebea8 100644
@@ -79,6 +79,7 @@ AC_CHECK_HEADERS_ONCE([ \
 ])
 AC_CHECK_HEADERS(fts.h, [have_fts=1])
 AC_SUBST(HAVE_FTS_H, $have_fts)
+AC_CHECK_HEADERS(linux/vm_sockets.h, [], [], [#include <sys/socket.h>])
 
 AC_CHECK_FUNCS_ONCE([ \
     clone3 \
include/lapi/vm_sockets.h new file +14 -0
new file mode 100644
index 000000000..94d0248c5
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC <[email protected]>
+ */
+
+#include <sys/socket.h>
+
+#if HAVE_LINUX_VM_SOCKETS_H
+#  include <linux/vm_sockets.h>
+#endif
+
+#ifndef VMADDR_CID_LOCAL
+#  define VMADDR_CID_LOCAL 1
+#endif
runtest/cve +1 -0
index 9da58d524..5a6ef966d 100644
@@ -63,3 +63,4 @@ cve-2020-14416 pty03
 cve-2020-25705 icmp_rate_limit01
 cve-2020-29373 io_uring02
 cve-2021-3444 bpf_prog05
+cve-2021-26708 vsock01
testcases/network/.gitignore +1 -0
index dab2bc34e..c65113960 100644
@@ -24,6 +24,7 @@
 /sctp/sctp_big_chunk
 /sockets/ltpClient
 /sockets/ltpServer
+/sockets/vsock01
 /stress/ns-tools/ns-icmp_redirector
 /stress/ns-tools/ns-icmpv4_sender
 /stress/ns-tools/ns-icmpv6_sender
testcases/network/sockets/Makefile +1 -0
index 7d4c289d0..5d655b8be 100644
@@ -10,4 +10,5 @@ INSTALL_TARGETS		:= *.sh
 
 LDLIBS			+= -lpthread
 
+include $(top_srcdir)/include/mk/testcases.mk
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/network/sockets/vsock01.c new file +129 -0

129 lines not on this page · raw message

Signature · 1 line
2.31.1
#1 lore raw

PATCH 1/1 vsock01, CVE-2021-26708: Add reproducer for race condition

Hi!

Quoted 10 lines
include/lapi/vm_sockets.h new file +4 -0
new file mode 100644
index 000000000..94d0248c5
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC <[email protected]>
+ */

include/lapi/vm_sockets.h line 14

Quoted 10 lines
include/lapi/vm_sockets.h new file +10 -0
+
+#include <sys/socket.h>
+
+#if HAVE_LINUX_VM_SOCKETS_H
+#  include <linux/vm_sockets.h>
+#endif
+
+#ifndef VMADDR_CID_LOCAL
+#  define VMADDR_CID_LOCAL 1
+#endif

I've added guards to this header.

Quoted 15 lines
include/lapi/vm_sockets.h new file +15 -0
+#include "config.h"
+#include "tst_test.h"
+
+#if HAVE_LINUX_VM_SOCKETS_H
+#  include "tst_fuzzy_sync.h"
+#  include "lapi/vm_sockets.h"
+
+static struct tst_fzsync_pair pair;
+int vsock = -1;
+
+void *writer(LTP_ATTRIBUTE_UNUSED void *unused)
+{
+	const uint64_t b_buflen = 0x4141;
+
+	while (tst_fzsync_run_b(&pair)) {

include/lapi/vm_sockets.h

Quoted 10 lines
include/lapi/vm_sockets.h new file +10 -0
+		tst_fzsync_start_race_b(&pair);
+		SAFE_SETSOCKOPT(vsock, AF_VSOCK,
+				SO_VM_SOCKETS_BUFFER_SIZE,
+				&b_buflen, sizeof(b_buflen));
+		tst_fzsync_end_race_b(&pair);
+	}
+
+
+	return NULL;
+}

And sprinkled a few 'static' keywords here, and pushed, thanks.

Signature · 2 lines
Cyril Hrubis
[email protected]
#2 lore raw

PATCH 1/1 vsock01, CVE-2021-26708: Add reproducer for race condition

Hello Cyril,

Quoted 43 lines · Cyril Hrubis

Hi!

Quoted 10 lines
include/lapi/vm_sockets.h new file +4 -0
new file mode 100644
index 000000000..94d0248c5
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC <[email protected]>
+ */

include/lapi/vm_sockets.h line 14

Quoted 10 lines
include/lapi/vm_sockets.h new file +10 -0
+
+#include <sys/socket.h>
+
+#if HAVE_LINUX_VM_SOCKETS_H
+#  include <linux/vm_sockets.h>
+#endif
+
+#ifndef VMADDR_CID_LOCAL
+#  define VMADDR_CID_LOCAL 1
+#endif

I've added guards to this header.

Quoted 19 lines
include/lapi/vm_sockets.h new file +19 -0
+#include "config.h"
+#include "tst_test.h"
+
+#if HAVE_LINUX_VM_SOCKETS_H
+#  include "tst_fuzzy_sync.h"
+#  include "lapi/vm_sockets.h"
+
+static struct tst_fzsync_pair pair;
+int vsock = -1;
+
+void *writer(LTP_ATTRIBUTE_UNUSED void *unused)
+{
+	const uint64_t b_buflen = 0x4141;
+
+	while (tst_fzsync_run_b(&pair)) {
+		tst_fzsync_start_race_b(&pair);
+		SAFE_SETSOCKOPT(vsock, AF_VSOCK,
+				SO_VM_SOCKETS_BUFFER_SIZE,
+				&b_buflen, sizeof(b_buflen));
Quoted 8 lines

include/lapi/vm_sockets.h

Quoted 6 lines
include/lapi/vm_sockets.h new file +6 -0
+		tst_fzsync_end_race_b(&pair);
+	}
+
+
+	return NULL;
+}

And sprinkled a few 'static' keywords here, and pushed, thanks.

Just noting; this would be caught by Wmissing-declarations.

Signature · 2 lines
Thank you,
Richard.