Re: [PATCHv2 net] selftests: netfilter: Pass the family parameter to conntrack tool

2021-01-05 Thread Hangbin Liu
On Tue, Jan 05, 2021 at 05:43:16PM +0800, Yi Chen wrote:
> From: yiche 
> 
> Fixes: 619ae8e0697a6 ("selftests: netfilter: add test case for conntrack 
> helper assignment")
> 
> Fix nft_conntrack_helper.sh fake fail:
> conntrack tool need "-f ipv6" parameter to show out ipv6 traffic items.
> sleep 1 second after background nc send packet, to make sure check
> is after this statement executed.

The Fixes tag should be above your signoff tag

Fixes: 619ae8e0697a6 ("selftests: netfilter: add test case for conntrack helper 
assignment")
> Signed-off-by: yiche 
> ---
>  .../selftests/netfilter/nft_conntrack_helper.sh  | 12 +---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/testing/selftests/netfilter/nft_conntrack_helper.sh 
> b/tools/testing/selftests/netfilter/nft_conntrack_helper.sh
> index edf0a48da6bf..bf6b9626c7dd 100755
> --- a/tools/testing/selftests/netfilter/nft_conntrack_helper.sh
> +++ b/tools/testing/selftests/netfilter/nft_conntrack_helper.sh
> @@ -94,7 +94,13 @@ check_for_helper()
>   local message=$2
>   local port=$3
>  
> - ip netns exec ${netns} conntrack -L -p tcp --dport $port 2> /dev/null 
> |grep -q 'helper=ftp'
> + if echo $message |grep -q 'ipv6';then
> + local family="ipv6"
> + else
> + local family="ipv4"
> + fi
> +
> + ip netns exec ${netns} conntrack -L -f $family -p tcp --dport $port 2> 
> /dev/null |grep -q 'helper=ftp'
>   if [ $? -ne 0 ] ; then
>   echo "FAIL: ${netns} did not show attached helper $message" 1>&2
>   ret=1
> @@ -111,8 +117,8 @@ test_helper()
>  
>   sleep 3 | ip netns exec ${ns2} nc -w 2 -l -p $port > /dev/null &
>  
> - sleep 1
>   sleep 1 | ip netns exec ${ns1} nc -w 2 10.0.1.2 $port > /dev/null &
> + sleep 1
>  
>   check_for_helper "$ns1" "ip $msg" $port
>   check_for_helper "$ns2" "ip $msg" $port
> @@ -128,8 +134,8 @@ test_helper()
>  
>   sleep 3 | ip netns exec ${ns2} nc -w 2 -6 -l -p $port > /dev/null &
>  
> - sleep 1
>   sleep 1 | ip netns exec ${ns1} nc -w 2 -6 dead:1::2 $port > /dev/null &
> + sleep 1
>  
>   check_for_helper "$ns1" "ipv6 $msg" $port
>   check_for_helper "$ns2" "ipv6 $msg" $port
> -- 
> 2.26.2
> 


Re: [PATCH v2 0/3] Extract run_kselftest.sh and generate stand-alone test list

2020-09-28 Thread Hangbin Liu
On Mon, Sep 28, 2020 at 01:26:47PM -0700, Kees Cook wrote:
> v2:
> - update documentation
> - include SPDX line in extracted script
> v1: 
> https://lore.kernel.org/linux-kselftest/20200925234527.1885234-1-keesc...@chromium.org/
> 

I'm not sure if the doc update are all appropriate. Need others help review.
The script part looks good to me. Thanks for your update.

Regards
Hangbin


Re: [PATCHv5 kselftest next] selftests/run_kselftest.sh: make each test individually selectable

2020-09-28 Thread Hangbin Liu
On Mon, Sep 28, 2020 at 01:06:15PM -0700, Kees Cook wrote:
> > I'm really sorry to make this trouble. And I'm OK to revert the patch.
> > I just a little wondering how do you generate this script.
> 
> This issue is with which shell is used. I suspect your /bin/sh is full
> /bin/bash, where as Naresh's, the CI's, and mine are /bin/dash (which
> lacks "-e" support for the built-in "echo").

Ah, got it. Thanks for your explanation.

Regards
Hangbin


Re: [PATCH 2/2] selftests/run_kselftest.sh: Make each test individually selectable

2020-09-26 Thread Hangbin Liu
On Fri, Sep 25, 2020 at 04:45:27PM -0700, Kees Cook wrote:
> Currently with run_kselftest.sh there is no way to choose which test
> we could run. All the tests listed in kselftest-list.txt are all run
> every time. This patch enhanced the run_kselftest.sh to make the test
> collections (or tests) individually selectable. e.g.:
> 
> $ ./run_kselftest.sh -c seccomp -t timers:posix_timers -t timers:nanosleep
> 
> Additionally adds a way to list all known tests with "-l", usage
> with "-h", and perform a dry run without running tests with "-n".

This is better than my previous patch and we can modify run_kselftest.sh
easily. The Documentation/dev-tools/kselftest.rst should also be update.

Thanks
Hangbin


Re: [PATCHv5 kselftest next] selftests/run_kselftest.sh: make each test individually selectable

2020-09-26 Thread Hangbin Liu
On Fri, Sep 25, 2020 at 02:16:14PM -0700, Kees Cook wrote:
> On Fri, Sep 25, 2020 at 01:51:53PM +0530, Naresh Kamboju wrote:
> > On Mon, 14 Sep 2020 at 07:53, Hangbin Liu  wrote:
> > >
> > > Currently, after generating run_kselftest.sh, there is no way to choose
> > > which test we could run. All the tests are listed together and we have
> > > to run all every time. This patch enhanced the run_kselftest.sh to make
> > > the tests individually selectable. e.g.
> > >
> > >   $ ./run_kselftest.sh -t "bpf size timers"
> > 
> > My test run break on linux next
> > 
> > ./run_kselftest.sh: line 1331: syntax error near unexpected token `)'
> > ./run_kselftest.sh: line 1331: `-e -s | --summary )
> > logfile=$BASE_DIR/output.log; cat /dev/null > $logfile; shift ;;'
> 
> Yes, please revert this patch. The resulting script is completely
> trashed:
> 
> BASE_DIR=$(realpath $(dirname $0))
> . ./kselftest/runner.sh
> TESTS="seccomp"
> 
> run_seccomp()
> {
> -e  [ -w /dev/kmsg ] && echo "kselftest: Running tests in seccomp" >> 
> /dev/kmsg
> -e  cd seccomp
> -en run_many
> \
> -ne "seccomp_bpf"
> \
> -ne "seccomp_benchmark"
> 
> -e  cd $ROOT
> }

I'm really sorry to make this trouble. And I'm OK to revert the patch.
I just a little wondering how do you generate this script.
I tested with 'make -C tools/testing/selftests gen_tar FORMAT=.xz' before
post the patch and all looks good to me.

```

run_seccomp()
{
[ -w /dev/kmsg ] && echo "kselftest: Running tests in seccomp" >> 
/dev/kmsg
cd seccomp
run_many\
"seccomp_bpf"   \
"seccomp_benchmark"
cd $ROOT
}

```

Thanks
Hangbin


[PATCHv5 kselftest next] selftests/run_kselftest.sh: make each test individually selectable

2020-09-13 Thread Hangbin Liu
Currently, after generating run_kselftest.sh, there is no way to choose
which test we could run. All the tests are listed together and we have
to run all every time. This patch enhanced the run_kselftest.sh to make
the tests individually selectable. e.g.

  $ ./run_kselftest.sh -t "bpf size timers"

Before the patch:


$ cat run_kselftest.sh
\#!/bin/sh
BASE_DIR=$(realpath $(dirname $0))
cd $BASE_DIR
. ./kselftest/runner.sh
ROOT=$PWD
if [ "$1" = "--summary" ]; then
  logfile=$BASE_DIR/output.log
  cat /dev/null > $logfile
fi
[ -w /dev/kmsg ] && echo "kselftest: Running tests in android" >> /dev/kmsg
cd android
run_many\
"run.sh"
cd $ROOT
..
[ -w /dev/kmsg ] && echo "kselftest: Running tests in zram" >> /dev/kmsg
cd zram
run_many\
"zram.sh"
cd $ROOT

After the patch:
===

$ cat run_kselftest.sh
\#!/bin/sh
BASE_DIR=$(realpath $(dirname $0))
. ./kselftest/runner.sh
TESTS="android .. filesystems/binderfs .. zram"

run_android()
{
[ -w /dev/kmsg ] && echo "kselftest: Running tests in android" >> 
/dev/kmsg
cd android
run_many\
"run.sh"
cd $ROOT
}

..

run_filesystems_binderfs()
{
[ -w /dev/kmsg ] && echo "kselftest: Running tests in 
filesystems/binderfs" >> /dev/kmsg
cd filesystems/binderfs
run_many\
"binderfs_test"
cd $ROOT
}

..

run_zram()
{
[ -w /dev/kmsg ] && echo "kselftest: Running tests in zram" >> /dev/kmsg
cd zram
run_many\
"zram.sh"
cd $ROOT
}

usage()
{
cat < 
$logfile; shift ;;
-t | --tests ) TESTS=$2; shift 2 ;;
-l | --list ) echo $TESTS; exit 0 ;;
-h | --help ) usage; exit 0 ;;
"" ) break;;
* ) usage; exit 1;;
esac
done

