Message ID | 20220712235310.1935121-4-joannelkoong@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | Add a second bind table hashed by port + address | expand |
On Tue, 2022-07-12 at 16:53 -0700, Joanne Koong wrote: > This patch adds a new test called sk_bind_sendto_listen. > > This test exercises the path where a socket's rcv saddr changes after it > has been added to the binding tables, and then a listen() on the socket > is invoked. The listen() should succeed. > > This test is copied over from one of syzbot's tests: > https://syzkaller.appspot.com/x/repro.c?x=1673a38df00000 > > Signed-off-by: Joanne Koong <joannelkoong@gmail.com> > --- > tools/testing/selftests/net/.gitignore | 1 + > tools/testing/selftests/net/Makefile | 1 + > .../selftests/net/sk_bind_sendto_listen.c | 80 +++++++++++++++++++ > 3 files changed, 82 insertions(+) > create mode 100644 tools/testing/selftests/net/sk_bind_sendto_listen.c > > diff --git a/tools/testing/selftests/net/.gitignore b/tools/testing/selftests/net/.gitignore > index 5b1adf6e29ae..5fd74a1162cc 100644 > --- a/tools/testing/selftests/net/.gitignore > +++ b/tools/testing/selftests/net/.gitignore > @@ -39,3 +39,4 @@ toeplitz > cmsg_sender > unix_connect > bind_bhash > +sk_bind_sendto_listen > diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile > index e678fc3030a2..ffcc472d50d5 100644 > --- a/tools/testing/selftests/net/Makefile > +++ b/tools/testing/selftests/net/Makefile > @@ -61,6 +61,7 @@ TEST_GEN_FILES += cmsg_sender > TEST_GEN_FILES += stress_reuseport_listen > TEST_PROGS += test_vxlan_vnifiltering.sh > TEST_GEN_FILES += bind_bhash > +TEST_GEN_FILES += sk_bind_sendto_listen It looks like this is never invoked by the self-tests ?!? you should likely update bind_bhash.sh to run the new program. Thanks! Paolo
On Thu, Jul 14, 2022 at 2:19 AM Paolo Abeni <pabeni@redhat.com> wrote: > > On Tue, 2022-07-12 at 16:53 -0700, Joanne Koong wrote: > > This patch adds a new test called sk_bind_sendto_listen. > > > > This test exercises the path where a socket's rcv saddr changes after it > > has been added to the binding tables, and then a listen() on the socket > > is invoked. The listen() should succeed. > > > > This test is copied over from one of syzbot's tests: > > https://syzkaller.appspot.com/x/repro.c?x=1673a38df00000 > > > > Signed-off-by: Joanne Koong <joannelkoong@gmail.com> > > --- > > tools/testing/selftests/net/.gitignore | 1 + > > tools/testing/selftests/net/Makefile | 1 + > > .../selftests/net/sk_bind_sendto_listen.c | 80 +++++++++++++++++++ > > 3 files changed, 82 insertions(+) > > create mode 100644 tools/testing/selftests/net/sk_bind_sendto_listen.c > > > > diff --git a/tools/testing/selftests/net/.gitignore b/tools/testing/selftests/net/.gitignore > > index 5b1adf6e29ae..5fd74a1162cc 100644 > > --- a/tools/testing/selftests/net/.gitignore > > +++ b/tools/testing/selftests/net/.gitignore > > @@ -39,3 +39,4 @@ toeplitz > > cmsg_sender > > unix_connect > > bind_bhash > > +sk_bind_sendto_listen > > diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile > > index e678fc3030a2..ffcc472d50d5 100644 > > --- a/tools/testing/selftests/net/Makefile > > +++ b/tools/testing/selftests/net/Makefile > > @@ -61,6 +61,7 @@ TEST_GEN_FILES += cmsg_sender > > TEST_GEN_FILES += stress_reuseport_listen > > TEST_PROGS += test_vxlan_vnifiltering.sh > > TEST_GEN_FILES += bind_bhash > > +TEST_GEN_FILES += sk_bind_sendto_listen > > It looks like this is never invoked by the self-tests ?!? you should > likely update bind_bhash.sh to run the new program. Oh, I see. I didn't realize the net selftests should get invoked automatically. Sorry about that. I will add a "TEST_GEN_PROGS += sk_bind_sendto_listen" line to the Makefile instead of adding it to bind_bhash.sh since the bhash setup is not required for running ./sk_bind_sendto_listen. Thanks! > > Thanks! > > Paolo >
diff --git a/tools/testing/selftests/net/.gitignore b/tools/testing/selftests/net/.gitignore index 5b1adf6e29ae..5fd74a1162cc 100644 --- a/tools/testing/selftests/net/.gitignore +++ b/tools/testing/selftests/net/.gitignore @@ -39,3 +39,4 @@ toeplitz cmsg_sender unix_connect bind_bhash +sk_bind_sendto_listen diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile index e678fc3030a2..ffcc472d50d5 100644 --- a/tools/testing/selftests/net/Makefile +++ b/tools/testing/selftests/net/Makefile @@ -61,6 +61,7 @@ TEST_GEN_FILES += cmsg_sender TEST_GEN_FILES += stress_reuseport_listen TEST_PROGS += test_vxlan_vnifiltering.sh TEST_GEN_FILES += bind_bhash +TEST_GEN_FILES += sk_bind_sendto_listen TEST_FILES := settings diff --git a/tools/testing/selftests/net/sk_bind_sendto_listen.c b/tools/testing/selftests/net/sk_bind_sendto_listen.c new file mode 100644 index 000000000000..b420d830f72c --- /dev/null +++ b/tools/testing/selftests/net/sk_bind_sendto_listen.c @@ -0,0 +1,80 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include <arpa/inet.h> +#include <error.h> +#include <errno.h> +#include <unistd.h> + +int main(void) +{ + int fd1, fd2, one = 1; + struct sockaddr_in6 bind_addr = { + .sin6_family = AF_INET6, + .sin6_port = htons(20000), + .sin6_flowinfo = htonl(0), + .sin6_addr = {}, + .sin6_scope_id = 0, + }; + + inet_pton(AF_INET6, "::", &bind_addr.sin6_addr); + + fd1 = socket(AF_INET6, SOCK_STREAM, IPPROTO_IP); + if (fd1 < 0) { + error(1, errno, "socket fd1"); + return -1; + } + + if (setsockopt(fd1, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one))) { + error(1, errno, "setsockopt(SO_REUSEADDR) fd1"); + goto out_err1; + } + + if (bind(fd1, (struct sockaddr *)&bind_addr, sizeof(bind_addr))) { + error(1, errno, "bind fd1"); + goto out_err1; + } + + if (sendto(fd1, NULL, 0, MSG_FASTOPEN, (struct sockaddr *)&bind_addr, + sizeof(bind_addr))) { + error(1, errno, "sendto fd1"); + goto out_err1; + } + + fd2 = socket(AF_INET6, SOCK_STREAM, IPPROTO_IP); + if (fd2 < 0) { + error(1, errno, "socket fd2"); + goto out_err1; + } + + if (setsockopt(fd2, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one))) { + error(1, errno, "setsockopt(SO_REUSEADDR) fd2"); + goto out_err2; + } + + if (bind(fd2, (struct sockaddr *)&bind_addr, sizeof(bind_addr))) { + error(1, errno, "bind fd2"); + goto out_err2; + } + + if (sendto(fd2, NULL, 0, MSG_FASTOPEN, (struct sockaddr *)&bind_addr, + sizeof(bind_addr)) != -1) { + error(1, errno, "sendto fd2"); + goto out_err2; + } + + if (listen(fd2, 0)) { + error(1, errno, "listen"); + goto out_err2; + } + + close(fd2); + close(fd1); + return 0; + +out_err2: + close(fd2); + +out_err1: + close(fd1); + return -1; +}
This patch adds a new test called sk_bind_sendto_listen. This test exercises the path where a socket's rcv saddr changes after it has been added to the binding tables, and then a listen() on the socket is invoked. The listen() should succeed. This test is copied over from one of syzbot's tests: https://syzkaller.appspot.com/x/repro.c?x=1673a38df00000 Signed-off-by: Joanne Koong <joannelkoong@gmail.com> --- tools/testing/selftests/net/.gitignore | 1 + tools/testing/selftests/net/Makefile | 1 + .../selftests/net/sk_bind_sendto_listen.c | 80 +++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 tools/testing/selftests/net/sk_bind_sendto_listen.c