• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0-or-later
3# Copyright (c) Köry Maincent <kory.maincent@bootlin.com> 2020
4# Copyright (c) 2015 Red Hat, Inc.
5#
6# Tests that a separate network namespace cannot affect sysfs contents
7# of the main namespace.
8
9TST_NEEDS_DRIVERS="dummy"
10TST_CLEANUP=do_cleanup
11TST_SETUP=do_setup
12TST_TESTFUNC=do_test
13TST_NEEDS_TMPDIR=1
14. tst_test.sh
15
16do_setup()
17{
18	NS_TYPE="net,mnt"
19	DUMMYDEV_HOST="dummy_test0"
20	DUMMYDEV="dummy_test1"
21
22	if tst_kvcmp -lt "2.6.35"; then
23		tst_brk TCONF "sysfs is not mount namespace aware for kernels older than 2.6.35"
24	fi
25
26	setns_check
27	if [ $? -eq 32 ]; then
28		tst_brk TCONF "setns not supported"
29	fi
30
31	NS_HANDLE=$(ns_create $NS_TYPE)
32	if [ $? -eq 1 ]; then
33		tst_res TINFO "$NS_HANDLE"
34		tst_brk TBROK "unable to create a new network namespace"
35	fi
36
37	ip link add $DUMMYDEV_HOST type dummy || \
38		tst_brk TBROK "failed to add a new (host) dummy device"
39
40	ns_exec $NS_HANDLE $NS_TYPE mount --make-rprivate /sys
41	ns_exec $NS_HANDLE $NS_TYPE ip link add $DUMMYDEV type dummy || \
42		tst_brk TBROK "failed to add a new dummy device"
43	ns_exec $NS_HANDLE $NS_TYPE mount -t sysfs none /sys 2>/dev/null
44}
45
46do_cleanup()
47{
48	ip link del $DUMMYDEV_HOST 2>/dev/null
49	ip link del $DUMMYDEV 2>/dev/null
50	kill -9 $NS_HANDLE 2>/dev/null
51}
52
53
54do_test()
55{
56	EXPECT_PASS ns_exec $NS_HANDLE $NS_TYPE test -e /sys/class/net/$DUMMYDEV
57	EXPECT_FAIL ns_exec $NS_HANDLE $NS_TYPE test -e /sys/class/net/$DUMMYDEV_HOST
58	EXPECT_FAIL test -e /sys/class/net/$DUMMYDEV
59}
60
61tst_run
62