Skip to contentSkip to conversation

Add setsockopt10 TLS ULP UAF CVE-2023-0461

PATCH Superseded Richard Palethorpe via ltp 4 participants 8 messages Oct 12, 2023 – Oct 16, 2023

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add setsockopt10 TLS ULP UAF CVE-2023-0461

---
 configure.ac                                  |   1 +
 runtest/cve                                   |   1 +
 runtest/syscalls                              |   1 +
 .../kernel/syscalls/setsockopt/.gitignore     |   1 +
 .../kernel/syscalls/setsockopt/setsockopt10.c | 204 ++++++++++++++++++
 5 files changed, 208 insertions(+)
 create mode 100644 testcases/kernel/syscalls/setsockopt/setsockopt10.c
configure.ac +1 -0
index 662c4c058..ee39f6b25 100644
@@ -64,6 +64,7 @@ AC_CHECK_HEADERS_ONCE([ \
     linux/netlink.h \
     linux/seccomp.h \
     linux/securebits.h \
+    linux/tls.h \
     linux/tty.h \
     linux/types.h \
     linux/userfaultfd.h \
runtest/cve +1 -0
index f9b36a182..569558af2 100644
@@ -85,6 +85,7 @@ cve-2022-0847 dirtypipe
 cve-2022-2590 dirtyc0w_shmem
 cve-2022-23222 bpf_prog07
 cve-2023-1829 tcindex01
+cve-2023-0461 setsockopt10
 # Tests below may cause kernel memory leak
 cve-2020-25704 perf_event_open03
 cve-2022-0185 fsconfig03
runtest/syscalls +1 -0
index 149c93820..471476411 100644
@@ -1425,6 +1425,7 @@ setsockopt06 setsockopt06
 setsockopt07 setsockopt07
 setsockopt08 setsockopt08
 setsockopt09 setsockopt09
+setsockopt10 setsockopt10
 
 settimeofday01 settimeofday01
 settimeofday02 settimeofday02
testcases/kernel/syscalls/setsockopt/.gitignore +1 -0
index fd3235bb3..5c05290a5 100644
@@ -7,3 +7,4 @@
 /setsockopt07
 /setsockopt08
 /setsockopt09
+/setsockopt10
testcases/kernel/syscalls/setsockopt/setsockopt10.c new file +204 -0

204 lines not on this page · raw message

Signature · 5 lines
2.40.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi!

Quoted 83 lines
testcases/kernel/syscalls/setsockopt/setsockopt10.c new file +83 -0
+#include "tst_test.h"
+
+#ifdef HAVE_LINUX_TLS_H
+
+#include <linux/tls.h>
+#include "netinet/in.h"
+#include "netinet/tcp.h"
+#include "tst_checkpoint.h"
+#include "tst_net.h"
+#include "tst_safe_net.h"
+#include "tst_taint.h"
+
+static struct tls12_crypto_info_aes_gcm_128 opts = {
+	.info = {
+		.version = TLS_1_2_VERSION,
+		.cipher_type = TLS_CIPHER_AES_GCM_128,
+	},
+	.iv = { 'i', 'v' },
+	.key = { 'k', 'e', 'y' },
+	.salt = { 's', 'a', 'l', 't' },
+	.rec_seq = { 'r', 'e', 'c', 's' },
+};
+
+static struct sockaddr_in tcp0_addr, tcp1_addr;
+static const struct sockaddr unspec_addr = {
+	.sa_family = AF_UNSPEC
+};
+
+static int tcp0_sk, tcp1_sk, tcp2_sk, tcp3_sk;
+
+static void setup(void)
+{
+	tst_init_sockaddr_inet(&tcp0_addr, "127.0.0.1", 0x7c90);
+	tst_init_sockaddr_inet(&tcp1_addr, "127.0.0.1", 0x7c91);
+}
+
+static void cleanup(void)
+{
+	if (tcp0_sk > 0)
+		SAFE_CLOSE(tcp0_sk);
+	if (tcp1_sk > 0)
+		SAFE_CLOSE(tcp1_sk);
+	if (tcp2_sk > 0)
+		SAFE_CLOSE(tcp2_sk);
+	if (tcp3_sk > 0)
+		SAFE_CLOSE(tcp3_sk);
+}
+
+static void child(void)
+{
+	tst_res(TINFO, "child: Listen for tcp1 connection");
+	tcp0_sk = SAFE_SOCKET(AF_INET, SOCK_STREAM, 0);
+	SAFE_BIND(tcp0_sk, (struct sockaddr *)&tcp0_addr, sizeof(tcp0_addr));
+	SAFE_LISTEN(tcp0_sk, 1);
+	TST_CHECKPOINT_WAKE(0);
+
+	tcp3_sk = SAFE_ACCEPT(tcp0_sk, NULL, 0);
+	TST_CHECKPOINT_WAIT(1);
+	SAFE_CLOSE(tcp3_sk);
+	SAFE_CLOSE(tcp0_sk);
+
+	tcp3_sk = SAFE_SOCKET(AF_INET, SOCK_STREAM, 0);
+	TST_CHECKPOINT_WAIT(2);
+
+	tst_res(TINFO, "child: connect for tcp2 connection");
+	TEST(connect(tcp3_sk, (struct sockaddr *)&tcp1_addr, sizeof(tcp1_addr)));
+
+	if (TST_RET == -1) {
+		tst_res(TINFO | TTERRNO, "child: could not connect to tcp1");
+		return;
+	}
+
+	TST_CHECKPOINT_WAIT(3);
+}
+
+static void run(void)
+{
+	const pid_t child_pid = SAFE_FORK();
+
+	if (child_pid == 0) {
+		child();
+		return;
+	}

testcases/kernel/syscalls/setsockopt/setsockopt10.c line 138

Quoted 10 lines
testcases/kernel/syscalls/setsockopt/setsockopt10.c new file +10 -0
+
+	tcp1_sk = SAFE_SOCKET(AF_INET, SOCK_STREAM, 0);
+	TST_CHECKPOINT_WAIT(0);
+
+	tst_res(TINFO, "parent: Connect for tcp0 connection");
+	SAFE_CONNECT(tcp1_sk, (struct sockaddr *)&tcp0_addr, sizeof(tcp0_addr));
+	TEST(setsockopt(tcp1_sk, SOL_TCP, TCP_ULP, "tls", 3));
+
+	if (TST_RET == -1 && TST_ERR == ENOENT)
+		tst_brk(TCONF | TTERRNO, "parent: setsockopt failed: The TLS module is probably not loaded");

Should we set .needs_drivers for the test so that it only attempts to run either if TLS is compiled in or could be modprobed as a module?

Quoted 23 lines
testcases/kernel/syscalls/setsockopt/setsockopt10.c new file +23 -0
+	else if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "parent: setsockopt failed");
+
+	SAFE_SETSOCKOPT(tcp1_sk, SOL_TLS, TLS_TX, &opts, sizeof(opts));
+	TST_CHECKPOINT_WAKE(1);
+
+	tst_res(TINFO, "parent: Disconnect by setting unspec address");
+	SAFE_CONNECT(tcp1_sk, &unspec_addr, sizeof(unspec_addr));
+	SAFE_BIND(tcp1_sk, (struct sockaddr *)&tcp1_addr, sizeof(tcp1_addr));
+
+	TEST(listen(tcp1_sk, 1));
+
+	if (TST_RET == -1) {
+		if (TST_ERR == EINVAL)
+			tst_res(TPASS | TTERRNO, "parent: Can't listen on disconnected TLS socket");
+		else
+			tst_res(TCONF | TTERRNO, "parent: Can't listen on disconnected TLS socket, but the errno is not EINVAL as expected");
+
+		TST_CHECKPOINT_WAKE(2);
+		goto out;
+	}
+
+	tst_res(TINFO, "parent: Can listen on disconnected TLS socket");

testcases/kernel/syscalls/setsockopt/setsockopt10.c line 171

Quoted 10 lines
testcases/kernel/syscalls/setsockopt/setsockopt10.c new file +10 -0
+	TST_CHECKPOINT_WAKE(2);
+
+	tcp2_sk = SAFE_ACCEPT(tcp1_sk, NULL, 0);
+	SAFE_CLOSE(tcp2_sk);
+
+	tst_res(TINFO, "parent: Attempting double free, because we set cipher options this should result in an crash");
+	SAFE_CLOSE(tcp1_sk);
+
+	TST_CHECKPOINT_WAKE(3);
+	usleep(0);

Did you forget this here?

testcases/kernel/syscalls/setsockopt/setsockopt10.c line 176

Quoted 4 lines
testcases/kernel/syscalls/setsockopt/setsockopt10.c new file +4 -0
+	if (tst_taint_check())
+		tst_res(TFAIL, "Kernel is tainted");
+	else
+		tst_res(TCONF, "No kernel taint or crash, maybe the kernel can clone the TLS-ULP context now?");

If you set up .taint_check this is going to be redundant since we print TFAIL in the test library in that case.

Quoted 33 lines
testcases/kernel/syscalls/setsockopt/setsockopt10.c new file +27 -0
+out:
+	tst_reap_children();
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run,
+	.forks_child = 1,
+	.needs_checkpoints = 1,
+	.taint_check = TST_TAINT_W | TST_TAINT_D,
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_TLS",
+		NULL
+	},
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "2c02d41d71f90"},
+		{"CVE", "2023-0461"},
+		{}
+	}
+};
+
+#else
+
+TST_TEST_TCONF("linux/tls.h missing, we assume your system is too old");
+
+#endif
Signature · 5 lines
2.40.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

