cve: new regression test-case for CVE-2018-5803
PATCH 1/1 cve: new regression test-case for CVE-2018-5803
There are two test-cases in runtest/cve:
* cve-2018-5803 - for over-sized INIT_ACK packet
* cve-2018-5803_2 - for over-sized INIT packet
--- include/lapi/socket.h | 4 + runtest/cve | 2 + testcases/cve/.gitignore | 1 + testcases/cve/cve-2018-5803.c | 124 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 131 insertions(+), 0 deletions(-) create mode 100644 testcases/cve/cve-2018-5803.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
@@ -30,3 +30,5 @@ cve-2017-17807 request_key04 cve-2017-1000364 stack_clash cve-2017-5754 meltdown cve-2017-17052 cve-2017-17052 +cve-2018-5803 cve-2018-5803 +cve-2018-5803_2 cve-2018-5803 -a 10000
testcases/cve/.gitignore +1 -0
@@ -12,3 +12,4 @@ cve-2017-5669 meltdown stack_clash cve-2017-17052 +cve-2018-5803
testcases/cve/cve-2018-5803.c new file +124 -0
124 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 1/1 cve: new regression test-case for CVE-2018-5803
Hi Alexey,
Quoted 18 lines
There are two test-cases in runtest/cve:
* cve-2018-5803 - for over-sizedINIT_ACKpacket
* cve-2018-5803_2 - for over-sized INIT packetSigned-off-by Alexey Kodanev <[email protected]>--- include/lapi/socket.h | 4 + runtest/cve | 2 + testcases/cve/.gitignore | 1 + testcases/cve/cve-2018-5803.c | 124 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 131 insertions(+), 0 deletions(-) create mode 100644 testcases/cve/cve-2018-5803.cinclude/lapi/socket.h +0
-0
include/lapi/socket.h line 50
Quoted 6 lines
include/lapi/socket.h +3
-0@@ -45,6 +45,10 @@# define SOCK_CLOEXEC 02000000#endif +#ifndef SOL_SCTP +# define SOL_SCTP 132 +#endif
I suppose you deliberately don't include linux/socket.h where SOL_SCTP is defined.
Quoted 64 lines
include/lapi/socket.h +1
-0+#ifndef SOL_UDPLITE # define SOL_UDPLITE 136/* UDP-Lite (RFC 3828) */ #endif runtest/cve +2
-0@@ -30,3 +30,5 @@ cve-2017-17807 request_key04 cve-2017-1000364 stack_clash cve-2017-5754 meltdown cve-2017-17052 cve-2017-17052 +cve-2018-5803 cve-2018-5803 +cve-2018-5803_2 cve-2018-5803 -a 10000testcases/cve/.gitignore +1
-0@@ -12,3 +12,4 @@ cve-2017-5669 meltdown stack_clash cve-2017-17052 +cve-2018-5803testcases/cve/cve-2018-5803.c new file +35
-0@@ -0,0 +1,124 @@ +/* +* 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" +
testcases/cve/cve-2018-5803.c line 45
Quoted 10 lines
testcases/cve/cve-2018-5803.c new file +10
-0+static int port; +static int sfd, cfd; +static struct sockaddr_in6 rmt, loc; + +static char *addr_param; +static int addr_num =3273 ; + +#ifndef SCTP_SOCKOPT_BINDX_ADD +# define SCTP_SOCKOPT_BINDX_ADD 100 +#endif
I suppose you deliberately don't include linux/sctp.h, where SCTP_SOCKOPT_BINDX_ADD defined.
Quoted 51 lines
testcases/cve/cve-2018-5803.c new file +51
-0+ +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) {
testcases/cve/cve-2018-5803.c line 106
Quoted 10 lines
testcases/cve/cve-2018-5803.c new file +10
-0+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));
Minor nit: you can use SAFE_CONNECT().
Quoted 8 lines
testcases/cve/cve-2018-5803.c new file +8
-0+ +SAFE_KILL (pid,SIGKILL ); +SAFE_WAITPID (pid,NULL ,0 ); + +tst_res (TPASS ,"test doesn't cause crash" ); +} + +static struct tst_option options[] = {
testcases/cve/cve-2018-5803.c line 124
Quoted 10 lines
testcases/cve/cve-2018-5803.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 +};
LGTM.
Found one BROK on EINVAL on setsockopt(), most of older kernels in VM don't crash, bug generate heavy load.
Kind regards,
Petr
PATCH 1/1 cve: new regression test-case for CVE-2018-5803
Quoted 23 lines · Petr Vorel
Hi Alexey,
Quoted 20 lines
There are two test-cases in runtest/cve:
* cve-2018-5803 - for over-sizedINIT_ACKpacket
* cve-2018-5803_2 - for over-sized INIT packetSigned-off-by Alexey Kodanev <[email protected]>--- include/lapi/socket.h | 4 + runtest/cve | 2 + testcases/cve/.gitignore | 1 + testcases/cve/cve-2018-5803.c | 124 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 131 insertions(+), 0 deletions(-) create mode 100644 testcases/cve/cve-2018-5803.cinclude/lapi/socket.h +0
-0@@ -45,6 +45,10 @@# define SOCK_CLOEXEC 02000000#endif
Quoted 5 lines
include/lapi/socket.h line 49
Quoted 3 lines
include/lapi/socket.h +3
-0+#ifndef SOL_SCTP +# define SOL_SCTP 132 +#endif I suppose you deliberately don't include
linux/socket.hwhereSOL_SCTPis defined.
Hi Petr,
Do you think we should include linux headers for consistency?
Quoted 6 lines
Quoted 6 lines
include/lapi/socket.h +1
-0+#ifndef SOL_UDPLITE # define SOL_UDPLITE 136/* UDP-Lite (RFC 3828) */ #endif runtest/cve +0
-0
...
Quoted 5 lines
Quoted 5 lines
runtest/cve +5
-0+ + if (!pid) { + struct sockaddr_in6 addr6; + socklen_t addr_size = sizeof(addr6); +
Quoted 9 lines
runtest/cve
Quoted 7 lines
runtest/cve +7
-0+ 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));Minor nit: you can use
SAFE_CONNECT().
No, it should fail in the kernels with the fix, on the second test-case when we get over-sized INIT chunk, I think ENOMEM returns in that case.
Quoted 20 lines
Quoted 8 lines
runtest/cve +8
-0+ + SAFE_KILL(pid, SIGKILL); + SAFE_WAITPID(pid, NULL, 0); + + tst_res(TPASS, "test doesn't cause crash"); +} + +static struct tst_option options[] = {runtest/cve
Quoted 10 lines
runtest/cve +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 +};LGTM.
Quoted 3 lines
Tested-by Petr Vorel <[email protected]>Found one BROK on EINVAL on
setsockopt(), most of older kernels in VM don't crash, bug generate heavy load.
Does it happen with a single address parameter? We could also lower parameter size in the second test, e.g. from 10000 to 4000.
Also change SOCK_STREAM to SOCK_SEQPACKET
testcases/cve/cve-2018-5803.c +1 -1
@@ -63,7 +63,7 @@ static void setup_client(void)struct sockaddr_in6 addr_buf[addr_num];int i; - cfd =SAFE_SOCKET (AF_INET6 ,SOCK_STREAM ,IPPROTO_SCTP ); + cfd =SAFE_SOCKET (AF_INET6 ,SOCK_SEQPACKET ,IPPROTO_SCTP ); rmt.sin6_family =AF_INET6 ; rmt.sin6_addr = in6addr_loopback; rmt.sin6_port =htons (port);
I could also add IPv4 version...
Thanks,
Alexey
PATCH 1/1 cve: new regression test-case for CVE-2018-5803
Hi Alexey,
Quoted 1 line
Do you think we should include linux headers for consistency?
Yes, although both SOL_SCTP and SOL_UDPLITE are defined the same for all architectures and probably never change, I'd include the header.
Actually SOL_UDPLITE is already defined in include/lapi/socket.h.
This file was added as wrapper for values <sys/socket.h> in aac9d1f0e by Xiao Yang, I included sys/socket.h in that lapi file in 3fd5746a8
Later you added in 0bc572423 constants from linux/socket.h.
I don't know what is a best practise, but I'd include both files in include/lapi/socket.h (they don't conflict) (or don't include neither of them):
#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h> #endif
#ifdef HAVE_LINUX_SOCKET_H
# include <linux/socket.h> #endif
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
+
#ifndefSOL_UDPLITE# define SOL_UDPLITE 136 /* UDP-Lite (RFC 3828) */ #endif
As I wrote, this is already defined in include/lapi/socket.h.
Quoted 10 lines
Quoted 2 lines
Quoted 2 lines
runtest/cve +0
-0...
Quoted 3 lines
runtest/cve
Quoted 2 lines
runtest/cve +2
-0+ fcntl(cfd, F_SETFL, O_NONBLOCK); + connect(cfd, (struct sockaddr *)&rmt, sizeof(rmt));Minor nit: you can use
SAFE_CONNECT().No, it should fail in the kernels with the fix, on the second test-case when we get over-sized INIT chunk, I think ENOMEM returns in that case.
Oh sorry, understand.
Kind regards,
Petr
PATCH 1/1 cve: new regression test-case for CVE-2018-5803
In reply to Alexey KodanevHi Alexey,
Quoted 7 lines
Quoted 4 lines
LGTM.
Tested-by Petr Vorel <[email protected]>Found one BROK on EINVAL on
setsockopt(), most of older kernels in VM don't crash, bug generate heavy load.Does it happen with a single address parameter? We could also lower parameter size in the second test, e.g. from 10000 to 4000.
I didn't notice before that it actually calls BUG() in skb_put(), test does not end. Adding -a 4000 does not help.
Quoted 17 lines
Also change
SOCK_STREAMtoSOCK_SEQPACKETtestcases/cve/cve-2018-5803.c +1
-1@@ -63,7 +63,7 @@ static void setup_client(void)struct sockaddr_in6 addr_buf[addr_num];int i; - cfd =SAFE_SOCKET (AF_INET6 ,SOCK_STREAM ,IPPROTO_SCTP ); + cfd =SAFE_SOCKET (AF_INET6 ,SOCK_SEQPACKET ,IPPROTO_SCTP ); rmt.sin6_family =AF_INET6 ; rmt.sin6_addr = in6addr_loopback; rmt.sin6_port =htons (port);
Quoted 1 line
I could also add IPv4 version...
I have no idea if it's useful.
Quoted 2 lines
Thanks,
Alexey
Kind regards,
Petr
PATCH 1/1 cve: new regression test-case for CVE-2018-5803
In reply to Alexey KodanevHello Alexey,
Quoted 3 lines · Alexey Kodanev
There are two test-cases in runtest/cve:
* cve-2018-5803 - for over-sizedINIT_ACKpacket
* cve-2018-5803_2 - for over-sized INIT packet
Naming tests purely after a CVE number seems to have been a mistake on my part because people are unable to recognise them. Could this be given a more descriptive name and location (i.e something with net and sctp in the name?). Of course it should still go in the cve runtest file.
Quoted 175 lines
Signed-off-by Alexey Kodanev <[email protected]>--- include/lapi/socket.h | 4 + runtest/cve | 2 + testcases/cve/.gitignore | 1 + testcases/cve/cve-2018-5803.c | 124 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 131 insertions(+), 0 deletions(-) create mode 100644 testcases/cve/cve-2018-5803.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@@ -30,3 +30,5 @@ cve-2017-17807 request_key04 cve-2017-1000364 stack_clash cve-2017-5754 meltdown cve-2017-17052 cve-2017-17052 +cve-2018-5803 cve-2018-5803 +cve-2018-5803_2 cve-2018-5803 -a 10000testcases/cve/.gitignore +1
-0@@ -12,3 +12,4 @@ cve-2017-5669 meltdown stack_clash cve-2017-17052 +cve-2018-5803testcases/cve/cve-2018-5803.c new file +124
-1@@ -0,0 +1,124 @@ +/* +* 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" + +static int port; +static int sfd, cfd; +static struct sockaddr_in6 rmt, loc; + +static char *addr_param; +static int addr_num =3273 ; + +#ifndef SCTP_SOCKOPT_BINDX_ADD +# define SCTP_SOCKOPT_BINDX_ADD 100 +#endif + +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[] = { + {"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 +}; --
Quoted 1 line
1.7.1
--
Thank you,
Richard.
PATCH 1/1 cve: new regression test-case for CVE-2018-5803
Quoted 4 lines · Richard Palethorpe
Hello Alexey,
Alexey Kodanev writes:
Quoted 8 lines
Quoted 3 lines
There are two test-cases in runtest/cve:
* cve-2018-5803 - for over-sizedINIT_ACKpacket
* cve-2018-5803_2 - for over-sized INIT packetNaming tests purely after a CVE number seems to have been a mistake on my part because people are unable to recognise them. Could this be given a more descriptive name and location (i.e something with net and sctp in the name?). Of course it should still go in the cve runtest file.
Hi Richard,
Sure, I'll move it to testcases/network/sctp/ and change the file name.
Thanks,
Alexey