Add setsockopt08, CVE-2021-22555
PATCH 1/1 Add setsockopt08, CVE-2021-22555
This is a copy and paste of Nicolai's reproducer. The main difference is that I moved some code around. Of course I also used LTP library features, but essentially it works the same.
There are some hard coded values which I do not like. I guess these could be calculated or varied somehow. However I struggle to understand what the kernel is doing. This perhaps needs more investigation. We could try generalising this test and setsockopt03.
---
runtest/cve | 1 +
runtest/syscalls | 1 + .../kernel/syscalls/setsockopt/.gitignore | 1 + .../kernel/syscalls/setsockopt/setsockopt08.c | 151 ++++++++++++++++++ 4 files changed, 154 insertions(+) create mode 100644 testcases/kernel/syscalls/setsockopt/setsockopt08.c
runtest/cve +1 -0
@@ -65,4 +65,5 @@ cve-2020-14416 pty03 cve-2020-25705 icmp_rate_limit01 cve-2020-29373 io_uring02 cve-2021-3444 bpf_prog05 +cve-2021-22555 setsockopt08 -i 100 cve-2021-26708 vsock01
runtest/syscalls +1 -0
@@ -1378,6 +1378,7 @@ setsockopt04 setsockopt04 setsockopt05 setsockopt05 setsockopt06 setsockopt06 setsockopt07 setsockopt07 +setsockopt08 setsockopt08 settimeofday01 settimeofday01 settimeofday02 settimeofday02
testcases/kernel/syscalls/setsockopt/.gitignore +1 -0
@@ -5,3 +5,4 @@ /setsockopt05 /setsockopt06 /setsockopt07 +/setsockopt08
testcases/kernel/syscalls/setsockopt/setsockopt08.c new file +151 -0
151 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v2 1/2 Add lapi/ip_tables.h and use it in setsockopt03
---
Oops forgot to add the file below.
V2:
* Add ip_tables.h compatability header
include/lapi/ip_tables.h | 46 +++++++++++++++++++ .../kernel/syscalls/setsockopt/setsockopt03.c | 39 +--------------- 2 files changed, 48 insertions(+), 37 deletions(-) create mode 100644 include/lapi/ip_tables.h
include/lapi/ip_tables.h new file +46 -0
@@ -0,0 +1,46 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#ifndef LAPI_IP_TABLES__ +#define LAPI_IP_TABLES__ + +#include "config.h" + +#include <linux/netfilter_ipv4/ip_tables.h> + +#ifndef HAVE_STRUCT_XT_ENTRY_MATCH +struct xt_entry_match { +union { +struct { +uint16_t match_size; +char name[29 ]; +uint8_t revision; + } user; +struct { +uint16_t match_size; +void *match; + } kernel; +uint16_t match_size; + } u; +unsigned char data[0 ]; +}; +#endif + +#ifndef HAVE_STRUCT_XT_ENTRY_TARGET +struct xt_entry_target { +union { +struct { +uint16_t target_size; +char name[29 ]; +uint8_t revision; + } user; +struct { +uint16_t target_size; +void *target; + } kernel; +uint16_t target_size; + } u; +unsigned char data[0 ]; +}; +#endif + +#endif
testcases/kernel/syscalls/setsockopt/setsockopt03.c +2 -37
@@ -21,12 +21,13 @@#include <netinet/in.h> #include <net/if.h> #include <limits.h> -#include <linux/netfilter_ipv4/ip_tables.h> #include "tst_test.h" #include "tst_safe_net.h" #include "tst_kernel.h" +#include "lapi/ip_tables.h" +#define TOO_SMALL_OFFSET 74#define OFFSET_OVERWRITE 0xFFFF#define NEXT_OFFSET (sizeof(struct ipt_entry) \
@@ -34,42 +35,6 @@ + sizeof(struct xt_entry_target))#define PADDING (OFFSET_OVERWRITE - NEXT_OFFSET) -#ifndef HAVE_STRUCT_XT_ENTRY_MATCH -struct xt_entry_match { -union { -struct { -uint16_t match_size; -char name[29 ]; -uint8_t revision; - } user; -struct { -uint16_t match_size; -void *match; - } kernel; -uint16_t match_size; - } u; -unsigned char data[0 ]; -}; -#endif - -#ifndef HAVE_STRUCT_XT_ENTRY_TARGET -struct xt_entry_target { -union { -struct { -uint16_t target_size; -char name[29 ]; -uint8_t revision; - } user; -struct { -uint16_t target_size; -void *target; - } kernel; -uint16_t target_size; - } u; -unsigned char data[0 ]; -}; -#endif -struct payload {struct ipt_replace repl;struct ipt_entry ent;
Signature · 1 line
2.31.1
PATCH v2 2/2 Add setsockopt08, CVE-2021-22555
This is a copy and paste of Nicolai's reproducer. The main difference is that I moved some code around. Of course I also used LTP library features, but essentially it works the same.
There are some hard coded values which I do not like. I guess these could be calculated or varied somehow. However I struggle to understand what the kernel is doing. This perhaps needs more investigation. We could try generalising this test and setsockopt03.
--- runtest/cve | 1 + runtest/syscalls | 1 + .../kernel/syscalls/setsockopt/.gitignore | 1 + .../kernel/syscalls/setsockopt/setsockopt08.c | 151 ++++++++++++++++++ 4 files changed, 154 insertions(+) create mode 100644 testcases/kernel/syscalls/setsockopt/setsockopt08.c
runtest/cve +1 -0
@@ -65,4 +65,5 @@ cve-2020-14416 pty03 cve-2020-25705 icmp_rate_limit01 cve-2020-29373 io_uring02 cve-2021-3444 bpf_prog05 +cve-2021-22555 setsockopt08 -i 100 cve-2021-26708 vsock01
runtest/syscalls +1 -0
@@ -1378,6 +1378,7 @@ setsockopt04 setsockopt04 setsockopt05 setsockopt05 setsockopt06 setsockopt06 setsockopt07 setsockopt07 +setsockopt08 setsockopt08 settimeofday01 settimeofday01 settimeofday02 settimeofday02
testcases/kernel/syscalls/setsockopt/.gitignore +1 -0
@@ -5,3 +5,4 @@ /setsockopt05 /setsockopt06 /setsockopt07 +/setsockopt08
testcases/kernel/syscalls/setsockopt/setsockopt08.c new file +151 -0
151 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v2 2/2 Add setsockopt08, CVE-2021-22555
Hi,
since this vulnerability is in the compat syscall wrappers, you should also copy the arch bits check from setsockopt03 setup().
Quoted 8 lines · Richard Palethorpe via ltp
This is a copy and paste of Nicolai's reproducer. The main difference is that I moved some code around. Of course I also used LTP library features, but essentially it works the same.
There are some hard coded values which I do not like. I guess these could be calculated or varied somehow. However I struggle to understand what the kernel is doing. This perhaps needs more investigation. We could try generalising this test and setsockopt03
Signature · 7 lines
Martin Doucha [email protected] QA Engineer for Software Maintenance SUSE LINUX, s.r.o. CORSO IIa Krizikova 148/34 186 00 Prague 8 Czech Republic
PATCH v2 2/2 Add setsockopt08, CVE-2021-22555
Hi,
Quoted 3 lines · Martin Doucha
Hi,
since this vulnerability is in the compat syscall wrappers, you should also copy the arch bits check from setsockopt03setup().
+1
Will roll another patch after a delay.
Quoted 10 lines · Richard Palethorpe via ltp
Quoted 8 lines
This is a copy and paste of Nicolai's reproducer. The main difference is that I moved some code around. Of course I also used LTP library features, but essentially it works the same.
There are some hard coded values which I do not like. I guess these could be calculated or varied somehow. However I struggle to understand what the kernel is doing. This perhaps needs more investigation. We could try generalising this test and setsockopt03
Signature · 2 lines
Thank you, Richard.
PATCH v3 1/3 API: TST_EXP_FAIL: Allow passing when errno is not checked
Judging by the existing usage of TST_EXP_FAIL(..., 0, ...) in finit_module02. We want to pass if errno == 0 otherwise the test will not return a result.
This is also less surprising than giving errno == 0 a dual meaning.
This also changes the trailing '\' indentation to tabs. However this is correct and the rest of the file is wrong.
---
V3:
* Add fix for TST_EXP_FAIL which prevented the test from passing on a non buggy system.
* TCONF but continue on non 32-bit compat mode
* Add Fixes trailer
V2:
* Add mising lapi header
include/tst_test_macros.h | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-)
include/tst_test_macros.h +9 -11
@@ -137,17 +137,15 @@ extern void *TST_RET_PTR;break ; \ } \ \ - if (ERRNO) { \ - if (TST_ERR == ERRNO) { \ - TST_MSG_(TPASS | TTERRNO, " ", \ - #SCALL, ##__VA_ARGS__); \ - TST_PASS = 1; \ - } else { \ - TST_MSGP_(TFAIL | TTERRNO, " expected %s", \ - tst_strerrno(ERRNO), \ - #SCALL, ##__VA_ARGS__); \ - } \ - } \ +if (!ERRNO ||TST_ERR ==ERRNO ) { \ + TST_MSG_(TPASS | TTERRNO, " ", \ +#SCALL , ##__VA_ARGS__); \ + TST_PASS = 1; \ + } else { \ + TST_MSGP_(TFAIL | TTERRNO, " expected %s", \ + tst_strerrno(ERRNO), \ + #SCALL, ##__VA_ARGS__); \ + } \ } while (0)#define TST_EXP_FAIL (SCALL ,ERRNO , ...) TST_EXP_FAIL_(TST_RET == 0, SCALL, ERRNO, __VA_ARGS__)
Signature · 1 line
2.31.1
PATCH v3 2/3 API: Add lapi/ip_tables.h and use it in setsockopt03
--- include/lapi/ip_tables.h | 46 +++++++++++++++++++ .../kernel/syscalls/setsockopt/setsockopt03.c | 39 +--------------- 2 files changed, 48 insertions(+), 37 deletions(-) create mode 100644 include/lapi/ip_tables.h
include/lapi/ip_tables.h new file +46 -0
@@ -0,0 +1,46 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#ifndef LAPI_IP_TABLES__ +#define LAPI_IP_TABLES__ + +#include "config.h" + +#include <linux/netfilter_ipv4/ip_tables.h> + +#ifndef HAVE_STRUCT_XT_ENTRY_MATCH +struct xt_entry_match { +union { +struct { +uint16_t match_size; +char name[29 ]; +uint8_t revision; + } user; +struct { +uint16_t match_size; +void *match; + } kernel; +uint16_t match_size; + } u; +unsigned char data[0 ]; +}; +#endif + +#ifndef HAVE_STRUCT_XT_ENTRY_TARGET +struct xt_entry_target { +union { +struct { +uint16_t target_size; +char name[29 ]; +uint8_t revision; + } user; +struct { +uint16_t target_size; +void *target; + } kernel; +uint16_t target_size; + } u; +unsigned char data[0 ]; +}; +#endif + +#endif
testcases/kernel/syscalls/setsockopt/setsockopt03.c +2 -37
@@ -21,12 +21,13 @@#include <netinet/in.h> #include <net/if.h> #include <limits.h> -#include <linux/netfilter_ipv4/ip_tables.h> #include "tst_test.h" #include "tst_safe_net.h" #include "tst_kernel.h" +#include "lapi/ip_tables.h" +#define TOO_SMALL_OFFSET 74#define OFFSET_OVERWRITE 0xFFFF#define NEXT_OFFSET (sizeof(struct ipt_entry) \
@@ -34,42 +35,6 @@ + sizeof(struct xt_entry_target))#define PADDING (OFFSET_OVERWRITE - NEXT_OFFSET) -#ifndef HAVE_STRUCT_XT_ENTRY_MATCH -struct xt_entry_match { -union { -struct { -uint16_t match_size; -char name[29 ]; -uint8_t revision; - } user; -struct { -uint16_t match_size; -void *match; - } kernel; -uint16_t match_size; - } u; -unsigned char data[0 ]; -}; -#endif - -#ifndef HAVE_STRUCT_XT_ENTRY_TARGET -struct xt_entry_target { -union { -struct { -uint16_t target_size; -char name[29 ]; -uint8_t revision; - } user; -struct { -uint16_t target_size; -void *target; - } kernel; -uint16_t target_size; - } u; -unsigned char data[0 ]; -}; -#endif -struct payload {struct ipt_replace repl;struct ipt_entry ent;
Signature · 1 line
2.31.1
PATCH v3 3/3 Add setsockopt08, CVE-2021-22555
In reply to Richard PalethorpeThis is a copy and paste of Nicolai's reproducer. The main difference is that I moved some code around. Of course I also used LTP library features, but essentially it works the same.
There are some hard coded values which I do not like. I guess these could be calculated or varied somehow. However I struggle to understand what the kernel is doing. This perhaps needs more investigation. We could try generalising this test and setsockopt03.
--- runtest/cve | 1 + runtest/syscalls | 1 + .../kernel/syscalls/setsockopt/.gitignore | 1 + .../kernel/syscalls/setsockopt/setsockopt08.c | 156 ++++++++++++++++++ 4 files changed, 159 insertions(+) create mode 100644 testcases/kernel/syscalls/setsockopt/setsockopt08.c
runtest/cve +1 -0
@@ -65,4 +65,5 @@ cve-2020-14416 pty03 cve-2020-25705 icmp_rate_limit01 cve-2020-29373 io_uring02 cve-2021-3444 bpf_prog05 +cve-2021-22555 setsockopt08 -i 100 cve-2021-26708 vsock01
runtest/syscalls +1 -0
@@ -1378,6 +1378,7 @@ setsockopt04 setsockopt04 setsockopt05 setsockopt05 setsockopt06 setsockopt06 setsockopt07 setsockopt07 +setsockopt08 setsockopt08 settimeofday01 settimeofday01 settimeofday02 settimeofday02
testcases/kernel/syscalls/setsockopt/.gitignore +1 -0
@@ -5,3 +5,4 @@ /setsockopt05 /setsockopt06 /setsockopt07 +/setsockopt08
testcases/kernel/syscalls/setsockopt/setsockopt08.c new file +156 -0
156 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v3 1/3 API: TST_EXP_FAIL: Allow passing when errno is not checked
In reply to Richard PalethorpeHi!
Quoted 3 lines
Judging by the existing usage of
TST_EXP_FAIL(..., 0, ...)infinit_module02. We want to pass if errno == 0 otherwise the test will not return a result.
This is actually not true, we do not pass 0 to TST_EXP_FAIL() in finit_module() at all. The places that are not initialized in the structure are initialized at runtime based on the kernel version. I do not think that we even pass 0 to TST_EXP_FAIL*() as an errno anywhere, but I haven't really checked all the callers.
Quoted 2 lines
This is also less surprising than giving errno == 0 a dual meaning.
But I do agree that the current if (ERRNO) branch is confusing. I would be for dropping the if (ERRNO) and checking the TST_ERR against ERRNO unconditionally.
Also note that the TEST() macro clears errno, so if a syscall fails but does not report any error TST_ERR will end up 0 either way so there is no need for having special handling for 0.
Quoted 55 lines
This also changes the trailing '\' indentation to tabs. However this is correct and the rest of the file is wrong.
Signed-off-by Richard Palethorpe <[email protected]>---
V3:
* Add fix forTST_EXP_FAILwhich prevented the test from passing on a non buggy system.
* TCONF but continue on non 32-bit compat mode
* Add Fixes trailerV2:
* Add mising lapi headerinclude/tst_test_macros.h | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-)include/tst_test_macros.h +9
-11@@ -137,17 +137,15 @@ extern void *TST_RET_PTR;break ; \ } \ \ - if (ERRNO) { \ - if (TST_ERR == ERRNO) { \ - TST_MSG_(TPASS | TTERRNO, " ", \ - #SCALL, ##__VA_ARGS__); \ - TST_PASS = 1; \ - } else { \ - TST_MSGP_(TFAIL | TTERRNO, " expected %s", \ - tst_strerrno(ERRNO), \ - #SCALL, ##__VA_ARGS__); \ - } \ - } \ +if (!ERRNO ||TST_ERR ==ERRNO ) { \ + TST_MSG_(TPASS | TTERRNO, " ", \ +#SCALL , ##__VA_ARGS__); \ + TST_PASS = 1; \ + } else { \ + TST_MSGP_(TFAIL | TTERRNO, " expected %s", \ + tst_strerrno(ERRNO), \ + #SCALL, ##__VA_ARGS__); \ + } \ } while (0)#define TST_EXP_FAIL (SCALL ,ERRNO , ...) TST_EXP_FAIL_(TST_RET == 0, SCALL, ERRNO, __VA_ARGS__)Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 1/3 API: TST_EXP_FAIL: Allow passing when errno is not checked
Hello,
Quoted 14 lines · Cyril Hrubis
Hi!
Quoted 3 lines
Judging by the existing usage of
TST_EXP_FAIL(..., 0, ...)infinit_module02. We want to pass if errno == 0 otherwise the test will not return a result.This is actually not true, we do not pass 0 to
TST_EXP_FAIL()infinit_module()at all. The places that are not initialized in the structure are initialized at runtime based on the kernel version. I do not think that we even pass 0 to TST_EXP_FAIL*() as an errno anywhere, but I haven't really checked all the callers.Quoted 2 lines
This is also less surprising than giving errno == 0 a dual meaning.
Quoted 7 lines
But I do agree that the current if (ERRNO) branch is confusing. I would be for dropping the if (ERRNO) and checking the
TST_ERRagainst ERRNO unconditionally.Also note that the
TEST()macro clears errno, so if a syscall fails but does not report any errorTST_ERRwill end up 0 either way so there is no need for having special handling for 0.
There is if the errno is set, but is undefined. Like if the resulting errno is platform or config dependent.
In the present case though we can just check for EINVAL. That is what the setsockopt man page indicates. Initially I wasn't sure if EFAULT were equally valid, but it seems not.
I suppose we can fall back to using TEST() if the other case arises.
Signature · 2 lines
Thank you, Richard.
PATCH v4 1/3 API: TST_EXP_FAIL: Allow passing when errno is not set
TEST() sets errno to zero. So if something does not set errno on failure it will be zero. It is normal for functions not to use errno, some standard libraries are the exception.
The original code will not allow for a pass result if errno is not set. So we can just remove the branch to allow that. It's not clear what the original intention was.
This also changes the trailing '\' indentation to tabs. However this is correct and the rest of the file is wrong.
---
V4:
* Check for EINVAL.
* Unconditionally check TST_ERR == ERRNO.
(redundant/irrelevant due to the above change, but we still should do it IMO)
V3:
* Add fix for TST_EXP_FAIL which prevented the test from passing on a non buggy system.
* TCONF but continue on non 32-bit compat mode
* Add Fixes trailer
V2:
* Add mising lapi header
include/tst_test_macros.h | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-)
include/tst_test_macros.h +9 -11
@@ -137,17 +137,15 @@ extern void *TST_RET_PTR;break ; \ } \ \ - if (ERRNO) { \ - if (TST_ERR == ERRNO) { \ - TST_MSG_(TPASS | TTERRNO, " ", \ - #SCALL, ##__VA_ARGS__); \ - TST_PASS = 1; \ - } else { \ - TST_MSGP_(TFAIL | TTERRNO, " expected %s", \ - tst_strerrno(ERRNO), \ - #SCALL, ##__VA_ARGS__); \ - } \ - } \ +if (TST_ERR ==ERRNO ) { \ + TST_MSG_(TPASS | TTERRNO, " ", \ +#SCALL , ##__VA_ARGS__); \ + TST_PASS = 1; \ + } else { \ + TST_MSGP_(TFAIL | TTERRNO, " expected %s", \ + tst_strerrno(ERRNO), \ + #SCALL, ##__VA_ARGS__); \ + } \ } while (0)#define TST_EXP_FAIL (SCALL ,ERRNO , ...) TST_EXP_FAIL_(TST_RET == 0, SCALL, ERRNO, __VA_ARGS__)
Signature · 1 line
2.31.1
PATCH v4 2/3 API: Add lapi/ip_tables.h and use it in setsockopt03
--- include/lapi/ip_tables.h | 46 +++++++++++++++++++ .../kernel/syscalls/setsockopt/setsockopt03.c | 39 +--------------- 2 files changed, 48 insertions(+), 37 deletions(-) create mode 100644 include/lapi/ip_tables.h
include/lapi/ip_tables.h new file +46 -0
@@ -0,0 +1,46 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#ifndef LAPI_IP_TABLES__ +#define LAPI_IP_TABLES__ + +#include "config.h" + +#include <linux/netfilter_ipv4/ip_tables.h> + +#ifndef HAVE_STRUCT_XT_ENTRY_MATCH +struct xt_entry_match { +union { +struct { +uint16_t match_size; +char name[29 ]; +uint8_t revision; + } user; +struct { +uint16_t match_size; +void *match; + } kernel; +uint16_t match_size; + } u; +unsigned char data[0 ]; +}; +#endif + +#ifndef HAVE_STRUCT_XT_ENTRY_TARGET +struct xt_entry_target { +union { +struct { +uint16_t target_size; +char name[29 ]; +uint8_t revision; + } user; +struct { +uint16_t target_size; +void *target; + } kernel; +uint16_t target_size; + } u; +unsigned char data[0 ]; +}; +#endif + +#endif
testcases/kernel/syscalls/setsockopt/setsockopt03.c +2 -37
@@ -21,12 +21,13 @@#include <netinet/in.h> #include <net/if.h> #include <limits.h> -#include <linux/netfilter_ipv4/ip_tables.h> #include "tst_test.h" #include "tst_safe_net.h" #include "tst_kernel.h" +#include "lapi/ip_tables.h" +#define TOO_SMALL_OFFSET 74#define OFFSET_OVERWRITE 0xFFFF#define NEXT_OFFSET (sizeof(struct ipt_entry) \
@@ -34,42 +35,6 @@ + sizeof(struct xt_entry_target))#define PADDING (OFFSET_OVERWRITE - NEXT_OFFSET) -#ifndef HAVE_STRUCT_XT_ENTRY_MATCH -struct xt_entry_match { -union { -struct { -uint16_t match_size; -char name[29 ]; -uint8_t revision; - } user; -struct { -uint16_t match_size; -void *match; - } kernel; -uint16_t match_size; - } u; -unsigned char data[0 ]; -}; -#endif - -#ifndef HAVE_STRUCT_XT_ENTRY_TARGET -struct xt_entry_target { -union { -struct { -uint16_t target_size; -char name[29 ]; -uint8_t revision; - } user; -struct { -uint16_t target_size; -void *target; - } kernel; -uint16_t target_size; - } u; -unsigned char data[0 ]; -}; -#endif -struct payload {struct ipt_replace repl;struct ipt_entry ent;
Signature · 1 line
2.31.1
PATCH v4 3/3 Add setsockopt08, CVE-2021-22555
In reply to Richard PalethorpeThis is a copy and paste of Nicolai's reproducer. The main difference is that I moved some code around. Of course I also used LTP library features, but essentially it works the same.
There are some hard coded values which I do not like. I guess these could be calculated or varied somehow. However I struggle to understand what the kernel is doing. This perhaps needs more investigation. We could try generalising this test and setsockopt03.
--- runtest/cve | 1 + runtest/syscalls | 1 + .../kernel/syscalls/setsockopt/.gitignore | 1 + .../kernel/syscalls/setsockopt/setsockopt08.c | 156 ++++++++++++++++++ 4 files changed, 159 insertions(+) create mode 100644 testcases/kernel/syscalls/setsockopt/setsockopt08.c
runtest/cve +1 -0
@@ -65,4 +65,5 @@ cve-2020-14416 pty03 cve-2020-25705 icmp_rate_limit01 cve-2020-29373 io_uring02 cve-2021-3444 bpf_prog05 +cve-2021-22555 setsockopt08 -i 100 cve-2021-26708 vsock01
runtest/syscalls +1 -0
@@ -1378,6 +1378,7 @@ setsockopt04 setsockopt04 setsockopt05 setsockopt05 setsockopt06 setsockopt06 setsockopt07 setsockopt07 +setsockopt08 setsockopt08 settimeofday01 settimeofday01 settimeofday02 settimeofday02
testcases/kernel/syscalls/setsockopt/.gitignore +1 -0
@@ -5,3 +5,4 @@ /setsockopt05 /setsockopt06 /setsockopt07 +/setsockopt08
testcases/kernel/syscalls/setsockopt/setsockopt08.c new file +156 -0
156 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v4 3/3 Add setsockopt08, CVE-2021-22555
Hi!
testcases/kernel/syscalls/setsockopt/setsockopt08.c line 84
Quoted 3 lines
testcases/kernel/syscalls/setsockopt/setsockopt08.c new file +3
-0+#include "tst_test.h" +#include "tst_safe_net.h" +#include "lapi/ip_tables.h"
I've fixed the failure on Centos with missing IFNAMSIZ but this still fails to compile on ubuntu xenial because the tst_safe_net.h pull in netinet/in.h and lapi/ip_tables.h pulls in linux/in.h and on old enough systems these two headers does not like to be included at the same time.
I'm not sure how to fix this, either we drop the include to linux/netfilter_ipv4/ip_tables.h completely or we add a configure check if netinet/in.h and linux/in.h could be included at the same time and ifdef the linux/netfilter_ipv4/ip_tables.h with that check.
Either way both looks like a hack, if anyone has a better idea please suggest it.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v4 3/3 Add setsockopt08, CVE-2021-22555
Hi!
Quoted 9 lines
testcases/kernel/syscalls/setsockopt/setsockopt08.c line 84
Quoted 3 lines
testcases/kernel/syscalls/setsockopt/setsockopt08.c new file +3
-0+#include "tst_test.h" +#include "tst_safe_net.h" +#include "lapi/ip_tables.h" I've fixed the failure on Centos with missing IFNAMSIZ but this still fails to compile on ubuntu xenial because the
tst_safe_net.hpull innetinet/in.handlapi/ip_tables.hpulls inlinux/in.hand on old enough systems these two headers does not like to be included at the same time.
Quoted 7 lines
I'm not sure how to fix this, either we drop the include to
linux/netfilter_ipv4/ip_tables.hcompletely or we add a configure check ifnetinet/in.handlinux/in.hcould be included at the same time and ifdef thelinux/netfilter_ipv4/ip_tables.hwith that check.Either way both looks like a hack, if anyone has a better idea please suggest it.
Uff and it looks like setsockopt03 does include the same headers so this could probably be fixed by another shuffle, but I will have to figure out what has to be moved and where.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v4 3/3 Add setsockopt08, CVE-2021-22555
Hello Cyril,
Quoted 15 lines · Cyril Hrubis
Hi!
Quoted 14 lines
testcases/kernel/syscalls/setsockopt/setsockopt08.c line 84
Quoted 3 lines
testcases/kernel/syscalls/setsockopt/setsockopt08.c new file +3
-0+#include "tst_test.h" +#include "tst_safe_net.h" +#include "lapi/ip_tables.h" I've fixed the failure on Centos with missing IFNAMSIZ but this still fails to compile on ubuntu xenial because the
tst_safe_net.hpull innetinet/in.handlapi/ip_tables.hpulls inlinux/in.hand on old enough systems these two headers does not like to be included at the same time.I'm not sure how to fix this, either we drop the include to
linux/netfilter_ipv4/ip_tables.hcompletely or we add a configure check ifnetinet/in.handlinux/in.hcould be included at the same time and ifdef thelinux/netfilter_ipv4/ip_tables.hwith that check.
Quoted 6 lines
Quoted 2 lines
Either way both looks like a hack, if anyone has a better idea please suggest it.
Uff and it looks like setsockopt03 does include the same headers so this could probably be fixed by another shuffle, but I will have to figure out what has to be moved and where.
Looking in libc-compat.h we have:
/* Coordinate with glibc netinet/in.h header. */
#if defined(_NETINET_IN_H)
/* GLIBC headers included first so don't define anything
* that would already be defined. */
#define __UAPI_DEF_IN_ADDR 0
...
I suppose we may be able to do something similar. In tst_safe_net.h we could check if _LINUX_IN_H is defined before including netinet/in.h. Then include lapi/ip_tables.h first. Maybe even put
#ifdef _NETINET_IN_H
# error "incompatible system header ..." #endif
in lapi/ip_tables.h
IDK if this may break some existing tests.
Signature · 2 lines
Thank you, Richard.
PATCH v4 1/3 API: TST_EXP_FAIL: Allow passing when errno is not set
In reply to Richard PalethorpeHi!
Patchset pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 1/3 API: TST_EXP_FAIL: Allow passing when errno is not checked
In reply to Richard PalethorpeHi!
Quoted 11 lines
Quoted 10 lines
Quoted 2 lines
This is also less surprising than giving errno == 0 a dual meaning.
But I do agree that the current if (ERRNO) branch is confusing. I would be for dropping the if (ERRNO) and checking the
TST_ERRagainst ERRNO unconditionally.Also note that the
TEST()macro clears errno, so if a syscall fails but does not report any errorTST_ERRwill end up 0 either way so there is no need for having special handling for 0.
Quoted 6 lines
There is if the errno is set, but is undefined. Like if the resulting errno is platform or config dependent.
In the present case though we can just check for EINVAL. That is what the setsockopt man page indicates. Initially I wasn't sure if EFAULT were equally valid, but it seems not.
There was also an idea to add another version that would take an array of possible errnos if that happens, but I fear that the complexity would be getting out of hand if we keep adding features like that.
Quoted 1 line
I suppose we can fall back to using
TEST()if the other case arises.
Yes.
Signature · 2 lines
Cyril Hrubis [email protected]