Hello,

Quoted 89 lines · Cyril Hrubis

Hi!

Quoted 88 lines
testcases/kernel/syscalls/setsockopt/setsockopt10.c new file +88 -0
+#include "tst_test.h"
+
+#ifdef HAVE_LINUX_TLS_H
+
+#include <linux/tls.h>
+#include "netinet/in.h"
+#include "netinet/tcp.h"
+#include "tst_checkpoint.h"
+#include "tst_net.h"
+#include "tst_safe_net.h"
+#include "tst_taint.h"
+
+static struct tls12_crypto_info_aes_gcm_128 opts = {
+	.info = {
+		.version = TLS_1_2_VERSION,
+		.cipher_type = TLS_CIPHER_AES_GCM_128,
+	},
+	.iv = { 'i', 'v' },
+	.key = { 'k', 'e', 'y' },
+	.salt = { 's', 'a', 'l', 't' },
+	.rec_seq = { 'r', 'e', 'c', 's' },
+};
+
+static struct sockaddr_in tcp0_addr, tcp1_addr;
+static const struct sockaddr unspec_addr = {
+	.sa_family = AF_UNSPEC
+};
+
+static int tcp0_sk, tcp1_sk, tcp2_sk, tcp3_sk;
+
+static void setup(void)
+{
+	tst_init_sockaddr_inet(&tcp0_addr, "127.0.0.1", 0x7c90);
+	tst_init_sockaddr_inet(&tcp1_addr, "127.0.0.1", 0x7c91);
+}
+
+static void cleanup(void)
+{
+	if (tcp0_sk > 0)
+		SAFE_CLOSE(tcp0_sk);
+	if (tcp1_sk > 0)
+		SAFE_CLOSE(tcp1_sk);
+	if (tcp2_sk > 0)
+		SAFE_CLOSE(tcp2_sk);
+	if (tcp3_sk > 0)
+		SAFE_CLOSE(tcp3_sk);
+}
+
+static void child(void)
+{
+	tst_res(TINFO, "child: Listen for tcp1 connection");
+	tcp0_sk = SAFE_SOCKET(AF_INET, SOCK_STREAM, 0);
+	SAFE_BIND(tcp0_sk, (struct sockaddr *)&tcp0_addr, sizeof(tcp0_addr));
+	SAFE_LISTEN(tcp0_sk, 1);
+	TST_CHECKPOINT_WAKE(0);
+
+	tcp3_sk = SAFE_ACCEPT(tcp0_sk, NULL, 0);
+	TST_CHECKPOINT_WAIT(1);
+	SAFE_CLOSE(tcp3_sk);
+	SAFE_CLOSE(tcp0_sk);
+
+	tcp3_sk = SAFE_SOCKET(AF_INET, SOCK_STREAM, 0);
+	TST_CHECKPOINT_WAIT(2);
+
+	tst_res(TINFO, "child: connect for tcp2 connection");
+	TEST(connect(tcp3_sk, (struct sockaddr *)&tcp1_addr, sizeof(tcp1_addr)));
+
+	if (TST_RET == -1) {
+		tst_res(TINFO | TTERRNO, "child: could not connect to tcp1");
+		return;
+	}
+
+	TST_CHECKPOINT_WAIT(3);
+}
+
+static void run(void)
+{
+	const pid_t child_pid = SAFE_FORK();
+
+	if (child_pid == 0) {
+		child();
+		return;
+	}
+
+	tcp1_sk = SAFE_SOCKET(AF_INET, SOCK_STREAM, 0);
+	TST_CHECKPOINT_WAIT(0);
+
+	tst_res(TINFO, "parent: Connect for tcp0 connection");
Quoted 8 lines

testcases/kernel/syscalls/setsockopt/setsockopt10.c line 138

Quoted 5 lines
testcases/kernel/syscalls/setsockopt/setsockopt10.c new file +5 -0
+	SAFE_CONNECT(tcp1_sk, (struct sockaddr *)&tcp0_addr, sizeof(tcp0_addr));
+	TEST(setsockopt(tcp1_sk, SOL_TCP, TCP_ULP, "tls", 3));
+
+	if (TST_RET == -1 && TST_ERR == ENOENT)
+		tst_brk(TCONF | TTERRNO, "parent: setsockopt failed: The TLS module is probably not loaded");

Should we set .needs_drivers for the test so that it only attempts to run either if TLS is compiled in or could be modprobed as a module?

Yes if it worked :-D, although I would still want to keep the above check. I tried it and noticed a number of problems.

On NixOS:

$ ./setsockopt10
tst_kconfig.c:87: TINFO: Parsing kernel config '/proc/config.gz'
tst_kernel.c:110: TWARN: expected file /lib/modules/6.5.5/modules.dep does not exist or not a file
tst_kernel.c:110: TWARN: expected file /lib/modules/6.5.5/modules.builtin does not exist or not a file
tst_test.c:1195: TCONF: tls driver not available
$ lsmod | grep tls
tls                   151552  0

We have a special switch for Android which disables the check, but it is not just Android. Granted NixOS is really wierd by desktop standards, but we have ALP and embedded systems to think about.

AFAICT the test library does not do a modprobe if the driver is missing. Some tests (e.g. zram, CAN) do that and then claim to require modprobe. This is not good, those tests do not need modprobe if the module is loaded or compiled in.

Perhaps if the check in tst_kernel fails for any reason we could just do a modprobe (or use the configured kernel usermode helper if it is set). If that fails we just carry on, like for Android. That's a seperate patch though IMO. Once we have a solution for that, this test can have needs_drivers added.

Quoted 30 lines
Quoted 30 lines
testcases/kernel/syscalls/setsockopt/setsockopt10.c new file +17 -0
+	else if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "parent: setsockopt failed");
+
+	SAFE_SETSOCKOPT(tcp1_sk, SOL_TLS, TLS_TX, &opts, sizeof(opts));
+	TST_CHECKPOINT_WAKE(1);
+
+	tst_res(TINFO, "parent: Disconnect by setting unspec address");
+	SAFE_CONNECT(tcp1_sk, &unspec_addr, sizeof(unspec_addr));
+	SAFE_BIND(tcp1_sk, (struct sockaddr *)&tcp1_addr, sizeof(tcp1_addr));
+
+	TEST(listen(tcp1_sk, 1));
+
+	if (TST_RET == -1) {
+		if (TST_ERR == EINVAL)
+			tst_res(TPASS | TTERRNO, "parent: Can't listen on disconnected TLS socket");
+		else
+ tst_res(TCONF | TTERRNO, "parent: Can't listen on disconnected TLS

socket, but the errno is not EINVAL as expected");

testcases/kernel/syscalls/setsockopt/setsockopt10.c new file +11 -0
+
+		TST_CHECKPOINT_WAKE(2);
+		goto out;
+	}
+
+	tst_res(TINFO, "parent: Can listen on disconnected TLS socket");
+	TST_CHECKPOINT_WAKE(2);
+
+	tcp2_sk = SAFE_ACCEPT(tcp1_sk, NULL, 0);
+	SAFE_CLOSE(tcp2_sk);
+
Quoted 8 lines

testcases/kernel/syscalls/setsockopt/setsockopt10.c line 171

Quoted 6 lines

+ tst_res(TINFO, "parent: Attempting double free, because we set cipher options this should result in an crash");

testcases/kernel/syscalls/setsockopt/setsockopt10.c new file +4 -0
+	SAFE_CLOSE(tcp1_sk);
+
+	TST_CHECKPOINT_WAKE(3);
+	usleep(0);

Did you forget this here?

It's supposed to give the kernel chance to propagate the taint or panic. Which stops it from printing there was no kernel taint in parallel with the kernel splat. It appears to work on my test system.

Quoted 8 lines

testcases/kernel/syscalls/setsockopt/setsockopt10.c line 176

Quoted 5 lines
testcases/kernel/syscalls/setsockopt/setsockopt10.c new file +4 -0
+	if (tst_taint_check())
+		tst_res(TFAIL, "Kernel is tainted");
+	else
+		tst_res(TCONF, "No kernel taint or crash, maybe the kernel can clone the TLS-ULP context now?");

If you set up .taint_check this is going to be redundant since we print TFAIL in the test library in that case.

In that case we can unconditionally do TCONF and it'll be overridden by fail and the resulting panic. Or it will be prevented by the panic.

Quoted 34 lines
Quoted 34 lines
testcases/kernel/syscalls/setsockopt/setsockopt10.c new file +27 -0
+out:
+	tst_reap_children();
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run,
+	.forks_child = 1,
+	.needs_checkpoints = 1,
+	.taint_check = TST_TAINT_W | TST_TAINT_D,
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_TLS",
+		NULL
+	},
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "2c02d41d71f90"},
+		{"CVE", "2023-0461"},
+		{}
+	}
+};
+
+#else
+
+TST_TEST_TCONF("linux/tls.h missing, we assume your system is too old");
+
+#endif
Signature · 5 lines
2.40.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Hi!

