Skip to contentSkip to conversation

tcindex01: Simplify test

PATCH In review Martin Doucha 2 participants 2 messages Sep 12, 2023 – Sep 13, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tcindex01: Simplify test

The bug can be reproduced simply by adding, removing and adding again the same tcindex traffic filter. If the bug is present, the attempt to add the removed filter again will fail with EEXIST error.

---

This change makes the test much faster by removing usleep() call and also allows reliably reproducing the bug on kernels v4.x.

 testcases/cve/tcindex01.c | 37 ++++++++++++-------------------------
 1 file changed, 12 insertions(+), 25 deletions(-)
testcases/cve/tcindex01.c +12 -25
index 9bd7de9dd..eb1f01109 100644
@@ -84,31 +84,18 @@ static void setup(void)
 
 static void run(void)
 {
-	unsigned int i;
-
-	for (i = 0; i < 100; i++) {
-		NETDEV_ADD_QDISC(DEVNAME, AF_UNSPEC, TC_H_ROOT, qd_handle,
-			"htb", qd_config);
-		NETDEV_ADD_TRAFFIC_CLASS(DEVNAME, qd_handle, clsid, "htb",
-			cls_config);
-		NETDEV_ADD_TRAFFIC_FILTER(DEVNAME, qd_handle, 10, ETH_P_IP, 1,
-			"tcindex", f_config);
-		NETDEV_REMOVE_TRAFFIC_FILTER(DEVNAME, qd_handle, 10, ETH_P_IP,
-			1, "tcindex");
-
-		/* Wait at least one jiffy for use-after-free */
-		usleep(10000);
-
-		NETDEV_REMOVE_QDISC(DEVNAME, AF_UNSPEC, TC_H_ROOT, qd_handle,
-			"htb");
-	}
-
-	if (tst_taint_check()) {
-		tst_res(TFAIL, "Kernel is vulnerable");
-		return;
-	}
-
-	tst_res(TPASS, "Nothing bad happened (yet)");
+	NETDEV_ADD_QDISC(DEVNAME, AF_UNSPEC, TC_H_ROOT, qd_handle, "htb",
+		qd_config);
+	NETDEV_ADD_TRAFFIC_CLASS(DEVNAME, qd_handle, clsid, "htb", cls_config);
+	NETDEV_ADD_TRAFFIC_FILTER(DEVNAME, qd_handle, 10, ETH_P_IP, 1,
+		"tcindex", f_config);
+	NETDEV_REMOVE_TRAFFIC_FILTER(DEVNAME, qd_handle, 10, ETH_P_IP,
+		1, "tcindex");
+	tst_res(TINFO, "Trying to add removed tcindex filter again...");
+	NETDEV_ADD_TRAFFIC_FILTER(DEVNAME, qd_handle, 10, ETH_P_IP, 1,
+		"tcindex", f_config);
+	NETDEV_REMOVE_QDISC(DEVNAME, AF_UNSPEC, TC_H_ROOT, qd_handle, "htb");
+	tst_res(TPASS, "Removing tcindex filter works correctly");
 }
 
 static void cleanup(void)
Signature · 5 lines
2.41.0


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

Hi!

testcases/cve/tcindex01.c static void setup(void) · line 96

Quoted 10 lines
testcases/cve/tcindex01.c +10 -0
+	NETDEV_ADD_QDISC(DEVNAME, AF_UNSPEC, TC_H_ROOT, qd_handle, "htb",
+		qd_config);
+	NETDEV_ADD_TRAFFIC_CLASS(DEVNAME, qd_handle, clsid, "htb", cls_config);
+	NETDEV_ADD_TRAFFIC_FILTER(DEVNAME, qd_handle, 10, ETH_P_IP, 1,
+		"tcindex", f_config);
+	NETDEV_REMOVE_TRAFFIC_FILTER(DEVNAME, qd_handle, 10, ETH_P_IP,
+		1, "tcindex");
+	tst_res(TINFO, "Trying to add removed tcindex filter again...");
+	NETDEV_ADD_TRAFFIC_FILTER(DEVNAME, qd_handle, 10, ETH_P_IP, 1,
+		"tcindex", f_config);

I suppose that this will now produce TBROK in case of vunerable kernel?

I wonder if we can turn that somehow into TFAIL instead so that it's clear that the kernel is vunerable and that this isn't broken test.

Maybe we can pass down a flag to modify_qdisc() that would use tst_res_(TFAIL, ...) in a case that the send_validate() has failed, pass it down as disabled in all the current macros and create NETDEV_TEST_ADD_TRAFIC_FITLER() that would pass the flag enabled.

Quoted 11 lines
testcases/cve/tcindex01.c +2 -0
+	NETDEV_REMOVE_QDISC(DEVNAME, AF_UNSPEC, TC_H_ROOT, qd_handle, "htb");
+	tst_res(TPASS, "Removing tcindex filter works correctly");
 }
 
 static void cleanup(void)
Signature · 5 lines
2.41.0


-- 
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