cd $BASE_DIR
ROOT=$PWD
for folder in $TESTS; do
folder=$(echo $folder | tr -s '/-' '_')
run_$folder
done

Signed-off-by: Hangbin Liu 

---
v5:
Forgot to update commit description for the new added -l option

v4:
Add parameter -l to list available tests, suggested by Bird, Tim

v3:
1) rebase the patch to latest code
2) move `tr -s "/-" "_"` in for loop at the end so user could use test
   folder name directly. Before the fix, user need to use
   ./run_kselftest.sh -t 'networking_forwarding'. Now they can just run
   ./run_kselftest.sh -t 'networking/forwarding' directly.

v2: update document and commit description.
---
 Documentation/dev-tools/kselftest.rst |  8 +
 tools/testing/selftests/Makefile  | 51 +--
 tools/testing/selftests/lib.mk|  2 +-
 3 files changed, 50 insertions(+), 11 deletions(-)

diff --git a/Documentation/dev-tools/kselftest.rst 
b/Documentation/dev-tools/kselftest.rst
index 469d115a95f1..7b92f9c177f6 100644
--- a/Documentation/dev-tools/kselftest.rst
+++ b/Documentation/dev-tools/kselftest.rst
@@ -151,6 +151,14 @@ note some tests will require root privileges::
$ cd kselftest
$ ./run_kselftest.sh
 
+Or you can run some specific test cases in the installed Kselftests by::
+
+   $ ./run_kselftest.sh -t "bpf size timers"
+
+You can view the available tests to run with::
+
+   $ ./run_kselftest.sh -l
+
 Packaging selftests
 ===
 
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index 15c1c1359c50..4c8159dd2bd7 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -225,13 +225,9 @@ ifdef INSTALL_PATH
@# Ask all targets to emit their test scripts
echo "#!/bin/sh" > $(ALL_SCRIPT)
echo "BASE_DIR=\$$(realpath \$$(dirname \$$0))" >> $(ALL_SCRIPT)
-   echo "cd \$$BASE_DIR" >> $(ALL_SCRIPT)
echo ". ./kselftest/runner.sh" >> $(ALL_SCRIPT)
-   echo "ROOT=\$$PWD" >> $(ALL_SCRIPT)
-   echo "if [ \"\$$1\" = \"--summary\" ]; then" >> $(ALL_SCRIPT)
-   echo "  logfile=\$$BASE_DIR/output.log" >> $(ALL_SCRIPT)
-   echo "  cat /dev/null > \$$logfile" >> $(ALL_SCRIPT)
-   echo "fi" >> $(ALL_SCRIPT)
+   echo "TESTS=\"$(TARGETS)\"" >> $(ALL_SCRIPT)
+   echo "" >> $(ALL_SCRIPT);
 