Quoted 6 lines
Quoted 2 lines

Should we set .needs_drivers for the test so that it only attempts to run either if TLS is compiled in or could be modprobed as a module?

Yes if it worked :-D, although I would still want to keep the above check. I tried it and noticed a number of problems.

Quoted 6 lines

On NixOS:

$ ./setsockopt10
tst_kconfig.c:87: TINFO: Parsing kernel config '/proc/config.gz'
tst_kernel.c:110: TWARN: expected file /lib/modules/6.5.5/modules.dep does not exist or not a file
tst_kernel.c:110: TWARN: expected file /lib/modules/6.5.5/modules.builtin does not exist or not a file

Can you strace modprobe to see what is different on the system, these files have to be installed somewhere in order for modprobe to actually work...

Quoted 4 lines

tst_test.c:1195: TCONF: tls driver not available

$ lsmod | grep tls
tls                   151552  0
Quoted 8 lines

We have a special switch for Android which disables the check, but it is not just Android. Granted NixOS is really wierd by desktop standards, but we have ALP and embedded systems to think about.

AFAICT the test library does not do a modprobe if the driver is missing. Some tests (e.g. zram, CAN) do that and then claim to require modprobe. This is not good, those tests do not need modprobe if the module is loaded or compiled in.

That all should be handled in the library when .need_drivers is set.

The problem is that without the modules.buildin file we cannot easily tell if things have been compiled in. If we manage to find the location of the files used by modprobe we should do something as:

1) Is foo in modules.buildin -> return to the test
2) Is foo in /proc/modules -> return to the text
3) Is foo in mdules.dep -> try modprobe foo

Quoted 5 lines

Perhaps if the check in tst_kernel fails for any reason we could just do a modprobe (or use the configured kernel usermode helper if it is set). If that fails we just carry on, like for Android. That's a seperate patch though IMO. Once we have a solution for that, this test can have needs_drivers added.

I suppose that just calling modprobe and check the return value would work as well, however that would make it hard dependency.

Quoted 38 lines
Quoted 29 lines
Quoted 29 lines
testcases/kernel/syscalls/setsockopt/setsockopt10.c new file +17 -0
+	else if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "parent: setsockopt failed");
+
+	SAFE_SETSOCKOPT(tcp1_sk, SOL_TLS, TLS_TX, &opts, sizeof(opts));
+	TST_CHECKPOINT_WAKE(1);
+
+	tst_res(TINFO, "parent: Disconnect by setting unspec address");
+	SAFE_CONNECT(tcp1_sk, &unspec_addr, sizeof(unspec_addr));
+	SAFE_BIND(tcp1_sk, (struct sockaddr *)&tcp1_addr, sizeof(tcp1_addr));
+
+	TEST(listen(tcp1_sk, 1));
+
+	if (TST_RET == -1) {
+		if (TST_ERR == EINVAL)
+			tst_res(TPASS | TTERRNO, "parent: Can't listen on disconnected TLS socket");
+		else
+ tst_res(TCONF | TTERRNO, "parent: Can't listen on disconnected TLS

socket, but the errno is not EINVAL as expected");

testcases/kernel/syscalls/setsockopt/setsockopt10.c new file +11 -0
+
+		TST_CHECKPOINT_WAKE(2);
+		goto out;
+	}
+
+	tst_res(TINFO, "parent: Can listen on disconnected TLS socket");
+	TST_CHECKPOINT_WAKE(2);
+
+	tcp2_sk = SAFE_ACCEPT(tcp1_sk, NULL, 0);
+	SAFE_CLOSE(tcp2_sk);
+
Quoted 8 lines

testcases/kernel/syscalls/setsockopt/setsockopt10.c line 171

Quoted 6 lines

+ tst_res(TINFO, "parent: Attempting double free, because we set cipher options this should result in an crash");

testcases/kernel/syscalls/setsockopt/setsockopt10.c new file +4 -0
+	SAFE_CLOSE(tcp1_sk);
+
+	TST_CHECKPOINT_WAKE(3);
+	usleep(0);

Did you forget this here?

Quoted 3 lines

It's supposed to give the kernel chance to propagate the taint or panic. Which stops it from printing there was no kernel taint in parallel with the kernel splat. It appears to work on my test system.

Right, so it's really just sched_yield(), maybe explicit sched_yield() would be more descriptive.

Quoted 10 lines
Quoted 7 lines

testcases/kernel/syscalls/setsockopt/setsockopt10.c line 176

Quoted 4 lines
testcases/kernel/syscalls/setsockopt/setsockopt10.c new file +4 -0
+	if (tst_taint_check())
+		tst_res(TFAIL, "Kernel is tainted");
+	else
+		tst_res(TCONF, "No kernel taint or crash, maybe the kernel can clone the TLS-ULP context now?");

If you set up .taint_check this is going to be redundant since we print TFAIL in the test library in that case.

In that case we can unconditionally do TCONF and it'll be overridden by fail and the resulting panic. Or it will be prevented by the panic.

I guess that we should make the message "No kernel crash, maybe ..." instead in that case.

Quoted 38 lines
Quoted 33 lines
Quoted 33 lines
testcases/kernel/syscalls/setsockopt/setsockopt10.c new file +27 -0
+out:
+	tst_reap_children();
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run,
+	.forks_child = 1,
+	.needs_checkpoints = 1,
+	.taint_check = TST_TAINT_W | TST_TAINT_D,
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_TLS",
+		NULL
+	},
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "2c02d41d71f90"},
+		{"CVE", "2023-0461"},
+		{}
+	}
+};
+
+#else
+
+TST_TEST_TCONF("linux/tls.h missing, we assume your system is too old");
+
+#endif
Signature · 5 lines
2.40.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Thank you,
Richard.
Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

