lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220210003649.3120861-9-kuba@kernel.org>
Date:   Wed,  9 Feb 2022 16:36:46 -0800
From:   Jakub Kicinski <kuba@...nel.org>
To:     davem@...emloft.net
Cc:     netdev@...r.kernel.org, willemb@...gle.com, lorenzo@...gle.com,
        maze@...gle.com, dsahern@...nel.org, yoshfuji@...ux-ipv6.org,
        shuah@...nel.org, linux-kselftest@...r.kernel.org,
        Jakub Kicinski <kuba@...nel.org>
Subject: [PATCH net-next 08/11] selftests: net: cmsg_so_mark: test with SO_MARK set by setsockopt

Test if setting SO_MARK with setsockopt works and if cmsg
takes precedence over it.

Signed-off-by: Jakub Kicinski <kuba@...nel.org>
---
 tools/testing/selftests/net/cmsg_sender.c   | 14 ++++++++++-
 tools/testing/selftests/net/cmsg_so_mark.sh | 28 +++++++++++++--------
 2 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/tools/testing/selftests/net/cmsg_sender.c b/tools/testing/selftests/net/cmsg_sender.c
index edb8c427c7cb..c7586a4b0361 100644
--- a/tools/testing/selftests/net/cmsg_sender.c
+++ b/tools/testing/selftests/net/cmsg_sender.c
@@ -29,6 +29,9 @@ struct options {
 	bool silent_send;
 	const char *host;
 	const char *service;
+	struct {
+		unsigned int mark;
+	} sockopt;
 	struct {
 		unsigned int family;
 		unsigned int type;
@@ -56,6 +59,7 @@ static void __attribute__((noreturn)) cs_usage(const char *bin)
 	       "\t\t        (u = UDP (default); i = ICMP; r = RAW)\n"
 	       "\n"
 	       "\t\t-m val  Set SO_MARK with given value\n"
+	       "\t\t-M val  Set SO_MARK via setsockopt\n"
 	       "");
 	exit(ERN_HELP);
 }
@@ -64,7 +68,7 @@ static void cs_parse_args(int argc, char *argv[])
 {
 	char o;
 
-	while ((o = getopt(argc, argv, "46sp:m:")) != -1) {
+	while ((o = getopt(argc, argv, "46sp:m:M:")) != -1) {
 		switch (o) {
 		case 's':
 			opt.silent_send = true;
@@ -91,6 +95,9 @@ static void cs_parse_args(int argc, char *argv[])
 			opt.mark.ena = true;
 			opt.mark.val = atoi(optarg);
 			break;
+		case 'M':
+			opt.sockopt.mark = atoi(optarg);
+			break;
 		}
 	}
 
@@ -175,6 +182,11 @@ int main(int argc, char *argv[])
 		sin6->sin6_port = htons(opt.sock.proto);
 	}
 
+	if (opt.sockopt.mark &&
+	    setsockopt(fd, SOL_SOCKET, SO_MARK,
+		       &opt.sockopt.mark, sizeof(opt.sockopt.mark)))
+		error(ERN_SOCKOPT, errno, "setsockopt SO_MARK");
+
 	iov[0].iov_base = buf;
 	iov[0].iov_len = sizeof(buf);
 
diff --git a/tools/testing/selftests/net/cmsg_so_mark.sh b/tools/testing/selftests/net/cmsg_so_mark.sh
index 925f6b9deee2..1650b8622f2f 100755
--- a/tools/testing/selftests/net/cmsg_so_mark.sh
+++ b/tools/testing/selftests/net/cmsg_so_mark.sh
@@ -43,19 +43,27 @@ check_result() {
     fi
 }
 
-for i in 4 6; do
-    [ $i == 4 ] && TGT=$TGT4 || TGT=$TGT6
+for ovr in setsock cmsg both; do
+    for i in 4 6; do
+	[ $i == 4 ] && TGT=$TGT4 || TGT=$TGT6
 
-    for p in u i r; do
-	[ $p == "u" ] && prot=UDP
-	[ $p == "i" ] && prot=ICMP
-	[ $p == "r" ] && prot=RAW
+	for p in u i r; do
+	    [ $p == "u" ] && prot=UDP
+	    [ $p == "i" ] && prot=ICMP
+	    [ $p == "r" ] && prot=RAW
 
-	ip netns exec $NS ./cmsg_sender -$i -p $p -m $((MARK + 1)) $TGT 1234
-	check_result $? 0 "$prot pass"
+	    [ $ovr == "setsock" ] && m="-M"
+	    [ $ovr == "cmsg" ]    && m="-m"
+	    [ $ovr == "both" ]    && m="-M $MARK -m"
 
-	ip netns exec $NS ./cmsg_sender -$i -p $p -m $MARK -s $TGT 1234
-	check_result $? 1 "$prot rejection"
+	    ip netns exec $NS ./cmsg_sender -$i -p $p $m $((MARK + 1)) $TGT 1234
+	    check_result $? 0 "$prot $ovr - pass"
+
+	    [ $ovr == "diff" ] && m="-M $((MARK + 1)) -m"
+
+	    ip netns exec $NS ./cmsg_sender -$i -p $p $m $MARK -s $TGT 1234
+	    check_result $? 1 "$prot $ovr - rejection"
+	done
     done
 done
 
-- 
2.34.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