@# While building run_kselftest.sh skip also non-existent TARGET dirs:
@# they could be the result of a build failure and should NOT be
@@ -239,15 +235,50 @@ ifdef INSTALL_PATH
for TARGET in $(TARGETS); do \
BUILD_TARGET=$$BUILD/$$TARGET;  \
[ ! -d $(I

[PATCHv4 kselftest next] selftests/run_kselftest.sh: make each test individually selectable

2020-09-13 Thread Hangbin Liu
Currently, after generating run_kselftest.sh, there is no way to choose
which test we could run. All the tests are listed together and we have
to run all every time. This patch enhanced the run_kselftest.sh to make
the tests individually selectable. e.g.

  $ ./run_kselftest.sh -t "bpf size timers"

Before the patch:


$ cat run_kselftest.sh
\#!/bin/sh
BASE_DIR=$(realpath $(dirname $0))
cd $BASE_DIR
. ./kselftest/runner.sh
ROOT=$PWD
if [ "$1" = "--summary" ]; then
  logfile=$BASE_DIR/output.log
  cat /dev/null > $logfile
fi
[ -w /dev/kmsg ] && echo "kselftest: Running tests in android" >> /dev/kmsg
cd android
run_many\
"run.sh"
cd $ROOT
..
[ -w /dev/kmsg ] && echo "kselftest: Running tests in zram" >> /dev/kmsg
cd zram
run_many\
"zram.sh"
cd $ROOT

After the patch:
===

$ cat run_kselftest.sh
\#!/bin/sh
BASE_DIR=$(realpath $(dirname $0))
. ./kselftest/runner.sh
TESTS="android .. filesystems/binderfs .. zram"

run_android()
{
[ -w /dev/kmsg ] && echo "kselftest: Running tests in android" >> 
/dev/kmsg
cd android
run_many\
"run.sh"
cd $ROOT
}

..

run_filesystems_binderfs()
{
[ -w /dev/kmsg ] && echo "kselftest: Running tests in 
filesystems/binderfs" >> /dev/kmsg
cd filesystems/binderfs
run_many\
"binderfs_test"
cd $ROOT
}

..

run_zram()
{
[ -w /dev/kmsg ] && echo "kselftest: Running tests in zram" >> /dev/kmsg
cd zram
run_many\
"zram.sh"
cd $ROOT
}

usage()
{
cat < 
$logfile; shift ;;
-t | --tests ) TESTS=$2; shift 2 ;;
-h | --help ) usage; exit 0;;
"" ) break;;
* ) usage; exit 1;;
esac
done

cd $BASE_DIR
ROOT=$PWD
for folder in $TESTS; do
folder=$(echo $folder | tr -s '/-' '_')
run_$folder
done

Signed-off-by: Hangbin Liu 

---
v4:
Add parameter -l to list available tests, suggested by Bird, Tim

v3:
1) rebase the patch to latest code
2) move `tr -s "/-" "_"` in for loop at the end so user could use test
   folder name directly. Before the fix, user need to use
   ./run_kselftest.sh -t 'networking_forwarding'. Now they can just run
   ./run_kselftest.sh -t 'networking/forwarding' directly.

v2: update document and commit description.
---
 Documentation/dev-tools/kselftest.rst |  8 +
 tools/testing/selftests/Makefile  | 51 +--
 tools/testing/selftests/lib.mk|  2 +-
 3 files changed, 50 insertions(+), 11 deletions(-)

diff --git a/Documentation/dev-tools/kselftest.rst 
b/Documentation/dev-tools/kselftest.rst
index 469d115a95f1..7b92f9c177f6 100644
--- a/Documentation/dev-tools/kselftest.rst
+++ b/Documentation/dev-tools/kselftest.rst
@@ -151,6 +151,14 @@ note some tests will require root privileges::
$ cd kselftest
$ ./run_kselftest.sh
 
+Or you can run some specific test cases in the installed Kselftests by::
+
+   $ ./run_kselftest.sh -t "bpf size timers"
+
+You can view the available tests to run with::
+
+   $ ./run_kselftest.sh -l
+
 Packaging selftests
 ===
 
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index 15c1c1359c50..4c8159dd2bd7 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -225,13 +225,9 @@ ifdef INSTALL_PATH
@# Ask all targets to emit their test scripts
echo "#!/bin/sh" > $(ALL_SCRIPT)
echo "BASE_DIR=\$$(realpath \$$(dirname \$$0))" >> $(ALL_SCRIPT)
-   echo "cd \$$BASE_DIR" >> $(ALL_SCRIPT)
echo ". ./kselftest/runner.sh" >> $(ALL_SCRIPT)
-   echo "ROOT=\$$PWD" >> $(ALL_SCRIPT)
-   echo "if [ \"\$$1\" = \"--summary\" ]; then" >> $(ALL_SCRIPT)
-   echo "  logfile=\$$BASE_DIR/output.log" >> $(ALL_SCRIPT)
-   echo "  cat /dev/null > \$$logfile" >> $(ALL_SCRIPT)
-   echo "fi" >> $(ALL_SCRIPT)
+   echo "TESTS=\"$(TARGETS)\"" >> $(ALL_SCRIPT)
+   echo "" >> $(ALL_SCRIPT);
 
@# While building run_kselftest.sh skip also non-existent TARGET dirs:
@# they could be the result of a build failure and should NOT be
@@ -239,15 +235,50 @@ ifdef INSTALL_PATH
for TARGET in $(TARGETS); do \
BUILD_TARGET=$$BUILD/$$TARGET;  \
[ ! -d $(INSTALL_PATH)/$$TARGET ] && echo "Skipping 
non-existent dir: $$TARGET" && continue; \
-   

[PATCHv3] selftests/run_kselftest.sh: make each test individually selectable

2020-09-11 Thread Hangbin Liu
Currently, after generating run_kselftest.sh, there is no way to choose
which test we could run. All the tests are listed together and we have
to run all every time. This patch enhanced the run_kselftest.sh to make
the tests individually selectable. e.g.

  $ ./run_kselftest.sh -t "bpf size timers"

Before the patch:


$ cat run_kselftest.sh
\#!/bin/sh
BASE_DIR=$(realpath $(dirname $0))
cd $BASE_DIR
. ./kselftest/runner.sh
ROOT=$PWD
if [ "$1" = "--summary" ]; then
  logfile=$BASE_DIR/output.log
  cat /dev/null > $logfile