Hello,

Quoted 9 lines · Cyril Hrubis

Hi!

Quoted 8 lines
Quoted 2 lines

Should we set .needs_drivers for the test so that it only attempts to run either if TLS is compiled in or could be modprobed as a module?

Yes if it worked :-D, although I would still want to keep the above check. I tried it and noticed a number of problems.

On NixOS:

Quoted 8 lines
Quoted 4 lines
$ ./setsockopt10
tst_kconfig.c:87: TINFO: Parsing kernel config '/proc/config.gz'
tst_kernel.c:110: TWARN: expected file /lib/modules/6.5.5/modules.dep does not exist or not a file
tst_kernel.c:110: TWARN: expected file /lib/modules/6.5.5/modules.builtin does not exist or not a file

Can you strace modprobe to see what is different on the system, these files have to be installed somewhere in order for modprobe to actually work...

They will be in /nix/store/<kernel package hash>/.../modules or similar. I can probably make it work on NixOS by creating a nix file, but I think there is a bigger issue.

Quoted 24 lines
Quoted 5 lines

tst_test.c:1195: TCONF: tls driver not available

$ lsmod | grep tls
tls                   151552  0
Quoted 8 lines

We have a special switch for Android which disables the check, but it is not just Android. Granted NixOS is really wierd by desktop standards, but we have ALP and embedded systems to think about.

AFAICT the test library does not do a modprobe if the driver is missing. Some tests (e.g. zram, CAN) do that and then claim to require modprobe. This is not good, those tests do not need modprobe if the module is loaded or compiled in.

That all should be handled in the library when .need_drivers is set.

