syscalls/connect02: Handle IPV6_ADDRFORM removal and listen() EINVAL
PATCH v2 1/1 syscalls/connect02: Handle IPV6_ADDRFORM removal and listen() EINVAL
Upstream kernel commit 31c5ea8a3296 ("ipv6: Remove IPV6_ADDRFORM.") completely removed IPV6_ADDRFORM socket option support from the Linux kernel, causing setsockopt(SOL_IPV6, IPV6_ADDRFORM, ...) to return -ENOPROTOOPT.
In addition, commit 8cc3aef0cb19 ("tcp: Do not allow buggy transitions between ehash and lhash2.") intentionally disallows converting an unhashed established socket into a listening socket by returning -EINVAL from listen().
Update connect02 to:
1. Probe getsockopt(IPV6_ADDRFORM) on ENOPROTOOPT failure to distinguish true kernel removal from the known regression fixed by 82c9ae440857, reporting TCONF only if the option is truly absent.
2. Report TCONF when listen() returns EINVAL due to the unhashed socket transition restriction.
---
V1 -> V2:
- Distinguish IPV6_ADDRFORM removal from CVE-2018-9568 regression (commit b6f6118901d1) via getsockopt() probe to retain TFAIL on buggy kernels.
- Report TCONF instead of TPASS when listen() returns EINVAL.
- Initialize 'family' to 0 and ensure sockets are closed on exit paths.
testcases/kernel/syscalls/connect/connect02.c | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/connect/connect02.c +26 -1
@@ -91,6 +91,21 @@ static void run(void) sizeof(optval)));if (TST_RET ==-1 ) { +if (TST_ERR ==ENOPROTOOPT ||TST_ERR ==EOPNOTSUPP ) { +int family =0 ; +socklen_t optlen =sizeof (family); + +if (getsockopt (fd,SOL_IPV6 ,IPV6_ADDRFORM , + &family, &optlen) ==-1 && errno ==ENOPROTOOPT ) { +SAFE_CLOSE (confd1); +SAFE_CLOSE (fd); +tst_brk (TCONF |TTERRNO , +"IPV6_ADDRFORM is removed/unsupported by this kernel" ); + } + } + +SAFE_CLOSE (confd1); +SAFE_CLOSE (fd);tst_res (TFAIL |TTERRNO ,"setsockopt(IPV6_ADDRFORM) failed" );return ;
@@ -104,7 +119,17 @@ static void run(void) sizeof(reset_addr));SAFE_BIND (fd, (struct sockaddr *)&bind_addr4,sizeof (bind_addr4)); -SAFE_LISTEN (fd,5 ); +TEST (listen (fd,5 )); +if (TST_RET ==-1 ) { +SAFE_CLOSE (confd1); +SAFE_CLOSE (fd); + +if (TST_ERR ==EINVAL ) { +tst_brk (TCONF , +"Transition from unhashed established socket to listening is disallowed" ); + } +tst_brk (TBROK |TTERRNO ,"listen(fd,5) failed unexpectedly" ); + } addrlen =tst_get_connect_address (fd, &client_addr2); confd2 =SAFE_SOCKET (AF_INET ,SOCK_STREAM ,IPPROTO_TCP );
--
2.56.0
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Ramesh,
Quoted 1 line · Ramesh Chhetri
syscalls/connect02: Handle
IPV6_ADDRFORMremoval andlisten()EINVAL
Verdict - Reviewed
---
Note:
The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp