sctp: add new regression test for CVE-2018-5803
v2 cover sctp: add new regression test for CVE-2018-5803
* create lapi/sctp.h header and define SCTP_SOCKOPT_BINDX_ADD if there is no linux/sctp.h.
* add new test to network/sctp for over-sized SCTP chunk.
Alexey Kodanev (2):
include/lapi: add sctp.h
sctp: new regression test sctp_big_chunk for CVE-2018-5803
configure.ac | 1 + include/lapi/sctp.h | 29 ++++++++ include/lapi/socket.h | 4 + runtest/cve | 2 + testcases/network/.gitignore | 1 + testcases/network/sctp/Makefile | 2 +- testcases/network/sctp/sctp_big_chunk.c | 121 +++++++++++++++++++++++++++++++ 7 files changed, 159 insertions(+), 1 deletions(-) create mode 100644 include/lapi/sctp.h create mode 100644 testcases/network/sctp/sctp_big_chunk.c
PATCH v2 1/2 include/lapi: add sctp.h
---
v2: include linux/sctp.h header and check it in the configure
configure.ac | 1 + include/lapi/sctp.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 0 deletions(-) create mode 100644 include/lapi/sctp.h
configure.ac +1 -0
@@ -44,6 +44,7 @@ AC_CHECK_HEADERS([ \ linux/mempolicy.h \ linux/module.h \ linux/netlink.h \ + linux/sctp.h \ mm.h \ pthread.h \ sys/epoll.h \
include/lapi/sctp.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* Copyright (c) 2018 Oracle and/or its affiliates. +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef LAPI_SCTP_H__ +#define LAPI_SCTP_H__ + +#ifdef HAVE_LINUX_SCTP_H +# include <linux/sctp.h> +#endif + +#ifndef SCTP_SOCKOPT_BINDX_ADD +# define SCTP_SOCKOPT_BINDX_ADD 100 +#endif + +#endif /* LAPI_SCTP_H__ */
Signature · 1 line
1.7.1
PATCH v2 1/2 include/lapi: add sctp.h
Quoted 46 lines
Signed-off-by Alexey Kodanev <[email protected]>---
v2: includelinux/sctp.hheader and check it in the configureconfigure.ac | 1 + include/lapi/sctp.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 0 deletions(-) create mode 100644 include/lapi/sctp.hconfigure.ac +1
-0@@ -44,6 +44,7 @@ AC_CHECK_HEADERS([ \ linux/mempolicy.h \ linux/module.h \ linux/netlink.h \ + linux/sctp.h \ mm.h \ pthread.h \ sys/epoll.h \include/lapi/sctp.h new file +19
-0@@ -0,0 +1,29 @@ +/* +* Copyright (c) 2018 Oracle and/or its affiliates. +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef LAPI_SCTP_H__ +#define LAPI_SCTP_H__
include/lapi/sctp.h line 29
Quoted 10 lines
include/lapi/sctp.h new file +10
-0+ +#ifdef HAVE_LINUX_SCTP_H +# include <linux/sctp.h> +#endif + +#ifndef SCTP_SOCKOPT_BINDX_ADD +# define SCTP_SOCKOPT_BINDX_ADD 100 +#endif + +#endif /* LAPI_SCTP_H__ */
BTW SCTP_SOCKOPT_BINDX_ADD is defined in both <linux/sctp.h> and <netinet/sctp.h>, so if we ever in future want to have some definitions from netinet/sctp.h, I'd be to create special file include/lapi/netinet_sctp.h (the same like include/lapi/netinet_in.h - taking that default is for "kernel/").
And we have included netinet/sctp.h in sources (utils/sctp/include/netinet/sctp.h), IMHO not good idea to have common headers in our sources.
Kind regards,
Petr
PATCH v2 1/2 include/lapi: add sctp.h
Quoted 3 lines · Petr Vorel
Quoted 3 lines
Signed-off-by Alexey Kodanev <[email protected]>---
v2: includelinux/sctp.hheader and check it in the configure
Applied the patch-set.
Quoted 5 lines
BTW
SCTP_SOCKOPT_BINDX_ADDis defined in both <linux/sctp.h> and <netinet/sctp.h>, so if we ever in future want to have some definitions fromnetinet/sctp.h, I'd be to create special fileinclude/lapi/netinet_sctp.h(the same likeinclude/lapi/netinet_in.h- taking that default is for "kernel/").
I think if we have netinet/sctp.h it should take precedences over linux/sctp.h. In OL7 it is provided by optional lksctp-tools-devel package.
Thanks,
Alexey
Quoted 9 lines
And we have included
netinet/sctp.hin sources (utils/sctp/include/netinet/sctp.h), IMHO not good idea to have common headers in our sources.Kind regards,
Petr
PATCH v2 1/2 include/lapi: add sctp.h
Hi Alexey,
Quoted 9 lines
Quoted 4 lines
BTW
SCTP_SOCKOPT_BINDX_ADDis defined in both <linux/sctp.h> and <netinet/sctp.h>, so if we ever in future want to have some definitions fromnetinet/sctp.h, I'd be to create special fileinclude/lapi/netinet_sctp.h(the same likeinclude/lapi/netinet_in.h- taking that default is for "kernel/").I think if we have
netinet/sctp.hit should take precedences overlinux/sctp.h. In OL7 it is provided by optional lksctp-tools-devel package.
But linux/sctp.h has much more definitions than netinet/sctp.h and we use some kernel specific definitions (e.g. SOL_UDPLITE is just in linux/sctp.h, SOL_SCTP is in both).
Quoted 2 lines
Thanks,
Alexey
Kind regards,
Petr
PATCH v2 2/2 sctp: new regression test sctp_big_chunk for CVE-2018-5803
In reply to Alexey KodanevAdded two test-cases in runtest/cve:
* cve-2018-5803 - over-sized INIT_ACK packet
* cve-2018-5803_2 - over-sized INIT packet
---
v2: rename the test file and move it to testcases/network/sctp/
include/lapi/socket.h | 4 + runtest/cve | 2 + testcases/network/.gitignore | 1 + testcases/network/sctp/Makefile | 2 +- testcases/network/sctp/sctp_big_chunk.c | 121 +++++++++++++++++++++++++++++++ 5 files changed, 129 insertions(+), 1 deletions(-) create mode 100644 testcases/network/sctp/sctp_big_chunk.c
include/lapi/socket.h +4 -0
@@ -45,6 +45,10 @@# define SOCK_CLOEXEC 02000000#endif +#ifndef SOL_SCTP +# define SOL_SCTP 132 +#endif +#ifndef SOL_UDPLITE # define SOL_UDPLITE 136/* UDP-Lite (RFC 3828) */ #endif
runtest/cve +2 -0
@@ -32,3 +32,5 @@ cve-2017-5754 meltdown cve-2017-17052 cve-2017-17052 cve-2017-16939 cve-2017-16939 cve-2017-17053 cve-2017-17053 +cve-2018-5803 sctp_big_chunk +cve-2018-5803_2 sctp_big_chunk -a 10000
testcases/network/.gitignore +1 -0
@@ -22,6 +22,7 @@ /nfsv4/locks/locktests /rpc/basic_tests/rpc01/rpc1 /rpc/basic_tests/rpc01/rpc_server +/sctp/sctp_big_chunk /sockets/ltpClient /sockets/ltpServer /stress/ns-tools/ns-icmp_redirector
testcases/network/sctp/Makefile +1 -1
@@ -15,7 +15,7 @@ top_srcdir ?= ../../.. -include $(top_srcdir)/include/mk/env_pre.mk +include $(top_srcdir)/include/mk/testcases.mk INSTALL_TARGETS := sctp01.sh
testcases/network/sctp/sctp_big_chunk.c new file +121 -0
121 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v2 2/2 sctp: new regression test sctp_big_chunk for CVE-2018-5803
Hi Alexey,
Quoted 183 lines
Added two test-cases in runtest/cve:
* cve-2018-5803 - over-sizedINIT_ACKpacket
* cve-2018-5803_2 - over-sized INIT packetSigned-off-by Alexey Kodanev <[email protected]>---
v2: rename the test file and move it to testcases/network/sctp/include/lapi/socket.h | 4 + runtest/cve | 2 + testcases/network/.gitignore | 1 + testcases/network/sctp/Makefile | 2 +- testcases/network/sctp/sctp_big_chunk.c | 121 +++++++++++++++++++++++++++++++ 5 files changed, 129 insertions(+), 1 deletions(-) create mode 100644 testcases/network/sctp/sctp_big_chunk.cinclude/lapi/socket.h +4
-0@@ -45,6 +45,10 @@# define SOCK_CLOEXEC 02000000#endif +#ifndef SOL_SCTP +# define SOL_SCTP 132 +#endif +#ifndef SOL_UDPLITE # define SOL_UDPLITE 136/* UDP-Lite (RFC 3828) */ #endif runtest/cve +2
-0@@ -32,3 +32,5 @@ cve-2017-5754 meltdown cve-2017-17052 cve-2017-17052 cve-2017-16939 cve-2017-16939 cve-2017-17053 cve-2017-17053 +cve-2018-5803 sctp_big_chunk +cve-2018-5803_2 sctp_big_chunk -a 10000testcases/network/.gitignore +1
-0@@ -22,6 +22,7 @@ /nfsv4/locks/locktests /rpc/basic_tests/rpc01/rpc1 /rpc/basic_tests/rpc01/rpc_server +/sctp/sctp_big_chunk /sockets/ltpClient /sockets/ltpServer /stress/ns-tools/ns-icmp_redirectortestcases/network/sctp/Makefile +1
-1@@ -15,7 +15,7 @@ top_srcdir ?= ../../.. -include $(top_srcdir)/include/mk/env_pre.mk +include $(top_srcdir)/include/mk/testcases.mk INSTALL_TARGETS := sctp01.shtestcases/network/sctp/sctp_big_chunk.c new file +111
-0@@ -0,0 +1,121 @@ +/* +* Copyright (c) 2018 Oracle and/or its affiliates. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License, or (at your option) any later version. +* +* This program is distributed in the hope that it would be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +* +* Regression test-case for the crash caused by over-sized SCTP chunk, +* fixed by upstream commit 07f2c7ab6f8d ("sctp: verify size of a new +* chunk in _sctp_make_chunk()") +*/ + +#include <stdlib.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <netdb.h> +#include <sys/syscall.h> +#include <fcntl.h> + +#include "tst_test.h" +#include "tst_safe_stdio.h" +#include "lapi/netinet_in.h" +#include "lapi/socket.h" +#include "lapi/sctp.h" + +static int port; +static int sfd, cfd; +static struct sockaddr_in6 rmt, loc; + +static char *addr_param; +static int addr_num =3273 ; + +static void setup_server (void ) +{ + loc.sin6_family =AF_INET6 ; + loc.sin6_addr = in6addr_loopback; + + sfd =SAFE_SOCKET (AF_INET6 ,SOCK_STREAM ,IPPROTO_SCTP ); +SAFE_BIND (sfd, (struct sockaddr *)&loc,sizeof (loc)); + + port =TST_GETSOCKPORT (sfd); +tst_res (TINFO ,"sctp server listen on %d" , port); + +SAFE_LISTEN (sfd,1 ); +} + +static void setup_client (void ) +{ +struct sockaddr_in6 addr_buf[addr_num]; +int i; + + cfd =SAFE_SOCKET (AF_INET6 ,SOCK_STREAM ,IPPROTO_SCTP ); + rmt.sin6_family =AF_INET6 ; + rmt.sin6_addr = in6addr_loopback; + rmt.sin6_port =htons (port); + +tst_res (TINFO ,"bind %d additional IP addresses" , addr_num); + +memset (addr_buf,0 ,sizeof (addr_buf)); +for (i =0 ; i < addr_num; ++i) { + addr_buf[i].sin6_family =AF_INET6 ; + addr_buf[i].sin6_addr = in6addr_loopback; + } + +SAFE_SETSOCKOPT (cfd,SOL_SCTP ,SCTP_SOCKOPT_BINDX_ADD , addr_buf, +sizeof (addr_buf)); +} + +static void setup (void ) +{ +if (tst_parse_int (addr_param, &addr_num,1 ,INT_MAX )) +tst_brk (TBROK ,"wrong address number '%s'" , addr_param); + +setup_server (); +setup_client (); +} + +static void run (void ) +{ +int pid =SAFE_FORK (); + +if (!pid) { +struct sockaddr_in6 addr6; +socklen_t addr_size =sizeof (addr6); + +if (accept (sfd, (struct sockaddr *)&addr6, &addr_size) <0 ) +tst_brk (TBROK |TERRNO ,"accept() failed" ); +exit (0 ); + } + +fcntl (cfd,F_SETFL ,O_NONBLOCK ); +connect (cfd, (struct sockaddr *)&rmt,sizeof (rmt)); + +SAFE_KILL (pid,SIGKILL ); +SAFE_WAITPID (pid,NULL ,0 ); + +tst_res (TPASS ,"test doesn't cause crash" ); +} + +static struct tst_option options[] = {
testcases/network/sctp/sctp_big_chunk.c line 121
Quoted 10 lines
testcases/network/sctp/sctp_big_chunk.c new file +10
-0+ {"a:", &addr_param, "-a number of additional IP address params"}, + {NULL, NULL, NULL} +}; + +static struct tst_test test = { + .setup = setup, + .forks_child =1 , + .test_all = run, + .options = options +};