The problem is that without the modules.buildin file we cannot easily tell if things have been compiled in. If we manage to find the location of the files used by modprobe we should do something as:

1) Is foo in modules.buildin -> return to the test
2) Is foo in /proc/modules -> return to the text
3) Is foo in mdules.dep -> try modprobe foo

Quoted 8 lines
Quoted 5 lines

Perhaps if the check in tst_kernel fails for any reason we could just do a modprobe (or use the configured kernel usermode helper if it is set). If that fails we just carry on, like for Android. That's a seperate patch though IMO. Once we have a solution for that, this test can have needs_drivers added.

I suppose that just calling modprobe and check the return value would work as well, however that would make it hard dependency.

IMO it should only be best efforts. If the system doesn't have these files or modprobe, or it is running in a sandbox, then we should just try to run the test. In the worst case it fails with TBROK, but we won't block testing unecessarily.

If the test doesn't require any unecessary privileges or resources then it can be used to see if a bug is reachable from a container or on some embedded system.

I suppose that it could fail by default and the checks could be disabled with an env var.

Quoted 98 lines
Quoted 39 lines
Quoted 30 lines
Quoted 30 lines
testcases/kernel/syscalls/setsockopt/setsockopt10.c new file +17 -0
+	else if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "parent: setsockopt failed");
+
+	SAFE_SETSOCKOPT(tcp1_sk, SOL_TLS, TLS_TX, &opts, sizeof(opts));
+	TST_CHECKPOINT_WAKE(1);
+
+	tst_res(TINFO, "parent: Disconnect by setting unspec address");
+	SAFE_CONNECT(tcp1_sk, &unspec_addr, sizeof(unspec_addr));
+	SAFE_BIND(tcp1_sk, (struct sockaddr *)&tcp1_addr, sizeof(tcp1_addr));
+
+	TEST(listen(tcp1_sk, 1));
+
+	if (TST_RET == -1) {
+		if (TST_ERR == EINVAL)
+			tst_res(TPASS | TTERRNO, "parent: Can't listen on disconnected TLS socket");
+		else
+ tst_res(TCONF | TTERRNO, "parent: Can't listen on disconnected TLS

socket, but the errno is not EINVAL as expected");

testcases/kernel/syscalls/setsockopt/setsockopt10.c new file +11 -0
+
+		TST_CHECKPOINT_WAKE(2);
+		goto out;
+	}
+
+	tst_res(TINFO, "parent: Can listen on disconnected TLS socket");
+	TST_CHECKPOINT_WAKE(2);
+
+	tcp2_sk = SAFE_ACCEPT(tcp1_sk, NULL, 0);
+	SAFE_CLOSE(tcp2_sk);
+
Quoted 8 lines

testcases/kernel/syscalls/setsockopt/setsockopt10.c line 171

Quoted 6 lines

+ tst_res(TINFO, "parent: Attempting double free, because we set cipher options this should result in an crash");

testcases/kernel/syscalls/setsockopt/setsockopt10.c new file +4 -0
+	SAFE_CLOSE(tcp1_sk);
+
+	TST_CHECKPOINT_WAKE(3);
+	usleep(0);

Did you forget this here?

Quoted 3 lines

It's supposed to give the kernel chance to propagate the taint or panic. Which stops it from printing there was no kernel taint in parallel with the kernel splat. It appears to work on my test system.

Right, so it's really just sched_yield(), maybe explicit sched_yield() would be more descriptive.

Quoted 10 lines
Quoted 7 lines

testcases/kernel/syscalls/setsockopt/setsockopt10.c line 176

Quoted 4 lines
testcases/kernel/syscalls/setsockopt/setsockopt10.c new file +4 -0
+	if (tst_taint_check())
+		tst_res(TFAIL, "Kernel is tainted");
+	else
+		tst_res(TCONF, "No kernel taint or crash, maybe the kernel can clone the TLS-ULP context now?");

If you set up .taint_check this is going to be redundant since we print TFAIL in the test library in that case.

In that case we can unconditionally do TCONF and it'll be overridden by fail and the resulting panic. Or it will be prevented by the panic.

I guess that we should make the message "No kernel crash, maybe ..." instead in that case.

Quoted 38 lines
Quoted 33 lines
Quoted 33 lines
testcases/kernel/syscalls/setsockopt/setsockopt10.c new file +27 -0
+out:
+	tst_reap_children();
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run,
+	.forks_child = 1,
+	.needs_checkpoints = 1,
+	.taint_check = TST_TAINT_W | TST_TAINT_D,
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_TLS",
+		NULL
+	},
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "2c02d41d71f90"},
+		{"CVE", "2023-0461"},
+		{}
+	}
+};
+
+#else
+
+TST_TEST_TCONF("linux/tls.h missing, we assume your system is too old");
+
+#endif
Signature · 5 lines
2.40.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Thank you,
Richard.
Signature · 5 lines
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw

Hi Richie, Cyril,

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

On NixOS:

$ ./setsockopt10
tst_kconfig.c:87: TINFO: Parsing kernel config '/proc/config.gz'
tst_kernel.c:110: TWARN: expected file /lib/modules/6.5.5/modules.dep does not exist or not a file
tst_kernel.c:110: TWARN: expected file /lib/modules/6.5.5/modules.builtin does not exist or not a file

