Skip to contentSkip to conversation

CVE Tests

PATCH New Richard Palethorpe 4 participants 27 messages Jun 23, 2017 – Jun 11, 2019

lore
Share & tools
lore
#0 lore raw

v3 cover CVE Tests

Version 3:
* Move .gitignore and runtest additions to correct commits
* Replace tst_fzsync_init() with static declaration
* Remove packet time stamping test cve-2017-7277
* Remove explicit tid struct members
* Use new SAFE_SHM* macros
* Add Xiao Yang/Fujitsu to copyright notice for CVE-2017-5669

Version 2:
* Remove unresolved merge conflict from two commits
* Use _GNU_SOURCE instead of __USE_GNU

Richard Palethorpe (9):
Add fuzzy synchronisation library for triggering races Test for vulnerability CVE-2016-7117 in recvmmsg error return path Test for CVE-2016-4997 on setsockopt
Test for uname26 exploit CVE-2012-0957
Add CVE .gitignore, Makefile and runtest files
Test for CVE-2014-0196 PTY echo race
Test for CVE-2017-5669 in shmat
Test for CVE-2017-6951 in request_key
Test for CVE-2017-2671 on ping sockets

 configure.ac                  |   2 +
 include/tst_fuzzy_sync.h      | 184 ++++++++++++++++++++++++++++++++++++++++++
 m4/ltp-mmsghdr.m4             |  22 +++++
 m4/ltp-uname.m4               |  20 +++++
 runtest/cve                   |   9 +++
 runtest/syscalls              |   4 +
 scenario_groups/default       |   1 +
 testcases/cve/.gitignore      |   7 ++
 testcases/cve/Makefile        |  26 ++++++
 testcases/cve/cve-2012-0957.c |  89 ++++++++++++++++++++
 testcases/cve/cve-2014-0196.c | 161 ++++++++++++++++++++++++++++++++++++
 testcases/cve/cve-2016-4997.c |  92 +++++++++++++++++++++
 testcases/cve/cve-2016-7117.c | 158 ++++++++++++++++++++++++++++++++++++
 testcases/cve/cve-2017-2671.c | 120 +++++++++++++++++++++++++++
 testcases/cve/cve-2017-5669.c |  88 ++++++++++++++++++++
 testcases/cve/cve-2017-6951.c |  46 +++++++++++
 16 files changed, 1029 insertions(+)
 create mode 100644 include/tst_fuzzy_sync.h
 create mode 100644 m4/ltp-mmsghdr.m4
 create mode 100644 m4/ltp-uname.m4
 create mode 100644 runtest/cve
 create mode 100644 testcases/cve/.gitignore
 create mode 100644 testcases/cve/Makefile
 create mode 100644 testcases/cve/cve-2012-0957.c
 create mode 100644 testcases/cve/cve-2014-0196.c
 create mode 100644 testcases/cve/cve-2016-4997.c
 create mode 100644 testcases/cve/cve-2016-7117.c
 create mode 100644 testcases/cve/cve-2017-2671.c
 create mode 100644 testcases/cve/cve-2017-5669.c
 create mode 100644 testcases/cve/cve-2017-6951.c
Signature · 1 line
2.12.2
#1 lore raw

PATCH v3 1/9 Add fuzzy synchronisation library for triggering races

Provide some functions for starting two actions at approximately the same time on different threads or processes. This is intended to amalgamate functionality built into at least three CVE tests. As well as conforming to DRY it is intended to help make reasoning about each test easier by abstracting away the synchronisation mechanism.

---
 include/tst_fuzzy_sync.h | 184 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 184 insertions(+)
 create mode 100644 include/tst_fuzzy_sync.h
