Skip to contentSkip to conversation

Move if_packet.h compat macros to LAPI headers

PATCH New Martin Doucha 2 participants 8 messages May 5, 2020 – May 25, 2020

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/3 Move if_packet.h compat macros to LAPI headers

---

Changes since v1: New patch.

 include/lapi/if_ether.h                       | 19 ++++++++++
 include/lapi/if_packet.h                      | 32 ++++++++++++++++
 .../kernel/syscalls/setsockopt/setsockopt02.c | 37 +------------------
 3 files changed, 53 insertions(+), 35 deletions(-)
 create mode 100644 include/lapi/if_ether.h
include/lapi/if_ether.h new file +19 -0
new file mode 100644
index 000000000..0e9a4fcc1
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 SUSE LLC <[email protected]>
+ */
+
+#ifndef __LAPI_IF_ETHER_H__
+#define __LAPI_IF_ETHER_H__
+
+#include "config.h"
+
+#ifdef HAVE_LINUX_IF_ETHER_H
+# include <linux/if_ether.h>
+#endif
+
+#ifndef ETH_P_ALL
+# define ETH_P_ALL 0x0003
+#endif
+
+#endif /* __LAPI_IF_ETHER_H__ */
include/lapi/if_packet.h +32 -0
index c077b564d..81110217d 100644
@@ -7,6 +7,24 @@
 #ifndef __LAPI_IF_PACKET_H__
 #define __LAPI_IF_PACKET_H__
 
+#include "config.h"
+
+#ifdef HAVE_LINUX_IF_PACKET_H
+# include <linux/if_packet.h>
+#endif
+
+#ifndef PACKET_RX_RING
+# define PACKET_RX_RING 5
+#endif
+
+#ifndef PACKET_VERSION
+# define PACKET_VERSION 10
+#endif
+
+#ifndef PACKET_RESERVE
+# define PACKET_RESERVE 12
+#endif
+
 #ifndef PACKET_FANOUT
 #define PACKET_FANOUT	18
 #endif
@@ -15,4 +33,18 @@
 #define PACKET_FANOUT_ROLLOVER	3
 #endif
 
+#ifndef HAVE_STRUCT_TPACKET_REQ3
+# define TPACKET_V3 2
+
+struct tpacket_req3 {
+	unsigned int	tp_block_size;
+	unsigned int	tp_block_nr;
+	unsigned int	tp_frame_size;
+	unsigned int	tp_frame_nr;
+	unsigned int	tp_retire_blk_tov;
+	unsigned int	tp_sizeof_priv;
+	unsigned int	tp_feature_req_word;
+};
+#endif
+
 #endif /* __LAPI_IF_PACKET_H__ */
testcases/kernel/syscalls/setsockopt/setsockopt02.c +2 -35
index dc9db2d43..f0a2a5ecd 100644
@@ -20,41 +20,8 @@
 #include <errno.h>
 #include "tst_test.h"
 #include "tst_safe_net.h"
-#include "config.h"
-
-#ifdef HAVE_LINUX_IF_PACKET_H
-# include <linux/if_packet.h>
-#endif
-
-#ifdef HAVE_LINUX_IF_ETHER_H
-# include <linux/if_ether.h>
-#endif
-
-#ifndef ETH_P_ALL
-# define ETH_P_ALL 0x0003
-#endif
-
-#ifndef PACKET_RX_RING
-# define PACKET_RX_RING 5
-#endif
-
-#ifndef PACKET_VERSION
-# define PACKET_VERSION 10
-#endif
-
-#ifndef HAVE_STRUCT_TPACKET_REQ3
-# define TPACKET_V3 2
-
-struct tpacket_req3 {
-	unsigned int	tp_block_size;
-	unsigned int	tp_block_nr;
-	unsigned int	tp_frame_size;
-	unsigned int	tp_frame_nr;
-	unsigned int	tp_retire_blk_tov;
-	unsigned int	tp_sizeof_priv;
-	unsigned int	tp_feature_req_word;
-};
-#endif
+#include "lapi/if_packet.h"
+#include "lapi/if_ether.h"
 
 static int sk;
 static long pgsz;
Signature · 1 line
2.26.2
#1 lore raw

PATCH v2 2/3 Add test for CVE 2016-8655

---

Changes since v1:
- Use LAPI headers
- Minor cleanup
- Quit early if TPACKET_V3 is not supported

This test is awfully slow but it checks for local root exploit.

 runtest/cve                                   |   1 +
 runtest/syscalls                              |   1 +
 .../kernel/syscalls/setsockopt/.gitignore     |   1 +
 testcases/kernel/syscalls/setsockopt/Makefile |   2 +
 .../kernel/syscalls/setsockopt/setsockopt06.c | 135 ++++++++++++++++++
 5 files changed, 140 insertions(+)
 create mode 100644 testcases/kernel/syscalls/setsockopt/setsockopt06.c
runtest/cve +1 -0
index c2e9e8c89..786b5ee76 100644
@@ -12,6 +12,7 @@ cve-2016-4997 setsockopt03
 cve-2016-5195 dirtyc0w
 cve-2016-7042 cve-2016-7042
 cve-2016-7117 cve-2016-7117
+cve-2016-8655 setsockopt06
 cve-2016-9604 keyctl08
 cve-2016-9793 setsockopt04
 cve-2016-10044 cve-2016-10044
runtest/syscalls +1 -0
index cbab5730c..bdcd9a5b8 100644
@@ -1326,6 +1326,7 @@ setsockopt02 setsockopt02
 setsockopt03 setsockopt03
 setsockopt04 setsockopt04
 setsockopt05 setsockopt05
+setsockopt06 setsockopt06
 
 settimeofday01 settimeofday01
 settimeofday02 settimeofday02
testcases/kernel/syscalls/setsockopt/.gitignore +1 -0
index f4eabd92b..ad067c3e3 100644
@@ -3,3 +3,4 @@
 /setsockopt03
 /setsockopt04
 /setsockopt05
+/setsockopt06
testcases/kernel/syscalls/setsockopt/Makefile +2 -0
index 044619fb8..1e80facd4 100644
@@ -2,6 +2,8 @@
 # Copyright (c) International Business Machines  Corp., 2001
 
 top_srcdir		?= ../../../..
+setsockopt06:		CFLAGS += -pthread
+setsockopt06:		LDLIBS += -lrt
 
 include $(top_srcdir)/include/mk/testcases.mk
 
testcases/kernel/syscalls/setsockopt/setsockopt06.c new file +135 -0

135 lines not on this page · raw message

Signature · 1 line
2.26.2
#3 lore raw

PATCH v2 3/3 Add test for CVE 2017-1000111

In reply to Martin Doucha

Fixes #497

---

Changes since v1:
- Use LAPI headers
- Quit early if TPACKET_V3 is not supported

The tiny race iteration limit is intentional. The bug is mostly harmless and the setsockopt(PACKET_RX_RING) syscall is really slow. Vulnerable kernels will fail the test in 15 iterations or less. The test will run for about 30 seconds on patched systems.

 runtest/cve                                   |   1 +
 runtest/syscalls                              |   1 +
 .../kernel/syscalls/setsockopt/.gitignore     |   1 +
 testcases/kernel/syscalls/setsockopt/Makefile |   4 +-
 .../kernel/syscalls/setsockopt/setsockopt07.c | 145 ++++++++++++++++++
 5 files changed, 150 insertions(+), 2 deletions(-)
 create mode 100644 testcases/kernel/syscalls/setsockopt/setsockopt07.c
runtest/cve +1 -0
index 786b5ee76..339d57f23 100644
@@ -40,6 +40,7 @@ cve-2017-16939 cve-2017-16939
 cve-2017-16995 bpf_prog03
 cve-2017-17053 cve-2017-17053
 cve-2017-18075 pcrypt_aead01
+cve-2017-1000111 setsockopt07
 cve-2017-1000112 setsockopt05
 cve-2017-1000380 snd_timer01
 cve-2018-5803 sctp_big_chunk
runtest/syscalls +1 -0
index bdcd9a5b8..3d953fd22 100644
@@ -1327,6 +1327,7 @@ setsockopt03 setsockopt03
 setsockopt04 setsockopt04
 setsockopt05 setsockopt05
 setsockopt06 setsockopt06
+setsockopt07 setsockopt07
 
 settimeofday01 settimeofday01
 settimeofday02 settimeofday02
testcases/kernel/syscalls/setsockopt/.gitignore +1 -0
index ad067c3e3..1ca5b836b 100644
@@ -4,3 +4,4 @@
 /setsockopt04
 /setsockopt05
 /setsockopt06
+/setsockopt07
testcases/kernel/syscalls/setsockopt/Makefile +2 -2
index 1e80facd4..678ada75a 100644
@@ -2,8 +2,8 @@
 # Copyright (c) International Business Machines  Corp., 2001
 
 top_srcdir		?= ../../../..
-setsockopt06:		CFLAGS += -pthread
-setsockopt06:		LDLIBS += -lrt
+setsockopt06 setsockopt07:	CFLAGS += -pthread
+setsockopt06 setsockopt07:	LDLIBS += -lrt
 
 include $(top_srcdir)/include/mk/testcases.mk
 
testcases/kernel/syscalls/setsockopt/setsockopt07.c new file +145 -0

145 lines not on this page · raw message

Signature · 1 line
2.26.2
#4 lore raw

PATCH v2 3/3 Add test for CVE 2017-1000111

Hi Martin,

testcases/kernel/syscalls/setsockopt/setsockopt07.c line 39

Quoted 4 lines
testcases/kernel/syscalls/setsockopt/setsockopt07.c new file +4 -0
+static void setup(void)
+{
+	int real_uid = getuid();
+	int real_gid = getgid();

Don't we want to add here taint check (you had it in v1)? tst_taint_init(TST_TAINT_W | TST_TAINT_D);

Otherwise whole patchset LGTM.

Kind regards,
Petr

#5 lore raw

PATCH v2 3/3 Add test for CVE 2017-1000111

Quoted 9 lines · Petr Vorel

Hi Martin,

testcases/kernel/syscalls/setsockopt/setsockopt07.c line 39

Quoted 4 lines
testcases/kernel/syscalls/setsockopt/setsockopt07.c new file +4 -0
+static void setup(void)
+{
+	int real_uid = getuid();
+	int real_gid = getgid();

Don't we want to add here taint check (you had it in v1)? tst_taint_init(TST_TAINT_W | TST_TAINT_D);

Taint check is meaningless in this test because the only ill effect from the race condition is that all incoming packets will be truncated to 0 bytes. Somebody would have to horribly break the code for receiving incoming packets in order to turn this bug into something that can actually taint the kernel.

Signature · 7 lines
Martin Doucha   [email protected]
QA Engineer for Software Maintenance
SUSE LINUX, s.r.o.
CORSO IIa
Krizikova 148/34
186 00 Prague 8
Czech Republic
#6 lore raw

PATCH v2 3/3 Add test for CVE 2017-1000111

Hi Martin,

Quoted 8 lines
Quoted 2 lines

Don't we want to add here taint check (you had it in v1)? tst_taint_init(TST_TAINT_W | TST_TAINT_D);

Taint check is meaningless in this test because the only ill effect from the race condition is that all incoming packets will be truncated to 0 bytes. Somebody would have to horribly break the code for receiving incoming packets in order to turn this bug into something that can actually taint the kernel.

Right, that makes no sense to add it then.
Thanks for explanation and your patchset, merged.

Kind regards,
Petr