For my info: this comes from Cyrils suggestion to use .needs_drivers.

Quoted 7 lines
Quoted 3 lines

Can you strace modprobe to see what is different on the system, these files have to be installed somewhere in order for modprobe to actually work...

They will be in /nix/store/<kernel package hash>/.../modules or similar. I can probably make it work on NixOS by creating a nix file, but I think there is a bigger issue.

"NixOS is a Linux distribution built on top of the Nix package manager." [1]

I have no idea why Linux distro needs non-standard patch. IMHO we can take patch which detects NixOS and use it's path, but for the distro itself would be better if it has at least symlink to the standard path (i.e. it'd be worth to report it).

As Cyril noted we have .needs_drivers, but that's also require config files in /lib/modules. But setsockopt10 could also benefit from .modprobe patchset [2], particularly [3]. i.e. instead of asking for CONFIG_TLS "modprobe tls" could work. But currently we also expect modules.builtin is in /lib/modules. We could rethink that (e.g. introduce variable which ignores the check, or allows to pass path the correct prefix of the directory or remove tst_check_builtin_driver(name), which is based on parsing modules.builtin).

But for broader discussion please comment on the patchset itself.

And now something completely different: root vs. normal user:

$ find /lib/modules/$(uname -r) |grep tls
...
/lib/modules/6.5.0-1-amd64/kernel/net/tls/tls.ko

But this does not work, when run as user:

$ ./setsockopt10
...
setsockopt10.c:96: TINFO: child: Listen for tcp1 connection
setsockopt10.c:133: TINFO: parent: Connect for tcp0 connection
setsockopt10.c:138: TCONF: parent: setsockopt failed: The TLS module is probably not loaded: ENOENT (2)
tst_test.c:1622: TINFO: Killed the leftover descendant processes

Maybe that has been discussed, but I'd really request the root, because it works with it:

# ./setsockopt10
...
setsockopt10.c:145: TINFO: parent: Disconnect by setting unspec address
setsockopt10.c:153: TPASS: parent: Can't listen on disconnected TLS socket: EINVAL (22)
setsockopt10.c:110: TINFO: child: connect for tcp2 connection
setsockopt10.c:114: TINFO: child: could not connect to tcp1: ECONNREFUSED (111)

Kind regards,
Petr

[1] https://en.wikipedia.org/wiki/NixOS
[2] https://patchwork.ozlabs.org/project/ltp/list/?series=377451&state=*
[3] https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw

Hello,

Quoted 19 lines · Petr Vorel

Hi Richie, Cyril,

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

On NixOS:

$ ./setsockopt10
tst_kconfig.c:87: TINFO: Parsing kernel config '/proc/config.gz'
tst_kernel.c:110: TWARN: expected file /lib/modules/6.5.5/modules.dep does not exist or not a file
tst_kernel.c:110: TWARN: expected file /lib/modules/6.5.5/modules.builtin does not exist or not a file

For my info: this comes from Cyrils suggestion to use .needs_drivers.

Quoted 7 lines
Quoted 3 lines

Can you strace modprobe to see what is different on the system, these files have to be installed somewhere in order for modprobe to actually work...

They will be in /nix/store/<kernel package hash>/.../modules or similar. I can probably make it work on NixOS by creating a nix file, but I think there is a bigger issue.

Quoted 6 lines

"NixOS is a Linux distribution built on top of the Nix package manager." [1]

I have no idea why Linux distro needs non-standard patch. IMHO we can take patch which detects NixOS and use it's path, but for the distro itself would be better if it has at least symlink to the standard path (i.e. it'd be worth to report it).

Only if you can point to a specification and NixOS accepts that spec. If it is not in POSIX then it is unlikely to get through. There is not even a /lib in NixOS. Any absolute paths interfere with reproducibility, isolation and such. To see how such a discussion is likey to go see this thread on /bin/bash:
https://discourse.nixos.org/t/add-bin-bash-to-avoid-unnecessary-pain/5673

OTOH all we need is a Nix file which creates the symlinks (or patches LTP) and specifies the LTPs deps to create a reproducible build of LTP in Nix. At some point I'll add it to CI.

However this doesn't help other distro's or embedded systems that we don't personally use.

Quoted 24 lines

As Cyril noted we have .needs_drivers, but that's also require config files in /lib/modules. But setsockopt10 could also benefit from .modprobe patchset [2], particularly [3]. i.e. instead of asking for CONFIG_TLS "modprobe tls" could work. But currently we also expect modules.builtin is in /lib/modules. We could rethink that (e.g. introduce variable which ignores the check, or allows to pass path the correct prefix of the directory or remove tst_check_builtin_driver(name), which is based on parsing modules.builtin).

But for broader discussion please comment on the patchset itself.

And now something completely different: root vs. normal user:

$ find /lib/modules/$(uname -r) |grep tls
...
/lib/modules/6.5.0-1-amd64/kernel/net/tls/tls.ko

But this does not work, when run as user:

$ ./setsockopt10
...
setsockopt10.c:96: TINFO: child: Listen for tcp1 connection
setsockopt10.c:133: TINFO: parent: Connect for tcp0 connection
setsockopt10.c:138: TCONF: parent: setsockopt failed: The TLS module is probably not loaded: ENOENT (2)
tst_test.c:1622: TINFO: Killed the leftover descendant processes
Quoted 2 lines