include/tst_fuzzy_sync.h new file +184 -0
new file mode 100644
index 000000000..122a6d736
@@ -0,0 +1,184 @@
+/*
+ * Copyright (c) 2017 Richard Palethorpe <[email protected]>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+/*
+ * Fuzzy Synchronisation - abreviated to fzsync
+ *
+ * This library is intended to help reproduce race conditions while running in
+ * a loop. You can use it to measure the time at which two functions are
+ * called in different threads. Then calculate the average time gap between
+ * the function calls and introduce a delay in one thread to synchronise the
+ * calls.
+ *
+ * It is called 'fuzzy' synchronisation because the time gap will naturally vary
+ * due to environmental factors. It is not a 'hard' synchronisation mechanism
+ * like lockstepping.
+ *
+ * For a usage example see testcases/cve/cve-2017-2671.c
+ */
+
+#include <sys/time.h>
+#include <time.h>
+
+#ifndef CLOCK_MONOTONIC_RAW
+#define CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC
+#endif
+
+/**
+ * struct tst_fzsync_pair - the state of a two way synchronisation
+ * @avg_diff: The average time difference over multiple iterations
+ * @avg_diff_trgt: The desired average time difference, defaults to 0
+ * @avg_alpha: The rate at which old diff samples are forgotten,
+ *             defaults to 0.25
+ * @a: The time at which call site A was last passed
+ * @b: The time at which call site B was last passed
+ * @delay: The size of the delay, positive to delay A, negative to delay B
+ * @delay_inc: The step size of a delay increment, defaults to 10
+ * @update_gap: The number of iterations between recalculating the delay.
+ *              Defaults to 0xF and must be of the form $2^n - 1$
+ *
+ * This contains all the necessary state for synchronising two points A and
+ * B. Where A is the time of an event in one process and B is the time of an
+ * event in another process.
+ */
+struct tst_fzsync_pair {
+	double avg_diff;
+	double avg_diff_trgt;
+	double avg_alpha;
+	struct timespec a;
+	struct timespec b;
+	long delay;
+	long delay_inc;
+	int update_gap;
+};
+
+/**
+ * TST_FZSYNC_PAIR_INIT - Default values for struct tst_fzysnc_pair
+ */
+#define TST_FZSYNC_PAIR_INIT {	\
+	.avg_alpha = 0.25,	\
+	.delay_inc = 10,	\
+	.update_gap = 0xF	\
+}
+
+static void tst_fzsync_pair_info(struct tst_fzsync_pair *pair)
+{
+	tst_res(TINFO, "avg_diff = %.5gns, delay = %05ld loops",
+		pair->avg_diff, pair->delay);
+}
+
+/**
+ * tst_fzsync_delay_a - Perform spin delay for A, if needed
+ *
+ * Usually called just before the point you want to synchronise.
+ */
+static inline void tst_fzsync_delay_a(struct tst_fzsync_pair *pair)
+{
+	volatile long spin_delay = pair->delay;
+
+	while (spin_delay > 0)
+		spin_delay--;
+}
+
+/**
+ * tst_fzsync_delay_b - Perform spin delay for B, if needed
+ *
+ * Usually called just before the point you want to synchronise.
+ */
+static inline void tst_fzsync_delay_b(struct tst_fzsync_pair *pair)
+{
+	volatile long spin_delay = pair->delay;
+
+	while (spin_delay < 0)
+		spin_delay++;
+}
+
+static inline void tst_fzsync_time(struct timespec *t)
+{
+	clock_gettime(CLOCK_MONOTONIC_RAW, t);
+}
+
+/**
+ * tst_fzsync_time_a - Set A's time to now.
+ *
+ * Called@the point you want to synchronise.
+ */
+static inline void tst_fzsync_time_a(struct tst_fzsync_pair *pair)
+{
+	tst_fzsync_time(&pair->a);
+}
+
+/**
+ * tst_fzsync_time_b - Set B's call time to now.
+ *
+ * Called at the point you want to synchronise.
+ */
+static inline void tst_fzsync_time_b(struct tst_fzsync_pair *pair)
+{
+	tst_fzsync_time(&pair->b);
+}
+
+/**
+ * tst_exp_moving_avg - Exponential moving average
+ * @alpha: The preference for receant samples over old ones.
+ * @sample: The current sample
+ * @prev_avg: The average of the all the previous samples
+ *
+ * Returns average including the current sample.
+ */
+static inline double tst_exp_moving_avg(double alpha, long sample,
+					double prev_avg)
+{
+	return alpha * sample + (1.0 - alpha) * prev_avg;
+}
+
+/**
+ * tst_fzsync_pair_update - Recalculate the delay
+ * @loop_index: The i in "for(i = 0;..." or zero to ignore update_gap
+ * @pair: The state necessary for calculating the delay
+ *
+ * This should be called at the end of each loop to update the average
+ * measured time difference (between A and B) and update the delay. It is
+ * assumed that A and B are less than a second apart.
+ *
+ * The values of update_gap, avg_alpha and delay_inc decide the speed at which
+ * the algorithm approaches the optimum delay value and whether it is
+ * stable. If your test is behaving strangely, it could be because this
+ * algorithm is behaving chaotically and flip-flopping between large positve
+ * and negative delay values. You can call tst_fzysync_pair_info every few
+ * loops to check whether the average difference and delay values are stable.
+ */
+static void tst_fzsync_pair_update(int loop_index, struct tst_fzsync_pair *pair)
+{
+	long diff;
+	long inc = pair->delay_inc;
+	long delay = pair->delay;
+	double target = pair->avg_diff_trgt;
+	double avg = pair->avg_diff;
+
+	diff = pair->a.tv_nsec - pair->b.tv_nsec;
+	avg = tst_exp_moving_avg(pair->avg_alpha, diff, avg);
+
+	if (!(loop_index & pair->update_gap)) {
+		if (avg > target)
+			delay -= inc;
+		else if (avg < target)
+			delay += inc;
+	}
+
+	pair->avg_diff = avg;
+	pair->delay = delay;
+}
Signature · 1 line
2.12.2
#2 lore raw

PATCH v3 1/9 Add fuzzy synchronisation library for triggering races

Hi!
Pushed with minor changes (see diff below), thanks.

include/tst_fuzzy_sync.h +4 -6
index 122a6d736..229217495 100644
@@ -34,7 +34,7 @@
 #include <time.h>
 
 #ifndef CLOCK_MONOTONIC_RAW