fi
[ -w /dev/kmsg ] && echo "kselftest: Running tests in android" >> /dev/kmsg
cd android
run_many\
"run.sh"
cd $ROOT
..
[ -w /dev/kmsg ] && echo "kselftest: Running tests in zram" >> /dev/kmsg
cd zram
run_many\
"zram.sh"
cd $ROOT

After the patch:
===

$ cat run_kselftest.sh
\#!/bin/sh
BASE_DIR=$(realpath $(dirname $0))
. ./kselftest/runner.sh
TESTS="android .. filesystems/binderfs .. zram"

run_android()
{
[ -w /dev/kmsg ] && echo "kselftest: Running tests in android" >> 
/dev/kmsg
cd android
run_many\
"run.sh"
cd $ROOT
}

..

run_filesystems_binderfs()
{
[ -w /dev/kmsg ] && echo "kselftest: Running tests in 
filesystems/binderfs" >> /dev/kmsg
cd filesystems/binderfs
run_many\
"binderfs_test"
cd $ROOT
}

..

run_zram()
{
[ -w /dev/kmsg ] && echo "kselftest: Running tests in zram" >> /dev/kmsg
cd zram
run_many\
"zram.sh"
cd $ROOT
}

usage()
{
cat < 
$logfile; shift ;;
-t | --tests ) TESTS=$2; shift 2 ;;
-h | --help ) usage; exit 0;;
"" ) break;;
* ) usage; exit 1;;
esac
done

cd $BASE_DIR
ROOT=$PWD
for folder in $TESTS; do
folder=$(echo $folder | tr -s '/-' '_')
run_$folder
done

Signed-off-by: Hangbin Liu 

---
v3:
1) rebase the patch to latest code
2) move `tr -s "/-" "_"` to the for loop at the end so user could use test
   folder name directly. Before the update, user need to run
   ./run_kselftest.sh -t 'networking_forwarding'. Now they can just run
   ./run_kselftest.sh -t 'networking/forwarding' directly.

v2: update document and commit description.
---
 Documentation/dev-tools/kselftest.rst |  4 +++
 tools/testing/selftests/Makefile  | 49 +--
 tools/testing/selftests/lib.mk|  2 +-
 3 files changed, 44 insertions(+), 11 deletions(-)

diff --git a/Documentation/dev-tools/kselftest.rst 
b/Documentation/dev-tools/kselftest.rst
index 469d115a95f1..94da633dd5f8 100644
--- a/Documentation/dev-tools/kselftest.rst
+++ b/Documentation/dev-tools/kselftest.rst
@@ -151,6 +151,10 @@ note some tests will require root privileges::
$ cd kselftest
$ ./run_kselftest.sh
 
+Or you can run some specific test cases in the installed Kselftests by::
+
+   $ ./run_kselftest.sh -t "bpf size timers"
+
 Packaging selftests
 ===
 
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index 15c1c1359c50..6b11d5e33019 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -225,13 +225,9 @@ ifdef INSTALL_PATH
@# Ask all targets to emit their test scripts
echo "#!/bin/sh" > $(ALL_SCRIPT)
echo "BASE_DIR=\$$(realpath \$$(dirname \$$0))" >> $(ALL_SCRIPT)
-   echo "cd \$$BASE_DIR" >> $(ALL_SCRIPT)
echo ". ./kselftest/runner.sh" >> $(ALL_SCRIPT)
-   echo "ROOT=\$$PWD" >> $(ALL_SCRIPT)
-   echo "if [ \"\$$1\" = \"--summary\" ]; then" >> $(ALL_SCRIPT)
-   echo "  logfile=\$$BASE_DIR/output.log" >> $(ALL_SCRIPT)
-   echo "  cat /dev/null > \$$logfile" >> $(ALL_SCRIPT)
-   echo "fi" >> $(ALL_SCRIPT)
+   echo "TESTS=\"$(TARGETS)\"" >> $(ALL_SCRIPT)
+   echo "" >> $(ALL_SCRIPT);
 
@# While building run_kselftest.sh skip also non-existent TARGET dirs:
@# they could be the result of a build failure and should NOT be
@@ -239,15 +235,48 @@ ifdef INSTALL_PATH
for TARGET in $(TARGETS); do \
BUILD_TARGET=$$BUILD/$$TARGET;  \
[ ! -d $(INSTALL_PATH)/$$TARGET ] && echo "Skipping 
non-existent dir: $$TARGET" && continue; \
-   echo "[ -w /dev/kmsg ] && echo \"kselftest: Running tests in 
$$TARGET\" >> /dev/kmsg" >> $(ALL_

Re: [PATCH] mld: fix memory leak in ipv6_mc_destroy_dev()

2020-06-12 Thread Hangbin Liu
On Thu, Jun 11, 2020 at 03:57:50PM +0800, Wang Hai wrote:
> Commit a84d01647989 ("mld: fix memory leak in mld_del_delrec()") fixed
> the memory leak of MLD, but missing the ipv6_mc_destroy_dev() path, in
> which mca_sources are leaked after ma_put().
> 
> Using ip6_mc_clear_src() to take care of the missing free.
> 
> BUG: memory leak
> unreferenced object 0x8881113d3180 (size 64):
>   comm "syz-executor071", pid 389, jiffies 4294887985 (age 17.943s)
>   hex dump (first 32 bytes):
> 00 00 00 00 00 00 00 00 ff 02 00 00 00 00 00 00  
> 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00  
>   backtrace:
> [<2cbc483c>] kmalloc include/linux/slab.h:555 [inline]
> [<2cbc483c>] kzalloc include/linux/slab.h:669 [inline]
> [<2cbc483c>] ip6_mc_add1_src net/ipv6/mcast.c:2237 [inline]
> [<2cbc483c>] ip6_mc_add_src+0x7f5/0xbb0 net/ipv6/mcast.c:2357
> [<58b8b1ff>] ip6_mc_source+0xe0c/0x1530 net/ipv6/mcast.c:449
> [<0bfc4fb5>] do_ipv6_setsockopt.isra.12+0x1b2c/0x3b30 
> net/ipv6/ipv6_sockglue.c:754
> [<e4e7a722>] ipv6_setsockopt+0xda/0x150 
> net/ipv6/ipv6_sockglue.c:950
> [<29260d9a>] rawv6_setsockopt+0x45/0x100 net/ipv6/raw.c:1081
> [<5c1b46f9>] __sys_setsockopt+0x131/0x210 net/socket.c:2132
> [<8491f7db>] __do_sys_setsockopt net/socket.c:2148 [inline]
> [<8491f7db>] __se_sys_setsockopt net/socket.c:2145 [inline]
> [<8491f7db>] __x64_sys_setsockopt+0xba/0x150 net/socket.c:2145
> [<c7bc11c5>] do_syscall_64+0xa1/0x530 arch/x86/entry/common.c:295
> [<5fb7a3f3>] entry_SYSCALL_64_after_hwframe+0x49/0xb3
> 
> Fixes: 1666d49e1d41 ("mld: do not remove mld souce list info when set link 
> down")
> Reported-by: Hulk Robot 
> Signed-off-by: Wang Hai 
> ---
>  net/ipv6/mcast.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/net/ipv6/mcast.c b/net/ipv6/mcast.c
> index 7e12d2114158..8cd2782a31e4 100644
> --- a/net/ipv6/mcast.c
> +++ b/net/ipv6/mcast.c
> @@ -2615,6 +2615,7 @@ void ipv6_mc_destroy_dev(struct inet6_dev *idev)
>   idev->mc_list = i->next;
>  
>   write_unlock_bh(&idev->lock);
> + ip6_mc_clear_src(i);
>   ma_put(i);
>   write_lock_bh(&idev->lock);
>   }
> -- 
> 2.17.1
> 

Acked-by: Hangbin Liu 


[PATCH 5.4] selftests/bpf: fix goto cleanup label not defined

2020-05-14 Thread Hangbin Liu
kernel test robot found a warning when build bpf selftest for 5.4.y stable
tree:

prog_tests/stacktrace_build_id_nmi.c:55:3: error: label ‘cleanup’ used but not 
defined
   goto cleanup;
   ^~~~

This is because we are lacking upstream commit dde53c1b763b
("selftests/bpf: Convert few more selftest to skeletons"). But this
commit is too large and need more backports. To fix it, the
easiest way is just use the current goto label 'close_prog'.

Reported-by: kernel test robot 
Fixes: da43712a7262 ("selftests/bpf: Skip perf hw events test if the setup 
disabled it")
Signed-off-by: Hangbin Liu 
---
 .../testing/selftests/bpf/prog_tests/stacktrace_build_id_nmi.c  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/stacktrace_build_id_nmi.c 
b/tools/testing/selftests/bpf/prog_tests/stacktrace_build_id_nmi.c
index 1735faf17536..437cb93e72ac 100644
--- a/tools/testing/selftests/bpf/prog_tests/stacktrace_build_id_nmi.c
+++ b/tools/testing/selftests/bpf/prog_tests/stacktrace_build_id_nmi.c
@@ -52,7 +52,7 @@ void test_stacktrace_build_id_nmi(void)
if (pmu_fd < 0 && errno == ENOENT) {
printf("%s:SKIP:no PERF_COUNT_HW_CPU_CYCLES\n", __func__);
test__skip();
-   goto cleanup;
+   goto close_prog;
}
if (CHECK(pmu_fd < 0, "perf_event_open", "err %d errno %d\n",
  pmu_fd, errno))
-- 
2.25.4



Re: hard-coded limit on unresolved multicast route cache in ipv4/ipmr.c causes slow, unreliable creation of multicast routes on busy networks

2019-06-24 Thread Hangbin Liu
On Tue, Dec 18, 2018 at 09:55:45PM -0800, David Miller wrote:
> From: Sukumar Gopalakrishnan 
> Date: Wed, 19 Dec 2018 10:57:02 +0530
> 
> > Hi David,
> > 
> >   There are two patch for this issue:
> >1) Your changes which removes cache_resolve_queue_len
> > 2) Hangbin's changes which make cache_resolve_queue_len configurable.
> > 
> > Which one will be chosen for this issue ?
> 
> I do plan to look into this, sorry for taking so long.
> 
> Right now I am overwhelmed preparing for the next merge window and
> synchronizing with other developers for that.
> 
> Please be patient.

Hi David,

Any progress for this issue?

Thanks
Hangbin


Re: [PATCH 4.9 41/51] fib_rules: return 0 directly if an exactly same rule exists when NLM_F_EXCL not supplied