Maybe that has been discussed, but I'd really request the root, because it works with it:

Yes, I did say why I don't want to require root in the previous message. However I'll take this to the patchset thread you posted.

Quoted 14 lines
# ./setsockopt10
...
setsockopt10.c:145: TINFO: parent: Disconnect by setting unspec address
setsockopt10.c:153: TPASS: parent: Can't listen on disconnected TLS socket: EINVAL (22)
setsockopt10.c:110: TINFO: child: connect for tcp2 connection
setsockopt10.c:114: TINFO: child: could not connect to tcp1: ECONNREFUSED (111)

Kind regards,
Petr

[1] https://en.wikipedia.org/wiki/NixOS
[2] https://patchwork.ozlabs.org/project/ltp/list/?series=377451&state=*
[3] https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/

Signature · 5 lines
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#7 lore raw

Hi Richie,

Quoted 30 lines

Hello,

Quoted 19 lines · Petr Vorel

Hi Richie, Cyril,

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

On NixOS:

$ ./setsockopt10
tst_kconfig.c:87: TINFO: Parsing kernel config '/proc/config.gz'
tst_kernel.c:110: TWARN: expected file /lib/modules/6.5.5/modules.dep does not exist or not a file
tst_kernel.c:110: TWARN: expected file /lib/modules/6.5.5/modules.builtin does not exist or not a file

For my info: this comes from Cyrils suggestion to use .needs_drivers.

Quoted 7 lines
Quoted 3 lines

Can you strace modprobe to see what is different on the system, these files have to be installed somewhere in order for modprobe to actually work...

They will be in /nix/store/<kernel package hash>/.../modules or similar. I can probably make it work on NixOS by creating a nix file, but I think there is a bigger issue.

Quoted 6 lines

"NixOS is a Linux distribution built on top of the Nix package manager." [1]

I have no idea why Linux distro needs non-standard patch. IMHO we can take patch which detects NixOS and use it's path, but for the distro itself would be better if it has at least symlink to the standard path (i.e. it'd be worth to report it).

Quoted 6 lines

Only if you can point to a specification and NixOS accepts that spec. If it is not in POSIX then it is unlikely to get through. There is not even a /lib in NixOS. Any absolute paths interfere with reproducibility, isolation and such. To see how such a discussion is likey to go see this thread on /bin/bash:
https://discourse.nixos.org/t/add-bin-bash-to-avoid-unnecessary-pain/5673

Lol, missing /bin/bash, that's serious, at least they have /bin/sh :).

Quoted 3 lines

OTOH all we need is a Nix file which creates the symlinks (or patches LTP) and specifies the LTPs deps to create a reproducible build of LTP in Nix. At some point I'll add it to CI.

I'm open to any solution - different path for NixOS or environment variable, which could be used for NixOS (and maybe hopefully for other use case). Please send a patch, whatever looks best to you.

Quoted 27 lines

However this doesn't help other distro's or embedded systems that we don't personally use.

Quoted 22 lines

As Cyril noted we have .needs_drivers, but that's also require config files in /lib/modules. But setsockopt10 could also benefit from .modprobe patchset [2], particularly [3]. i.e. instead of asking for CONFIG_TLS "modprobe tls" could work. But currently we also expect modules.builtin is in /lib/modules. We could rethink that (e.g. introduce variable which ignores the check, or allows to pass path the correct prefix of the directory or remove tst_check_builtin_driver(name), which is based on parsing modules.builtin).

But for broader discussion please comment on the patchset itself.

And now something completely different: root vs. normal user:

$ find /lib/modules/$(uname -r) |grep tls
...
/lib/modules/6.5.0-1-amd64/kernel/net/tls/tls.ko

But this does not work, when run as user:

$ ./setsockopt10
...
setsockopt10.c:96: TINFO: child: Listen for tcp1 connection
setsockopt10.c:133: TINFO: parent: Connect for tcp0 connection
setsockopt10.c:138: TCONF: parent: setsockopt failed: The TLS module is probably not loaded: ENOENT (2)
tst_test.c:1622: TINFO: Killed the leftover descendant processes
Quoted 5 lines
Quoted 2 lines

Maybe that has been discussed, but I'd really request the root, because it works with it:

Yes, I did say why I don't want to require root in the previous message. However I'll take this to the patchset thread you posted.

Ah right, thanks for info. +1 for keeping the discussion there.

Kind regards,
Petr

Quoted 13 lines
Quoted 13 lines
# ./setsockopt10
...
setsockopt10.c:145: TINFO: parent: Disconnect by setting unspec address
setsockopt10.c:153: TPASS: parent: Can't listen on disconnected TLS socket: EINVAL (22)
setsockopt10.c:110: TINFO: child: connect for tcp2 connection
setsockopt10.c:114: TINFO: child: could not connect to tcp1: ECONNREFUSED (111)

Kind regards,
Petr

[1] https://en.wikipedia.org/wiki/NixOS
[2] https://patchwork.ozlabs.org/project/ltp/list/?series=377451&state=*
[3] https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp