From: Allison Henderson Date: Mon, 4 May 2026 05:41:39 +0000 (-0700) Subject: selftests: rds: Add SUDO_USER env variable X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=d601239dcc268fa5b9217e379bd5bb02100a55e3;p=thirdparty%2Flinux.git selftests: rds: Add SUDO_USER env variable This patch modifies rds selftests to use the environment variable SUDO_USER for tcpdumps if it is set. This is needed to avoid chown operations on the vng 9pfs which is not supported. Passing a user listed in sudoers avoids the tcpdump privilege drop which may otherwise create empty pcaps Signed-off-by: Allison Henderson Link: https://patch.msgid.link/20260504054143.4027538-7-achender@kernel.org Signed-off-by: Jakub Kicinski --- diff --git a/tools/testing/selftests/net/rds/README.txt b/tools/testing/selftests/net/rds/README.txt index e629e08f04ef..295dc82c0770 100644 --- a/tools/testing/selftests/net/rds/README.txt +++ b/tools/testing/selftests/net/rds/README.txt @@ -37,6 +37,12 @@ ENV VARIABLES: the specified --rwdir path for logs to persist on the host. + SUDO_USER The user name that should be used for tcpdump + --relinquish-privileges. Set this to a user + belonging to the sudoers group to avoid drop + privilege errors with the vng 9p filesystem + which may result in empty pcaps + EXAMPLE: # Create a suitable gcov enabled .config @@ -54,6 +60,7 @@ EXAMPLE: # launch the tests in a VM vng -v --rwdir ./ --run . --user root --cpus 4 -- \ "export PYTHONPATH=tools/testing/selftests/net/; \ + export SUDO_USER=example_user; \ export RDS_LOG_DIR=tools/testing/selftests/net/rds/rds_logs; \ tools/testing/selftests/net/rds/run.sh" diff --git a/tools/testing/selftests/net/rds/test.py b/tools/testing/selftests/net/rds/test.py index 0ece8324d255..7a3616ac288f 100755 --- a/tools/testing/selftests/net/rds/test.py +++ b/tools/testing/selftests/net/rds/test.py @@ -134,10 +134,15 @@ if logdir is not None: for net in [NET0, NET1]: pcap = logdir+'/'+net+'.pcap' fd, pcap_tmp = tempfile.mkstemp(suffix=".pcap", prefix=f"{net}-", dir="/tmp") + + tcpdump_cmd = ['ip', 'netns', 'exec', net, '/usr/sbin/tcpdump'] + sudo_user = os.environ.get('SUDO_USER') + if sudo_user: + tcpdump_cmd.extend(['-Z', sudo_user]) + tcpdump_cmd.extend(['-i', 'any', '-w', pcap_tmp]) + # pylint: disable-next=consider-using-with - p = subprocess.Popen( - ['ip', 'netns', 'exec', net, - '/usr/sbin/tcpdump', '-i', 'any', '-w', pcap_tmp]) + p = subprocess.Popen(tcpdump_cmd) tcpdump_procs.append((p, pcap_tmp, pcap, fd)) # simulate packet loss, duplication and corruption