* [PATCH net-next 1/2] net: dccp: initialize (addr,port) listening hashtable
@ 2018-12-15 22:27 Peter Oskolkov
2018-12-15 22:27 ` [PATCH net-next 2/2] selftests: net: reuseport_addr_any: add DCCP Peter Oskolkov
2018-12-16 20:14 ` [PATCH net-next 1/2] net: dccp: initialize (addr,port) listening hashtable David Miller
0 siblings, 2 replies; 5+ messages in thread
From: Peter Oskolkov @ 2018-12-15 22:27 UTC (permalink / raw)
To: David Miller, netdev
Cc: Peter Oskolkov, Eric Dumazet, Peter Oskolkov, syzcaller
Commit d9fbc7f6431f "net: tcp: prefer listeners bound to an address"
removes port-only listener lookups. This caused segfaults in DCCP
lookups because DCCP did not initialize the (addr,port) hashtable.
This patch adds said initialization.
The only non-trivial issue here is the size of the new hashtable.
It seemed reasonable to make it match the size of the port-only
hashtable (= INET_LHTABLE_SIZE) that was used previously. Other
parameters to inet_hashinfo2_init() match those used in TCP.
Tested: syzcaller issues fixed; the second patch in the patchset
tests that DCCP lookups work correctly.
Fixes: d9fbc7f6431f "net: tcp: prefer listeners bound to an address"
Reported-by: syzcaller <syzkaller@googlegroups.com>
Signed-off-by: Peter Oskolkov <posk@google.com>
---
net/dccp/proto.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/net/dccp/proto.c b/net/dccp/proto.c
index 658cd32bb7b37..be0b223aa8625 100644
--- a/net/dccp/proto.c
+++ b/net/dccp/proto.c
@@ -1141,6 +1141,9 @@ static int __init dccp_init(void)
goto out_fail;
rc = -ENOBUFS;
inet_hashinfo_init(&dccp_hashinfo);
+ inet_hashinfo2_init(&dccp_hashinfo, "dccp_listen_portaddr_hash",
+ INET_LHTABLE_SIZE, 21, /* one slot per 2 MB*/
+ 0, 64 * 1024);
dccp_hashinfo.bind_bucket_cachep =
kmem_cache_create("dccp_bind_bucket",
sizeof(struct inet_bind_bucket), 0,
--
2.20.0.405.gbc1bbc6f85-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH net-next 2/2] selftests: net: reuseport_addr_any: add DCCP 2018-12-15 22:27 [PATCH net-next 1/2] net: dccp: initialize (addr,port) listening hashtable Peter Oskolkov @ 2018-12-15 22:27 ` Peter Oskolkov 2018-12-16 20:14 ` David Miller 2018-12-16 20:14 ` [PATCH net-next 1/2] net: dccp: initialize (addr,port) listening hashtable David Miller 1 sibling, 1 reply; 5+ messages in thread From: Peter Oskolkov @ 2018-12-15 22:27 UTC (permalink / raw) To: David Miller, netdev; +Cc: Peter Oskolkov, Eric Dumazet, Peter Oskolkov This patch adds coverage of DCCP to reuseport_addr_any selftest. Signed-off-by: Peter Oskolkov <posk@google.com> --- .../selftests/net/reuseport_addr_any.c | 49 ++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/net/reuseport_addr_any.c b/tools/testing/selftests/net/reuseport_addr_any.c index f5e01d989519d..4ac3e24b7cfcf 100644 --- a/tools/testing/selftests/net/reuseport_addr_any.c +++ b/tools/testing/selftests/net/reuseport_addr_any.c @@ -9,6 +9,7 @@ #include <arpa/inet.h> #include <errno.h> #include <error.h> +#include <linux/dccp.h> #include <linux/in.h> #include <linux/unistd.h> #include <stdbool.h> @@ -75,7 +76,16 @@ static void build_rcv_fd(int family, int proto, int *rcv_fds, int count, error(1, errno, "failed to bind receive socket"); if (proto == SOCK_STREAM && listen(rcv_fds[i], 10)) - error(1, errno, "failed to listen on receive port"); + error(1, errno, "tcp: failed to listen on receive port"); + else if (proto == SOCK_DCCP) { + if (setsockopt(rcv_fds[i], SOL_DCCP, + DCCP_SOCKOPT_SERVICE, + &(int) {htonl(42)}, sizeof(int))) + error(1, errno, "failed to setsockopt"); + + if (listen(rcv_fds[i], 10)) + error(1, errno, "dccp: failed to listen on receive port"); + } } } @@ -124,6 +134,11 @@ static int connect_and_send(int family, int proto) if (fd < 0) error(1, errno, "failed to create send socket"); + if (proto == SOCK_DCCP && + setsockopt(fd, SOL_DCCP, DCCP_SOCKOPT_SERVICE, + &(int){htonl(42)}, sizeof(int))) + error(1, errno, "failed to setsockopt"); + if (bind(fd, saddr, sz)) error(1, errno, "failed to bind send socket"); @@ -146,7 +161,7 @@ static int receive_once(int epfd, int proto) if (i < 0) error(1, errno, "epoll_wait failed"); - if (proto == SOCK_STREAM) { + if (proto == SOCK_STREAM || proto == SOCK_DCCP) { fd = accept(ev.data.fd, NULL, NULL); if (fd < 0) error(1, errno, "failed to accept"); @@ -259,6 +274,36 @@ int main(void) for (i = 0; i < 9; ++i) close(rcv_fds[i]); + fprintf(stderr, "---- DCCP IPv4 ----\n"); + build_rcv_fd(AF_INET, SOCK_DCCP, rcv_fds, 2, NULL); + build_rcv_fd(AF_INET6, SOCK_DCCP, rcv_fds + 2, 2, NULL); + build_rcv_fd(AF_INET, SOCK_DCCP, rcv_fds + 4, 1, IP4_ADDR); + build_rcv_fd(AF_INET, SOCK_DCCP, rcv_fds + 5, 2, NULL); + build_rcv_fd(AF_INET6, SOCK_DCCP, rcv_fds + 7, 2, NULL); + test(rcv_fds, 9, AF_INET, SOCK_DCCP, rcv_fds[4]); + for (i = 0; i < 9; ++i) + close(rcv_fds[i]); + + fprintf(stderr, "---- DCCP IPv6 ----\n"); + build_rcv_fd(AF_INET, SOCK_DCCP, rcv_fds, 2, NULL); + build_rcv_fd(AF_INET6, SOCK_DCCP, rcv_fds + 2, 2, NULL); + build_rcv_fd(AF_INET6, SOCK_DCCP, rcv_fds + 4, 1, IP6_ADDR); + build_rcv_fd(AF_INET, SOCK_DCCP, rcv_fds + 5, 2, NULL); + build_rcv_fd(AF_INET6, SOCK_DCCP, rcv_fds + 7, 2, NULL); + test(rcv_fds, 9, AF_INET6, SOCK_DCCP, rcv_fds[4]); + for (i = 0; i < 9; ++i) + close(rcv_fds[i]); + + fprintf(stderr, "---- DCCP IPv4 mapped to IPv6 ----\n"); + build_rcv_fd(AF_INET, SOCK_DCCP, rcv_fds, 2, NULL); + build_rcv_fd(AF_INET6, SOCK_DCCP, rcv_fds + 2, 2, NULL); + build_rcv_fd(AF_INET6, SOCK_DCCP, rcv_fds + 4, 1, IP4_MAPPED6); + build_rcv_fd(AF_INET, SOCK_DCCP, rcv_fds + 5, 2, NULL); + build_rcv_fd(AF_INET6, SOCK_DCCP, rcv_fds + 7, 2, NULL); + test(rcv_fds, 9, AF_INET, SOCK_DCCP, rcv_fds[4]); + for (i = 0; i < 9; ++i) + close(rcv_fds[i]); + fprintf(stderr, "SUCCESS\n"); return 0; } -- 2.20.0.405.gbc1bbc6f85-goog ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net-next 2/2] selftests: net: reuseport_addr_any: add DCCP 2018-12-15 22:27 ` [PATCH net-next 2/2] selftests: net: reuseport_addr_any: add DCCP Peter Oskolkov @ 2018-12-16 20:14 ` David Miller 0 siblings, 0 replies; 5+ messages in thread From: David Miller @ 2018-12-16 20:14 UTC (permalink / raw) To: posk; +Cc: netdev, posk.devel, edumazet From: Peter Oskolkov <posk@google.com> Date: Sat, 15 Dec 2018 14:27:24 -0800 > This patch adds coverage of DCCP to reuseport_addr_any selftest. > > Signed-off-by: Peter Oskolkov <posk@google.com> Applied. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next 1/2] net: dccp: initialize (addr,port) listening hashtable 2018-12-15 22:27 [PATCH net-next 1/2] net: dccp: initialize (addr,port) listening hashtable Peter Oskolkov 2018-12-15 22:27 ` [PATCH net-next 2/2] selftests: net: reuseport_addr_any: add DCCP Peter Oskolkov @ 2018-12-16 20:14 ` David Miller 2018-12-16 20:36 ` David Miller 1 sibling, 1 reply; 5+ messages in thread From: David Miller @ 2018-12-16 20:14 UTC (permalink / raw) To: posk; +Cc: netdev, posk.devel, edumazet, syzkaller From: Peter Oskolkov <posk@google.com> Date: Sat, 15 Dec 2018 14:27:23 -0800 > Commit d9fbc7f6431f "net: tcp: prefer listeners bound to an address" > removes port-only listener lookups. This caused segfaults in DCCP > lookups because DCCP did not initialize the (addr,port) hashtable. > > This patch adds said initialization. > > The only non-trivial issue here is the size of the new hashtable. > It seemed reasonable to make it match the size of the port-only > hashtable (= INET_LHTABLE_SIZE) that was used previously. Other > parameters to inet_hashinfo2_init() match those used in TCP. > > Tested: syzcaller issues fixed; the second patch in the patchset > tests that DCCP lookups work correctly. > > Fixes: d9fbc7f6431f "net: tcp: prefer listeners bound to an address" > Reported-by: syzcaller <syzkaller@googlegroups.com> > Signed-off-by: Peter Oskolkov <posk@google.com> Applied. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next 1/2] net: dccp: initialize (addr,port) listening hashtable 2018-12-16 20:14 ` [PATCH net-next 1/2] net: dccp: initialize (addr,port) listening hashtable David Miller @ 2018-12-16 20:36 ` David Miller 0 siblings, 0 replies; 5+ messages in thread From: David Miller @ 2018-12-16 20:36 UTC (permalink / raw) To: posk; +Cc: netdev, posk.devel, edumazet, syzkaller From: David Miller <davem@davemloft.net> Date: Sun, 16 Dec 2018 12:14:50 -0800 (PST) > From: Peter Oskolkov <posk@google.com> > Date: Sat, 15 Dec 2018 14:27:23 -0800 > >> Commit d9fbc7f6431f "net: tcp: prefer listeners bound to an address" >> removes port-only listener lookups. This caused segfaults in DCCP >> lookups because DCCP did not initialize the (addr,port) hashtable. >> >> This patch adds said initialization. >> >> The only non-trivial issue here is the size of the new hashtable. >> It seemed reasonable to make it match the size of the port-only >> hashtable (= INET_LHTABLE_SIZE) that was used previously. Other >> parameters to inet_hashinfo2_init() match those used in TCP. >> >> Tested: syzcaller issues fixed; the second patch in the patchset >> tests that DCCP lookups work correctly. >> >> Fixes: d9fbc7f6431f "net: tcp: prefer listeners bound to an address" >> Reported-by: syzcaller <syzkaller@googlegroups.com> >> Signed-off-by: Peter Oskolkov <posk@google.com> > > Applied. I had to revert, please test with dccp being modular: ERROR: "inet_hashinfo2_init" [net/dccp/dccp.ko] undefined! make[1]: *** [scripts/Makefile.modpost:92: __modpost] Error 1 ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-12-16 20:36 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2018-12-15 22:27 [PATCH net-next 1/2] net: dccp: initialize (addr,port) listening hashtable Peter Oskolkov 2018-12-15 22:27 ` [PATCH net-next 2/2] selftests: net: reuseport_addr_any: add DCCP Peter Oskolkov 2018-12-16 20:14 ` David Miller 2018-12-16 20:14 ` [PATCH net-next 1/2] net: dccp: initialize (addr,port) listening hashtable David Miller 2018-12-16 20:36 ` David Miller
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).