2019-05-19 Thread Hangbin Liu
On Sun, May 19, 2019 at 10:27:53PM +0200, Florian Westphal wrote:
> Nathan Chancellor  wrote:
> > On Wed, May 15, 2019 at 12:56:16PM +0200, Greg Kroah-Hartman wrote:
> > > From: Hangbin Liu 
> > > 
> > > [ Upstream commit e9919a24d3022f72bcadc407e73a6ef17093a849 ]
> 
> [..]
> 
> > > Fixes: 153380ec4b9 ("fib_rules: Added NLM_F_EXCL support to 
> > > fib_nl_newrule")
> > > Reported-by: Thomas Haller 
> > > Signed-off-by: Hangbin Liu 
> > > Signed-off-by: David S. Miller 
> > > Signed-off-by: Greg Kroah-Hartman 
> > > ---
> > >  net/core/fib_rules.c |6 +++---
> > >  1 file changed, 3 insertions(+), 3 deletions(-)
> > > 
> > > --- a/net/core/fib_rules.c
> > > +++ b/net/core/fib_rules.c
> > > @@ -429,9 +429,9 @@ int fib_nl_newrule(struct sk_buff *skb,
> > >   if (rule->l3mdev && rule->table)
> > >   goto errout_free;
> > >  
> > > - if ((nlh->nlmsg_flags & NLM_F_EXCL) &&
> > > - rule_exists(ops, frh, tb, rule)) {
> > > - err = -EEXIST;
> > > + if (rule_exists(ops, frh, tb, rule)) {
> > > + if (nlh->nlmsg_flags & NLM_F_EXCL)
> > > + err = -EEXIST;
> > This commit is causing issues on Android devices when Wi-Fi and mobile
> > data are both enabled. The device will do a soft reboot consistently.
> 
> Not surprising, the patch can't be applied to 4.9 as-is.
> 
> In 4.9, code looks like this:
> 
>  err = -EINVAL;
>  /* irrelevant */
>  if (rule_exists(ops, frh, tb, rule)) {
>   if (nlh->nlmsg_flags & NLM_F_EXCL)
> err = -EEXIST;
> goto errout_free;
>  }
> 
> So, if rule_exists() is true, we return -EINVAL to caller
> instead of 0, unlike upstream.
> 
> I don't think this commit is stable material.

Thanks Florian for helping check it. So we need either revert this patch,
or at least backport adeb45cbb505 ("fib_rules: fix error return code") and
f9d4b0c1e969 ("fib_rules: move common handling of newrule delrule
msgs into fib_nl2rule").

For me, I agree to revert this patch from stable tree as it's a small fix. The
issue has been there for a long time and I didn't see much complain from
customer.

Thanks
Hangbin



Re: [PATCH 4.19 01/24] bridge: do not add port to router list when receives query with source 0.0.0.0

2019-02-20 Thread Hangbin Liu
On Wed, Feb 20, 2019 at 03:09:21PM +0200, Nikolay Aleksandrov wrote:
> On 20/02/2019 14:48, Sebastian Gottschall wrote:
> > *reminder*
> > 
> [snip]
> >    }
> >    static void br_ip4_multicast_query(struct net_bridge *br,
> >>> Is this also a problem in 4.20?  This patch went into 4.20-rc1, so it
> >>> has been around for a while with no reported issues that I can find.
> >>> Any pointers to the reports?
> >>
> >> i need to check this. i found this patch in 4.9, 4.14 and 4.4
> >> the rest was picked up from the mailinglist. according to the git sources 
> >> of 4.20 and 5.0 the same code is in there as well
> >>
> >> i just got the report from users today and was able to reproduce it with 
> >> iptv streams. just by disabling the code it was working again.
> >>
> >> Sebastian
> >>>
> >>> thanks,
> >>>
> >>> greg k-h
> >>>
> >>
> 
> Could you please include more details about the setup that's broken ?
> Note that we were warned[1] of potential breakage from this change

Sorry I missed Linus's reply after Ying Xu replied. I will read it and
disscuss with Ying Xu.

> after it went in and regardless of the suggestion from the RFC we'll
> probably have to revert this patch.
> 
> Ying Xu as author of the patch, any thoughts ?

No, we are also waiting for more details from Sebastian.

Thanks
Hangbin

> 
> Also adding Linus Lüssing to the CC as he was the one who warned against it.
> Note that the warning was sent as a reply to my breakage fix, but it was 
> intended
> for the original patch.
> 
> Thanks,
>  Nik
> 
> [1] https://www.mail-archive.com/netdev@vger.kernel.org/msg272944.html
> 


Re: linux-next: build failure in Linus' tree

2018-10-28 Thread Hangbin Liu
On Sun, Oct 28, 2018 at 03:45:16PM -0700, Linus Torvalds wrote:
> On Sun, Oct 28, 2018 at 3:35 PM Stephen Rothwell  
> wrote:
> >
> > After merging the origin tree, today's linux-next build (powerpc
> > ppc64_defconfig) failed like this:
> 
> linux-next is back! Wheee..
> 
> >   5a2de63fd1a5 ("bridge: do not add port to router list when receives query 
> > with source 0.0.0.0")
> 
> David?
> 
>  Linus

Sorry, I forgot to check if IPv6 is configured. Nikolay has helped post
a fix for this issue.

Regards
Hangbin


Re: linux-next: Signed-off-by missing for commit in the net tree

2018-05-10 Thread Hangbin Liu
On Fri, May 11, 2018 at 07:17:16AM +1000, Stephen Rothwell wrote:
> Hi all,
> 
> Commit
> 
>   0e8411e426e2 ("ipv4: reset fnhe_mtu_locked after cache route flushed")
> 
> is missing a Signed-off-by from its author.

Opps, My bad.

> After route cache is flushed via ipv4_sysctl_rtcache_flush(), we forget
> to reset fnhe_mtu_locked in rt_bind_exception(). When pmtu is updated
> in __ip_rt_update_pmtu(), it will return directly since the pmtu is
> still locked. e.g.
>
> + ip netns exec client ping 10.10.1.1 -c 1 -s 1400 -M do
> PING 10.10.1.1 (10.10.1.1) 1400(1428) bytes of data.
> From 10.10.0.254 icmp_seq=1 Frag needed and DF set (mtu = 0)
>
> --- 10.10.1.1 ping statistics ---
> 1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms

I shouldn't add comments with the '---' lines. David reminded me before. But
I didn't realise it when pasted the ping logs. Another lesson learned...

Thanks Stephen.

Regards
Hangbin


Re: possible deadlock in smc_close_non_accepted

2018-05-03 Thread Hangbin Liu
#syz fix: net/smc: simplify wait when closing listen socket


Re: WARNING: kobject bug in br_add_if

2018-04-26 Thread Hangbin Liu
On Thu, Apr 26, 2018 at 10:04:16AM +0200, Dmitry Vyukov wrote:
> On Thu, Apr 26, 2018 at 8:13 AM, Hangbin Liu  wrote:
> > On Wed, Apr 11, 2018 at 05:18:23PM +0200, Dmitry Vyukov wrote:
> >> On Wed, Apr 11, 2018 at 5:15 PM, syzbot
> >>  wrote:
> >> > Hello,
> >> >
> >> > syzbot hit the following crash on upstream commit
> >> > 10b84daddbec72c6b440216a69de9a9605127f7a (Sat Mar 31 17:59:00 2018 +)
> >> > Merge branch 'perf-urgent-for-linus' of
> >> > git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
> >> > syzbot dashboard link:
> >> > https://syzkaller.appspot.com/bug?extid=de73361ee4971b6e6f75
> >> >
> >> > So far this crash happened 4 times on net-next, upstream.
> >> > Unfortunately, I don't have any reproducer for this crash yet.
> >> > Raw console output:
> >> > https://syzkaller.appspot.com/x/log.txt?id=5007286875455488
> >> > Kernel config:
> >> > https://syzkaller.appspot.com/x/.config?id=-2760467897697295172
> >> > compiler: gcc (GCC) 7.1.1 20170620
> >> >
> >> > IMPORTANT: if you fix the bug, please add the following tag to the 
> >> > commit:
> >> > Reported-by: syzbot+de73361ee4971b6e6...@syzkaller.appspotmail.com
> >> > It will help syzbot understand when the bug is fixed. See footer for
> >> > details.
> >> > If you forward the report, please keep this part and the footer.
> >>
> >> +Greg
> >>
> >> The plan is to remove this WARNING from kobject_add, if there are no 
> >> objections.
> >
> > Hi Dmitry,
> >
> > For this bug, why should we remove the WARNING instead of adding a check in
> > br_add_if()? Something like
> 
> 
> Mainline because nobody wants to fix these.
> If you think this is a real bug and you are ready to fix it, please
> mail an official patch.
> 
> >> > [ cut here ]
> >> > binder: 23650:23651 unknown command 1078223622
> >> > kobject_add_internal failed for brport (error: -12 parent: bond0)

Re-checked the error. This is a -ENOMEM. So normally we could ignore it.

But on the other hand, although we could find out the slave iface's
master in netdev_master_upper_dev_link(). It already go much further
and allocate some resource and change iface state. e.g.

[54273.968516] br0: port 1(em1) entered blocking state
[54273.973979] br0: port 1(em1) entered disabled state

So I think we'd better return as early as possible. I will post a fix
for this.

Thanks
Hangbin

> >> > binder: 23650:23651 ioctl c0306201 2000dfd0 returned -22
> >> > WARNING: CPU: 1 PID: 23647 at lib/kobject.c:242
> >> > kobject_add_internal+0x3f6/0xbc0 lib/kobject.c:240
> >> > Kernel panic - not syncing: panic_on_warn set ...
> >> >
> >> > CPU: 1 PID: 23647 Comm: syz-executor7 Not tainted 4.16.0-rc7+ #374
> >> > binder: BINDER_SET_CONTEXT_MGR already set
> >> > Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
> >> > Google 01/01/2011
> >> > Call Trace:
> >> >  __dump_stack lib/dump_stack.c:17 [inline]
> >> >  dump_stack+0x194/0x24d lib/dump_stack.c:53
> >> >  panic+0x1e4/0x41c kernel/panic.c:183
> >> >  __warn+0x1dc/0x200 kernel/panic.c:547
> >> >  report_bug+0x1f4/0x2b0 lib/bug.c:186
> >> >  fixup_bug.part.10+0x37/0x80 arch/x86/kernel/traps.c:178
> >> >  fixup_bug arch/x86/kernel/traps.c:247 [inline]
> >> >  do_error_trap+0x2d7/0x3e0 arch/x86/kernel/traps.c:296
> >> >  do_invalid_op+0x1b/0x20 arch/x86/kernel/traps.c:315
> >> >  invalid_op+0x1b/0x40 arch/x86/entry/entry_64.S:986
> >> > RIP: 0010:kobject_add_internal+0x3f6/0xbc0 lib/kobject.c:240
> >> > RSP: 0018:8801d089f560 EFLAGS: 00010286
> >> > RAX: dc08 RBX: 8801adbee178 RCX: 815b193e
> >> > RDX: 0004 RSI: c900022aa000 RDI: 11003a113e31
> >> > RBP: 8801d089f658 R08: 11003a113df3 R09: 
> >> > R10:  R11:  R12: 11003a113eb2
> >> > R13: fff4 R14: 8801abd88828 R15: 8801d75a1e00
> >> >  kobject_add_varg lib/kobject.c:364 [inline]
> >> >  kobject_init_and_add+0xf9/0x150 lib/kobject.c:436
> >> >  br_add_if+0x79a/0x1a70 net/bridge/br_if.c:533
> >> >  add_del_if+0xf4/0x140 net/bridge/br_ioctl.c:101
> >> >  br_dev_ioctl+0xa2/0xc0 net/bridge/br_ioctl.c:396
> >

Re: WARNING: kobject bug in br_add_if

2018-04-25 Thread Hangbin Liu
On Wed, Apr 11, 2018 at 05:18:23PM +0200, Dmitry Vyukov wrote:
> On Wed, Apr 11, 2018 at 5:15 PM, syzbot
>  wrote:
> > Hello,
> >
> > syzbot hit the following crash on upstream commit
> > 10b84daddbec72c6b440216a69de9a9605127f7a (Sat Mar 31 17:59:00 2018 +)
> > Merge branch 'perf-urgent-for-linus' of
> > git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
> > syzbot dashboard link:
> > https://syzkaller.appspot.com/bug?extid=de73361ee4971b6e6f75
> >
> > So far this crash happened 4 times on net-next, upstream.
> > Unfortunately, I don't have any reproducer for this crash yet.
> > Raw console output:
> > https://syzkaller.appspot.com/x/log.txt?id=5007286875455488
> > Kernel config:
> > https://syzkaller.appspot.com/x/.config?id=-2760467897697295172
> > compiler: gcc (GCC) 7.1.1 20170620
> >
> > IMPORTANT: if you fix the bug, please add the following tag to the commit:
> > Reported-by: syzbot+de73361ee4971b6e6...@syzkaller.appspotmail.com
> > It will help syzbot understand when the bug is fixed. See footer for
> > details.
> > If you forward the report, please keep this part and the footer.
> 
> +Greg
> 
> The plan is to remove this WARNING from kobject_add, if there are no 
> objections.

Hi Dmitry,

For this bug, why should we remove the WARNING instead of adding a check in
br_add_if()? Something like

diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c
index 82c1a6f..79dcc3d 100644
--- a/net/bridge/br_if.c
+++ b/net/bridge/br_if.c
@@ -518,8 +518,8 @@ int br_add_if(struct net_bridge *br, struct net_device *dev,
return -ELOOP;
}

-   /* Device is already being bridged */
-   if (br_port_exists(dev))
+   /* Device still has master upper dev */
+   if (netdev_master_upper_dev_get(dev))
return -EBUSY;

/* No bridging devices that dislike that (e.g. wireless) */

Thanks
Hangbin
> 
> > [ cut here ]
> > binder: 23650:23651 unknown command 1078223622
> > kobject_add_internal failed for brport (error: -12 parent: bond0)
> > binder: 23650:23651 ioctl c0306201 2000dfd0 returned -22
> > WARNING: CPU: 1 PID: 23647 at lib/kobject.c:242
> > kobject_add_internal+0x3f6/0xbc0 lib/kobject.c:240
> > Kernel panic - not syncing: panic_on_warn set ...
> >
> > CPU: 1 PID: 23647 Comm: syz-executor7 Not tainted 4.16.0-rc7+ #374
> > binder: BINDER_SET_CONTEXT_MGR already set
> > Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
> > Google 01/01/2011
> > Call Trace:
> >  __dump_stack lib/dump_stack.c:17 [inline]
> >  dump_stack+0x194/0x24d lib/dump_stack.c:53
> >  panic+0x1e4/0x41c kernel/panic.c:183
> >  __warn+0x1dc/0x200 kernel/panic.c:547
> >  report_bug+0x1f4/0x2b0 lib/bug.c:186
> >  fixup_bug.part.10+0x37/0x80 arch/x86/kernel/traps.c:178
> >  fixup_bug arch/x86/kernel/traps.c:247 [inline]
> >  do_error_trap+0x2d7/0x3e0 arch/x86/kernel/traps.c:296
> >  do_invalid_op+0x1b/0x20 arch/x86/kernel/traps.c:315
> >  invalid_op+0x1b/0x40 arch/x86/entry/entry_64.S:986
> > RIP: 0010:kobject_add_internal+0x3f6/0xbc0 lib/kobject.c:240
> > RSP: 0018:8801d089f560 EFLAGS: 00010286
> > RAX: dc08 RBX: 8801adbee178 RCX: 815b193e
> > RDX: 0004 RSI: c900022aa000 RDI: 11003a113e31
> > RBP: 8801d089f658 R08: 11003a113df3 R09: 
> > R10:  R11:  R12: 11003a113eb2
> > R13: fff4 R14: 8801abd88828 R15: 8801d75a1e00
> >  kobject_add_varg lib/kobject.c:364 [inline]
> >  kobject_init_and_add+0xf9/0x150 lib/kobject.c:436
> >  br_add_if+0x79a/0x1a70 net/bridge/br_if.c:533
> >  add_del_if+0xf4/0x140 net/bridge/br_ioctl.c:101
> >  br_dev_ioctl+0xa2/0xc0 net/bridge/br_ioctl.c:396
> >  dev_ifsioc+0x333/0x9b0 net/core/dev_ioctl.c:334
> >  dev_ioctl+0x176/0xbe0 net/core/dev_ioctl.c:500
> >  sock_do_ioctl+0x1ba/0x390 net/socket.c:981
> >  sock_ioctl+0x367/0x670 net/socket.c:1081
> >  vfs_ioctl fs/ioctl.c:46 [inline]
> >  do_vfs_ioctl+0x1b1/0x1520 fs/ioctl.c:686
> >  SYSC_ioctl fs/ioctl.c:701 [inline]
> >  SyS_ioctl+0x8f/0xc0 fs/ioctl.c:692
> >  do_syscall_64+0x281/0x940 arch/x86/entry/common.c:287
> >  entry_SYSCALL_64_after_hwframe+0x42/0xb7
> > RIP: 0033:0x454e79
> > RSP: 002b:7eff7dab7c68 EFLAGS: 0246 ORIG_RAX: 0010
> > RAX: ffda RBX: 7eff7dab86d4 RCX: 00454e79
> > RDX: 2000 RSI: 89a2 RDI: 0014
> > RBP: 0072bea0 R08:  R09: 
> > R10:  R11: 0246 R12: 0015
> > R13: 0369 R14: 006f7278 R15: 0006
> > Dumping ftrace buffer:
> >(ftrace buffer empty)
> > Kernel Offset: disabled
> > Rebooting in 86400 seconds..


Re: [PATCH 3.2 086/126] igmp: do not remove igmp souce list info when set link down

2017-02-15 Thread Hangbin Liu
2017-02-16 6:41 GMT+08:00 Ben Hutchings :
> 3.2.85-rc1 review patch.  If anyone has any objections, please let me know.
>
> --
>
> From: Hangbin Liu 
>
> commit 24803f38a5c0b6c57ed800b47e695f9ce474bc3a upstream.
>
> In commit 24cf3af3fed5 ("igmp: call ip_mc_clear_src..."), we forgot to remove
> igmpv3_clear_delrec() in ip_mc_down(), which also called ip_mc_clear_src().
> This make us clear all IGMPv3 source filter info after NETDEV_DOWN.
> Move igmpv3_clear_delrec() to ip_mc_destroy_dev() and then no need
> ip_mc_clear_src() in ip_mc_destroy_dev().
>
> On the other hand, we should restore back instead of free all source filter
> info in igmpv3_del_delrec(). Or we will not able to restore IGMPv3 source
> filter info after NETDEV_UP and NETDEV_POST_TYPE_CHANGE.
>
> Fixes: 24cf3af3fed5 ("igmp: call ip_mc_clear_src() only when ...")
> Signed-off-by: Hangbin Liu 
> Signed-off-by: David S. Miller 
> [bwh: Backported to 3.2:
>  - Use IGMP_Unsolicited_Report_Count instead of sysctl_igmp_qrv
>  - Adjust context]
> Signed-off-by: Ben Hutchings 

Hi Ben,

There is a bug fix for this patch, please consider drop this patch or
include the fix.

commit 9c8bb163ae784be4f79ae504e78c862806087c54
Author: Hangbin Liu 
Date:   Wed Feb 8 21:16:45 2017 +0800

igmp, mld: Fix memory leak in igmpv3/mld_del_delrec()

In function igmpv3/mld_add_delrec() we allocate pmc and put it in
idev->mc_tomb, so we should free it when we don't need it in del_delrec().
But I removed kfree(pmc) incorrectly in latest two patches. Now fix it.

Fixes: 24803f38a5c0 ("igmp: do not remove igmp souce list info when ...")
Fixes: 1666d49e1d41 ("mld: do not remove mld souce list info when ...")
Reported-by: Daniel Borkmann 
Signed-off-by: Hangbin Liu 
Signed-off-by: David S. Miller 

Thanks
Hangbin