-#define CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC
+# define CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC
 #endif
 
 /**
@@ -133,7 +133,7 @@ static inline void tst_fzsync_time_b(struct tst_fzsync_pair *pair)
 
 /**
  * tst_exp_moving_avg - Exponential moving average
- * @alpha: The preference for receant samples over old ones.
+ * @alpha: The preference for recent samples over old ones.
  * @sample: The current sample
  * @prev_avg: The average of the all the previous samples
  *
@@ -165,7 +165,6 @@ static void tst_fzsync_pair_update(int loop_index, struct tst_fzsync_pair *pair)
 {
        long diff;
        long inc = pair->delay_inc;
-       long delay = pair->delay;
        double target = pair->avg_diff_trgt;
        double avg = pair->avg_diff;
 
@@ -174,11 +173,10 @@ static void tst_fzsync_pair_update(int loop_index, struct tst_fzsync_pair *pair)
 
        if (!(loop_index & pair->update_gap)) {
                if (avg > target)
-                       delay -= inc;
+                       pair->delay -= inc;
                else if (avg < target)
-                       delay += inc;
+                       pair->delay += inc;
        }
 
        pair->avg_diff = avg;
-       pair->delay = delay;
 }

Apart from fixing obvious typo and minor style issue I've changed this function not to tuch the pair->delay unless we recalculated it, as the code is a bit easier to understand that way.

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

PATCH v3 1/9 Add fuzzy synchronisation library for triggering races

In reply to Richard Palethorpe

So, I have had some feedback on the synchronisation library from Nicolai Stange and there are few things which can be fixed or improved. I can't necessarily do them straight away so I will list some of them here.

* Make the target (offset) time a range instead of a scalar value.
* Make target offset relative to CPU speed.
* Take tv_sec into account for when we are close to rolling from one second to the next.
* Use two long running threads instead of starting the second thread each iteration.

The target offset would be better as a range which we can slide over until the right timing is found. However the appropriate time range will be different for one system to the next, so this range should be normalised or we could generate it based on the time a relevant syscall takes to execute.

Just using the nano seconds from the timespec will result in occasional errors when the two timestamps are taken on either side of the boundary between two seconds e.g. a = 0.9999 and b = 1.0001.

Finally, we currently spin up a new child thread every iteration. However we could have two long running threads, or processes, which we synchronise every iteration using a second synchronisation primitive (The fork synchronisation library in LTP may already be suitable for this). This may reduce the variability between iterations.

--
Thank you,
Richard.

#4 lore raw

PATCH v3 2/9 Test for vulnerability CVE-2016-7117 in recvmmsg error return path

In reply to Richard Palethorpe
---
 configure.ac                  |   1 +
 m4/ltp-mmsghdr.m4             |  22 ++++++
 testcases/cve/cve-2016-7117.c | 158 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 181 insertions(+)
 create mode 100644 m4/ltp-mmsghdr.m4
 create mode 100644 testcases/cve/cve-2016-7117.c
configure.ac +1 -0
index cbe01d34f..326da8ece 100644
@@ -192,5 +192,6 @@ LTP_CHECK_EPOLL_PWAIT
 LTP_CHECK_KEYUTILS_SUPPORT
 LTP_CHECK_SYNC_ADD_AND_FETCH
 LTP_CHECK_BUILTIN_CLEAR_CACHE
+LTP_CHECK_MMSGHDR
 
 AC_OUTPUT
m4/ltp-mmsghdr.m4 new file +22 -0
new file mode 100644
index 000000000..05522180e
@@ -0,0 +1,22 @@
+dnl Copyright (c) 2017 Richard Palethorpe <[email protected]>
+dnl
+dnl This program is free software;  you can redistribute it and/or modify
+dnl it under the terms of the GNU General Public License as published by
+dnl the Free Software Foundation; either version 2 of the License, or
+dnl (at your option) any later version.
+dnl
+dnl This program is distributed in the hope that it will be useful,
+dnl but WITHOUT ANY WARRANTY;  without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+dnl the GNU General Public License for more details.
+dnl
+dnl You should have received a copy of the GNU General Public License
+dnl along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+AC_DEFUN([LTP_CHECK_MMSGHDR],[
+AC_CHECK_TYPES([struct mmsghdr],,,[
+#define _GNU_SOURCE
+#include <sys/types.h>
+#include <sys/socket.h>
+])
+])
testcases/cve/cve-2016-7117.c new file +158 -0

158 lines not on this page · raw message

Signature · 1 line
2.12.2
#5 lore raw

PATCH v3 2/9 Test for vulnerability CVE-2016-7117 in recvmmsg error return path

Hi!
I've added a #include "config.h" to the test to include the config created by configure explicitly. At the moment it's included via one of the headers included from the tst_test.h but that may change in the future.

Also when I tried to run the test my too early percentage seems to start at a pretty low number then climbs to nearly 100% steadily, which seems to be strange since the delay is more or less the same all the time. I will look into this later if time permits.

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

PATCH v3 3/9 Test for CVE-2016-4997 on setsockopt

In reply to Richard Palethorpe
---
 testcases/cve/cve-2016-4997.c | 92 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 92 insertions(+)
 create mode 100644 testcases/cve/cve-2016-4997.c
testcases/cve/cve-2016-4997.c new file +92 -0
new file mode 100644
index 000000000..a413b561e
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2017 Richard Palethorpe <[email protected]>
+ * Based on repro-compatReleaseEntry.c by NCC group
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+/*
+ * Test for CVE-2016-4997
+ *
+ * For a full explanation of how the vulnerability works see:
+ * https://github.com/nccgroup/TriforceLinuxSyscallFuzzer/tree/master/crash_reports/report_compatIpt
+ *
+ * The original vulnerability was present in the 32-bit compatibility system
+ * call, so the test should be compiled with -m32 and run on a 64-bit kernel.
+ * For simplicities sake the test requests root privliges instead of creating
+ * a user namespace.
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <net/if.h>
+#include <limits.h>
+#include <linux/netfilter_ipv4/ip_tables.h>
+
+#include "tst_test.h"
+#include "tst_safe_net.h"
+#include "tst_kernel.h"
+
+#define TOO_SMALL_OFFSET 74
+#define OFFSET_OVERWRITE 0xFFFF
+#define NEXT_OFFSET (sizeof(struct ipt_entry)		\
+		     + sizeof(struct xt_entry_match)	\
+		     + sizeof(struct xt_entry_target))
+#define PADDING (OFFSET_OVERWRITE - NEXT_OFFSET)
+
+struct payload {
+	struct ipt_replace repl;
+	struct ipt_entry ent;
+	struct xt_entry_match match;
+	struct xt_entry_target targ;
+	char padding[PADDING];
+	struct xt_entry_target targ2;
+};
+
+static void setup(void)
+{
+	if (tst_kernel_bits() == 32 || sizeof(long) > 4)
+		tst_res(TCONF,
+			"The vulnerability was only present in 32-bit compat mode");
+}
+
+static void run(void)
+{
+	int ret, sock_fd;
+	struct payload p = { 0 };
+
+	sock_fd = SAFE_SOCKET(AF_INET, SOCK_DGRAM, 0);
+
+	strncpy(p.match.u.user.name, "icmp", sizeof(p.match.u.user.name));
+	p.match.u.match_size = OFFSET_OVERWRITE;
+
+	p.ent.next_offset = NEXT_OFFSET;
+	p.ent.target_offset = TOO_SMALL_OFFSET;
+
+	p.repl.num_entries = 2;
+	p.repl.num_counters = 1;
+	p.repl.size = sizeof(struct payload);
+	p.repl.valid_hooks = 0;
+
+	ret = setsockopt(sock_fd, SOL_IP, IPT_SO_SET_REPLACE,
+			 &p, sizeof(struct payload));
+	tst_res(TPASS | TERRNO, "We didn't cause a crash, setsockopt returned %d", ret);
+}
+
+static struct tst_test test = {
+	.min_kver = "2.6.32",
+	.setup = setup,
+	.test_all = run,
+	.needs_root = 1,
+};
Signature · 1 line
2.12.2
#7 lore raw

PATCH v3 3/9 Test for CVE-2016-4997 on setsockopt

Hi!
Applied, thanks.

BTW: I will try to resurrect the 32bit library LTP patch so that we can
make use of it here.

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

PATCH v3 3/9 Test for CVE-2016-4997 on setsockopt

In reply to Richard Palethorpe

Hi Richard, Cyril,

looking at this LTP test (3be0d391f renamed it into testcases/kernel/syscalls/setsockopt/setsockopt03.c).

Quoted 3 lines
---
 testcases/cve/cve-2016-4997.c | 92 +++++++++++++++++++++++++++++++++++++++++++

...

testcases/cve/cve-2016-4997.c line 61

Quoted 5 lines
testcases/cve/cve-2016-4997.c new file +5 -0
+static void setup(void)
+{
+	if (tst_kernel_bits() == 32 || sizeof(long) > 4)
+		tst_res(TCONF,
+			"The vulnerability was only present in 32-bit compat mode");

Was it intentional to run it on normal 64bit?
Shouldn't it be tst_brk(TCONF, ...) used?

Kind regards,
Petr

Quoted 31 lines
testcases/cve/cve-2016-4997.c new file +31 -0
+}
+
+static void run(void)
+{
+	int ret, sock_fd;
+	struct payload p = { 0 };
+
+	sock_fd = SAFE_SOCKET(AF_INET, SOCK_DGRAM, 0);
+
+	strncpy(p.match.u.user.name, "icmp", sizeof(p.match.u.user.name));
+	p.match.u.match_size = OFFSET_OVERWRITE;
+
+	p.ent.next_offset = NEXT_OFFSET;
+	p.ent.target_offset = TOO_SMALL_OFFSET;
+
+	p.repl.num_entries = 2;
+	p.repl.num_counters = 1;
+	p.repl.size = sizeof(struct payload);
+	p.repl.valid_hooks = 0;
+
+	ret = setsockopt(sock_fd, SOL_IP, IPT_SO_SET_REPLACE,
+			 &p, sizeof(struct payload));
+	tst_res(TPASS | TERRNO, "We didn't cause a crash, setsockopt returned %d", ret);
+}
+
+static struct tst_test test = {
+	.min_kver = "2.6.32",
+	.setup = setup,
+	.test_all = run,
+	.needs_root = 1,
+};
#9 lore raw

PATCH v3 4/9 Test for uname26 exploit CVE-2012-0957

In reply to Richard Palethorpe

Attempt to exploit the uname kernel memory leak which occurred when the UNAME26 personality was set.

---
 configure.ac                  |  1 +
 m4/ltp-uname.m4               | 20 ++++++++++
 testcases/cve/cve-2012-0957.c | 89 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 110 insertions(+)
 create mode 100644 m4/ltp-uname.m4
 create mode 100644 testcases/cve/cve-2012-0957.c
configure.ac +1 -0
index 326da8ece..658003972 100644
@@ -193,5 +193,6 @@ LTP_CHECK_KEYUTILS_SUPPORT
 LTP_CHECK_SYNC_ADD_AND_FETCH
 LTP_CHECK_BUILTIN_CLEAR_CACHE
 LTP_CHECK_MMSGHDR
+LTP_CHECK_UNAME_DOMAINNAME
 
 AC_OUTPUT
m4/ltp-uname.m4 new file +20 -0
new file mode 100644
index 000000000..5a3002200
@@ -0,0 +1,20 @@
+dnl Copyright (c) 2017 Richard Palethorpe <[email protected]>
+dnl
+dnl This program is free software;  you can redistribute it and/or modify
+dnl it under the terms of the GNU General Public License as published by
+dnl the Free Software Foundation; either version 2 of the License, or
+dnl (at your option) any later version.
+dnl
+dnl This program is distributed in the hope that it will be useful,
+dnl but WITHOUT ANY WARRANTY;  without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+dnl the GNU General Public License for more details.
+dnl
+dnl You should have received a copy of the GNU General Public License
+dnl along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+AC_DEFUN([LTP_CHECK_UNAME_DOMAINNAME],[
+AC_CHECK_MEMBERS([struct utsname.domainname],,,[
+#define _GNU_SOURCE
+#include <sys/utsname.h>
+])])
testcases/cve/cve-2012-0957.c new file +89 -0

89 lines not on this page · raw message

Signature · 1 line
2.12.2
#10 lore raw

PATCH v3 4/9 Test for uname26 exploit CVE-2012-0957

Quoted 39 lines

Attempt to exploit the uname kernel memory leak which occurred when the UNAME26 personality was set.

---
 configure.ac                  |  1 +
 m4/ltp-uname.m4               | 20 ++++++++++
 testcases/cve/cve-2012-0957.c | 89 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 110 insertions(+)
 create mode 100644 m4/ltp-uname.m4
 create mode 100644 testcases/cve/cve-2012-0957.c
configure.ac +1 -0
index 326da8ece..658003972 100644
@@ -193,5 +193,6 @@ LTP_CHECK_KEYUTILS_SUPPORT
 LTP_CHECK_SYNC_ADD_AND_FETCH
 LTP_CHECK_BUILTIN_CLEAR_CACHE
 LTP_CHECK_MMSGHDR
+LTP_CHECK_UNAME_DOMAINNAME
 
 AC_OUTPUT
m4/ltp-uname.m4 new file +9 -0
new file mode 100644
index 000000000..5a3002200
@@ -0,0 +1,20 @@
+dnl Copyright (c) 2017 Richard Palethorpe <[email protected]>
+dnl
+dnl This program is free software;  you can redistribute it and/or modify
+dnl it under the terms of the GNU General Public License as published by
+dnl the Free Software Foundation; either version 2 of the License, or
+dnl (at your option) any later version.
+dnl
+dnl This program is distributed in the hope that it will be useful,
+dnl but WITHOUT ANY WARRANTY;  without even the implied warranty of

m4/ltp-uname.m4 line 19

Quoted 10 lines
m4/ltp-uname.m4 new file +10 -0
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+dnl the GNU General Public License for more details.
+dnl
+dnl You should have received a copy of the GNU General Public License
+dnl along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+AC_DEFUN([LTP_CHECK_UNAME_DOMAINNAME],[
+AC_CHECK_MEMBERS([struct utsname.domainname],,,[
+#define _GNU_SOURCE
+#include <sys/utsname.h>

Hi!
Applied, thanks.

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

PATCH v3 5/9 Add CVE .gitignore, Makefile and runtest files

In reply to Richard Palethorpe
---
 runtest/cve              |  5 +++++
 runtest/syscalls         |  2 ++
 scenario_groups/default  |  1 +
 testcases/cve/.gitignore |  3 +++
 testcases/cve/Makefile   | 25 +++++++++++++++++++++++++
 5 files changed, 36 insertions(+)
 create mode 100644 runtest/cve
 create mode 100644 testcases/cve/.gitignore
 create mode 100644 testcases/cve/Makefile
runtest/cve new file +5 -0
new file mode 100644
index 000000000..83b53d906
@@ -0,0 +1,5 @@
+# Tests which check for vulnerabilities by CVE number
+cve-2012-0957 cve-2012-0957
+cve-2016-4997 cve-2016-4997
+cve-2016-5195 dirtyc0w
+cve-2016-7117 cve-2016-7117
runtest/syscalls +2 -0
index 08d299a5b..85755eb12 100644
@@ -1143,6 +1143,7 @@ set_tid_address01 set_tid_address01
 setsid01 setsid01
 
 setsockopt01 setsockopt01
+cve-2016-4997 cve-2016-4997
 
 settimeofday01 settimeofday01
 settimeofday02 settimeofday02
@@ -1356,6 +1357,7 @@ umask01 umask01
 uname01 uname01
 uname02 uname02
 uname03 uname03
+cve-2012-0957 cve-2012-0957
 
 unlink01 symlink01 -T unlink01
 unlink05 unlink05
scenario_groups/default +1 -0
index b0d770171..5658a618b 100644
@@ -32,3 +32,4 @@ can
 cpuhotplug
 net.ipv6_lib
 input
+cve
testcases/cve/.gitignore new file +3 -0
new file mode 100644
index 000000000..9c24b83ec
@@ -0,0 +1,3 @@
+cve-2012-0957
+cve-2016-4997
+cve-2016-7117
testcases/cve/Makefile new file +25 -0
new file mode 100644
index 000000000..d642b73b4
@@ -0,0 +1,25 @@
+# Copyright (c) 2017 Linux Test Project
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+top_srcdir		?= ../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+CFLAGS			+= -D_GNU_SOURCE
+
+cve-2014-0196:	LDFLAGS += -lpthread -lutil -lrt
+cve-2016-7117:	LDFLAGS += -lpthread -lrt
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
Signature · 1 line
2.12.2
#12 lore raw

PATCH v3 5/9 Add CVE .gitignore, Makefile and runtest files

Hi!
Pushed, thanks.

(The first batch of cve tests has been pushed into the git repo now, and I will continue with the review.)

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

PATCH v3 6/9 Test for CVE-2014-0196 PTY echo race

In reply to Richard Palethorpe
---
 runtest/cve                   |   1 +
 testcases/cve/.gitignore      |   1 +
 testcases/cve/cve-2014-0196.c | 161 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 163 insertions(+)
 create mode 100644 testcases/cve/cve-2014-0196.c
runtest/cve +1 -0
index 83b53d906..6556ffb0f 100644
@@ -1,5 +1,6 @@
 # Tests which check for vulnerabilities by CVE number
 cve-2012-0957 cve-2012-0957
+cve-2014-0196 cve-2014-0196
 cve-2016-4997 cve-2016-4997
 cve-2016-5195 dirtyc0w
 cve-2016-7117 cve-2016-7117
testcases/cve/.gitignore +1 -0
index 9c24b83ec..ff5844263 100644
@@ -1,3 +1,4 @@
 cve-2012-0957
+cve-2014-0196
 cve-2016-4997
 cve-2016-7117
testcases/cve/cve-2014-0196.c new file +161 -0

161 lines not on this page · raw message

Signature · 1 line
2.12.2
#14 lore raw

PATCH v3 6/9 Test for CVE-2014-0196 PTY echo race

Hi!
I've added CFLAGS and LDLIBS to the Makefile (since I removed these while I was fixing the build) and pushed, thanks.

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

PATCH v3 7/9 Test for CVE-2017-5669 in shmat

In reply to Richard Palethorpe

Xiao Yang and myself independently wrote the same test. Xiao's version can be seen here: http://lists.linux.it/pipermail/ltp/2017-June/004695.html

---
 runtest/cve                   |  1 +
 runtest/syscalls              |  1 +
 testcases/cve/.gitignore      |  1 +
 testcases/cve/cve-2017-5669.c | 88 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 91 insertions(+)
 create mode 100644 testcases/cve/cve-2017-5669.c
runtest/cve +1 -0
index 6556ffb0f..166c98c8a 100644
@@ -4,3 +4,4 @@ cve-2014-0196 cve-2014-0196
 cve-2016-4997 cve-2016-4997
 cve-2016-5195 dirtyc0w
 cve-2016-7117 cve-2016-7117
+cve-2017-5669 cve-2017-5669
runtest/syscalls +1 -0
index 85755eb12..12ef696f1 100644
@@ -1164,6 +1164,7 @@ setxattr03 setxattr03
 shmat01 shmat01
 shmat02 shmat02
 shmat03 shmat03
+cve-2017-5669 cve-2017-5669
 
 shmctl01 shmctl01
 shmctl02 shmctl02
testcases/cve/.gitignore +1 -0
index ff5844263..715cbab38 100644
@@ -2,3 +2,4 @@ cve-2012-0957
 cve-2014-0196
 cve-2016-4997
 cve-2016-7117
+cve-2017-5669
testcases/cve/cve-2017-5669.c new file +88 -0

88 lines not on this page · raw message

Signature · 1 line
2.12.2
#16 lore raw

PATCH v3 7/9 Test for CVE-2017-5669 in shmat

Hi!

Quoted 4 lines
testcases/cve/cve-2017-5669.c new file +4 -0
+static void cleanup(void)
+{
+	if (shm_addr)
+		SAFE_SHMDT(shm_addr);

testcases/cve/cve-2017-5669.c line 59

Quoted 10 lines
testcases/cve/cve-2017-5669.c new file +10 -0
+	shm_addr = 0;
+
+	if (shm_id)
+		SAFE_SHMCTL(shm_id, IPC_RMID, 0);
+	shm_id = 0;
+}
+
+static void run(void)
+{
+	shm_id = SAFE_SHMGET(IPC_PRIVATE, getpagesize(), 0777);

Shouldn't be this done once in the test setup()?

Quoted 12 lines
testcases/cve/cve-2017-5669.c new file +12 -0
+	tst_res(TINFO, "Attempting to attach shared memory to null page");
+	shm_addr = shmat(shm_id, ((void *)1), SHM_RND);
+	if (shm_addr == (void *)-1) {
+		if (errno == EINVAL) {
+			tst_res(TPASS, "shmat returned EINVAL");
+			shm_addr = 0;
+			return;
+		}
+		tst_brk(TBROK | TERRNO,
+			"The bug was not triggered, but the shmat error is unexpected");
+	}
+

testcases/cve/cve-2017-5669.c line 82

Quoted 10 lines
testcases/cve/cve-2017-5669.c new file +10 -0
+	tst_res(TINFO, "Mapped shared memory to %p", shm_addr);
+
+	if (!((size_t)shm_addr & (~0U << 16)))
+		tst_res(TFAIL,
+			"We have mapped a VM address within the first 64Kb");
+	else
+		tst_res(TPASS,
+			"The kernel assigned a different VM address");
+
+	((char *)shm_addr)[0] = 'P';

Why do we try to write to the addres at all?

We do PASS/FAIL decision based only on the addres returned from shmat().

Also we should detach the memory here in case that the test was called with -i parameter.

Quoted 12 lines
testcases/cve/cve-2017-5669.c new file +6 -0
+}
+
+static struct tst_test test = {
+	.cleanup = cleanup,
+	.test_all = run,
+};
Signature · 5 lines
2.12.2


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis
[email protected]
#17 lore raw

PATCH v3 7/9 Test for CVE-2017-5669 in shmat

Hello Cyril,

Quoted 17 lines · Cyril Hrubis

Hi!

Quoted 4 lines
testcases/cve/cve-2017-5669.c new file +4 -0
+static void cleanup(void)
+{
+	if (shm_addr)
+		SAFE_SHMDT(shm_addr);

testcases/cve/cve-2017-5669.c line 59

Quoted 10 lines
testcases/cve/cve-2017-5669.c new file +10 -0
+	shm_addr = 0;
+
+	if (shm_id)
+		SAFE_SHMCTL(shm_id, IPC_RMID, 0);
+	shm_id = 0;
+}
+
+static void run(void)
+{
+	shm_id = SAFE_SHMGET(IPC_PRIVATE, getpagesize(), 0777);

Shouldn't be this done once in the test setup()?

Yes.

Quoted 26 lines
Quoted 13 lines
testcases/cve/cve-2017-5669.c new file +12 -0
+	tst_res(TINFO, "Attempting to attach shared memory to null page");
+	shm_addr = shmat(shm_id, ((void *)1), SHM_RND);
+	if (shm_addr == (void *)-1) {
+		if (errno == EINVAL) {
+			tst_res(TPASS, "shmat returned EINVAL");
+			shm_addr = 0;
+			return;
+		}
+		tst_brk(TBROK | TERRNO,
+			"The bug was not triggered, but the shmat error is unexpected");
+	}
+

testcases/cve/cve-2017-5669.c line 82

Quoted 10 lines
testcases/cve/cve-2017-5669.c new file +10 -0
+	tst_res(TINFO, "Mapped shared memory to %p", shm_addr);
+
+	if (!((size_t)shm_addr & (~0U << 16)))
+		tst_res(TFAIL,
+			"We have mapped a VM address within the first 64Kb");
+	else
+		tst_res(TPASS,
+			"The kernel assigned a different VM address");
+
+	((char *)shm_addr)[0] = 'P';

Why do we try to write to the addres at all?

Quoted 2 lines

We do PASS/FAIL decision based only on the addres returned from shmat().

To see if anything interesting happens, like a segfault. I don't think anything is likely to happen, but it seemed worth leaving in at the time.

Quoted 3 lines

Also we should detach the memory here in case that the test was called with -i parameter.

OK.

Signature · 2 lines
Thank you,
Richard.
#18 lore raw

PATCH v3 7/9 Test for CVE-2017-5669 in shmat

Hi!

Quoted 8 lines
Quoted 4 lines

Why do we try to write to the addres at all?

We do PASS/FAIL decision based only on the addres returned from shmat().

To see if anything interesting happens, like a segfault. I don't think anything is likely to happen, but it seemed worth leaving in at the time.

Maybe we should also add a TINFO message then, that we are about dereference the address then.

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

PATCH v4 1/1 Test for CVE-2017-5669 in shmat

Xiao Yang and myself independently wrote the same test. Xiao's version can be seen here: http://lists.linux.it/pipermail/ltp/2017-June/004695.html

---

* V4 - Add info message about touching the memory and make sure memory is cleaned up.

 runtest/cve                   |  1 +
 runtest/syscalls              |  1 +
 testcases/cve/.gitignore      |  1 +
 testcases/cve/cve-2017-5669.c | 97 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 100 insertions(+)
 create mode 100644 testcases/cve/cve-2017-5669.c
runtest/cve +1 -0
index 6556ffb0f..166c98c8a 100644
@@ -4,3 +4,4 @@ cve-2014-0196 cve-2014-0196
 cve-2016-4997 cve-2016-4997
 cve-2016-5195 dirtyc0w
 cve-2016-7117 cve-2016-7117
+cve-2017-5669 cve-2017-5669
runtest/syscalls +1 -0
index bd4f1e8e7..25fa74c10 100644
@@ -1160,6 +1160,7 @@ setxattr03 setxattr03
 
 shmat01 shmat01
 shmat02 shmat02
+cve-2017-5669 cve-2017-5669
 
 shmctl01 shmctl01
 shmctl02 shmctl02
testcases/cve/.gitignore +1 -0
index ff5844263..715cbab38 100644
@@ -2,3 +2,4 @@ cve-2012-0957
 cve-2014-0196
 cve-2016-4997
 cve-2016-7117
+cve-2017-5669
testcases/cve/cve-2017-5669.c new file +97 -0

97 lines not on this page · raw message

Signature · 1 line
2.13.2
#20 lore raw

PATCH v4 1/1 Test for CVE-2017-5669 in shmat

Hi!

Quoted 8 lines
testcases/cve/cve-2017-5669.c new file +8 -0
+static int shm_id;
+static void *shm_addr;
+
+static void setup(void)
+{
+	shm_id = SAFE_SHMGET(IPC_PRIVATE, getpagesize(), 0777);
+}
+

testcases/cve/cve-2017-5669.c line 60

Quoted 10 lines
testcases/cve/cve-2017-5669.c new file +10 -0
+static void cleanup(void)
+{
+	if (shm_addr)
+		SAFE_SHMDT(shm_addr);
+	shm_addr = 0;
+
+	if (shm_id)
+		SAFE_SHMCTL(shm_id, IPC_RMID, 0);
+	shm_id = 0;
+}

I've removed the assignments from here, since these were useless.

Quoted 20 lines
testcases/cve/cve-2017-5669.c new file +20 -0
+static void run(void)
+{
+	tst_res(TINFO, "Attempting to attach shared memory to null page");
+	shm_addr = shmat(shm_id, ((void *)1), SHM_RND);
+	if (shm_addr == (void *)-1) {
+		shm_addr = 0;
+		if (errno == EINVAL) {
+			tst_res(TPASS, "shmat returned EINVAL");
+			return;
+		}
+		tst_brk(TBROK | TERRNO,
+			"The bug was not triggered, but the shmat error is unexpected");
+	}
+
+	tst_res(TINFO, "Mapped shared memory to %p", shm_addr);
+
+	if (!((size_t)shm_addr & (~0U << 16)))
+		tst_res(TFAIL,
+			"We have mapped a VM address within the first 64Kb");
+	else

testcases/cve/cve-2017-5669.c line 91

Quoted 10 lines
testcases/cve/cve-2017-5669.c new file +10 -0
+		tst_res(TPASS,
+			"The kernel assigned a different VM address");
+
+	tst_res(TINFO,
+		"Touching shared memory to see if anything strange happens");
+	((char *)shm_addr)[0] = 'P';
+
+	SAFE_SHMDT(shm_addr);
+	shm_addr = 0;
+}

And used NULL for shm_addr ones and pushed, thanks.

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

PATCH v3 8/9 Test for CVE-2017-6951 in request_key

In reply to Richard Palethorpe
---
 runtest/cve                   |  1 +
 runtest/syscalls              |  1 +
 testcases/cve/.gitignore      |  1 +
 testcases/cve/cve-2017-6951.c | 46 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 49 insertions(+)
 create mode 100644 testcases/cve/cve-2017-6951.c
runtest/cve +1 -0
index 166c98c8a..ee0614a9c 100644
@@ -5,3 +5,4 @@ cve-2016-4997 cve-2016-4997
 cve-2016-5195 dirtyc0w
 cve-2016-7117 cve-2016-7117
 cve-2017-5669 cve-2017-5669
+cve-2017-6951 cve-2017-6951
runtest/syscalls +1 -0
index 12ef696f1..d72bc965b 100644
@@ -919,6 +919,7 @@ renameat202 renameat202 -i 10
 
 request_key01 request_key01
 request_key02 request_key02
+cve-2017-6951 cve-2017-6951
 
 rmdir01 rmdir01
 rmdir02 rmdir02
testcases/cve/.gitignore +1 -0
index 715cbab38..979d18369 100644
@@ -3,3 +3,4 @@ cve-2014-0196
 cve-2016-4997
 cve-2016-7117
 cve-2017-5669
+cve-2017-6951
testcases/cve/cve-2017-6951.c new file +46 -0

46 lines not on this page · raw message

Signature · 1 line
2.12.2
#23 lore raw

PATCH v3 9/9 Test for CVE-2017-2671 on ping sockets

In reply to Richard Palethorpe
---
 runtest/cve                   |   1 +
 testcases/cve/.gitignore      |   1 +
 testcases/cve/Makefile        |   1 +
 testcases/cve/cve-2017-2671.c | 120 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 123 insertions(+)
 create mode 100644 testcases/cve/cve-2017-2671.c
runtest/cve +1 -0
index ee0614a9c..32a39cf80 100644
@@ -4,5 +4,6 @@ cve-2014-0196 cve-2014-0196
 cve-2016-4997 cve-2016-4997
 cve-2016-5195 dirtyc0w
 cve-2016-7117 cve-2016-7117
+cve-2017-2671 cve-2017-2671
 cve-2017-5669 cve-2017-5669
 cve-2017-6951 cve-2017-6951
testcases/cve/.gitignore +1 -0
index 979d18369..b83372b08 100644
@@ -2,5 +2,6 @@ cve-2012-0957
 cve-2014-0196
 cve-2016-4997
 cve-2016-7117
+cve-2017-2671
 cve-2017-5669
 cve-2017-6951
testcases/cve/Makefile +1 -0
index d642b73b4..e9d9044d5 100644
@@ -21,5 +21,6 @@ CFLAGS			+= -D_GNU_SOURCE
 
 cve-2014-0196:	LDFLAGS += -lpthread -lutil -lrt
 cve-2016-7117:	LDFLAGS += -lpthread -lrt
+cve-2017-2671:	LDFLAGS += -lpthread -lrt
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/cve/cve-2017-2671.c new file +120 -0

120 lines not on this page · raw message

Signature · 1 line
2.12.2
#24 lore raw

PATCH v3 9/9 Test for CVE-2017-2671 on ping sockets

Hi!

Quoted 15 lines
testcases/cve/cve-2017-2671.c new file +15 -0
+static void run(void)
+{
+	pthread_t thrd;
+	int i;
+
+	sockfd = SAFE_SOCKET(AF_INET, SOCK_DGRAM, IPPROTO_ICMP);
+	tst_res(TINFO, "Created ping socket, attempting to race...");
+
+	for (i = 0; i < ATTEMPTS; i++) {
+		SAFE_CONNECT(sockfd,
+			     (struct sockaddr *)&iaddr, sizeof(iaddr));
+		SAFE_PTHREAD_CREATE(&thrd, 0, connect_b, 0);
+
+		tst_fzsync_delay_a(&fzsync_pair);
+		connect(sockfd, (struct sockaddr *)&uaddr, sizeof(uaddr));

testcases/cve/cve-2017-2671.c line 112

Quoted 10 lines
testcases/cve/cve-2017-2671.c new file +10 -0
+		tst_fzsync_time_a(&fzsync_pair);
+
+		SAFE_PTHREAD_JOIN(thrd, 0);
+		tst_fzsync_pair_update(i, &fzsync_pair);
+
+		if (!(i & 0x7FFF))
+			tst_fzsync_pair_info(&fzsync_pair);
+	}
+
+	tst_res(TPASS, "We didn't crash");

Hmm, shouldn't we close the sockfd here?

Or even better cannot we create the socket in the test setup and destroy it in the test cleanup. That way everything should work fine even with the -i option.

Quoted 14 lines
testcases/cve/cve-2017-2671.c new file +8 -0
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+	.cleanup = cleanup,
+	.needs_root = 1,
+};
Signature · 5 lines
2.12.2


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis
[email protected]
#25 lore raw

PATCH v4 1/1 Test for CVE-2017-2671 on ping sockets

---

V4 - Move socket creation and destruction to setup and cleanup. Also fix Makefile.

 runtest/cve                   |   1 +
 testcases/cve/.gitignore      |   1 +
 testcases/cve/Makefile        |   3 ++
 testcases/cve/cve-2017-2671.c | 121 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 126 insertions(+)
 create mode 100644 testcases/cve/cve-2017-2671.c
runtest/cve +1 -0
index ee0614a9c..32a39cf80 100644
@@ -4,5 +4,6 @@ cve-2014-0196 cve-2014-0196
 cve-2016-4997 cve-2016-4997
 cve-2016-5195 dirtyc0w
 cve-2016-7117 cve-2016-7117
+cve-2017-2671 cve-2017-2671
 cve-2017-5669 cve-2017-5669
 cve-2017-6951 cve-2017-6951
testcases/cve/.gitignore +1 -0
index bdb73f33b..1577cf914 100644
@@ -2,5 +2,6 @@ cve-2012-0957
 cve-2014-0196
 cve-2016-4997
 cve-2016-7117
+cve-2017-2671
 cve-2017-6951
 cve-2017-5669
testcases/cve/Makefile +3 -0
index 31f19d871..04abc1f9c 100644
@@ -25,4 +25,7 @@ cve-2016-7117:	LDLIBS += -lrt
 cve-2014-0196:  CFLAGS += -pthread
 cve-2014-0196:  LDLIBS += -lrt -lutil
 
+cve-2017-2671:	CFLAGS += -pthread
+cve-2017-2671:	LDLIBS += -lrt
+
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/cve/cve-2017-2671.c new file +121 -0

121 lines not on this page · raw message

Signature · 1 line
2.13.2