Bug 1886305

Summary: connect AF_UNSPEC on a connecting AF_INET6 socket returns an error
Product: Red Hat Enterprise Linux 7 Reporter: Tom Deseyn <tdeseyn>
Component: kernelAssignee: Paolo Abeni <pabeni>
kernel sub component: Networking QA Contact: Jinghua Wu <jinwu>
Status: CLOSED ERRATA Docs Contact:
Severity: unspecified    
Priority: unspecified CC: atragler, hasuzuki, jiji, kzhang, mleitner, nmurray, omosnace, pabeni, sukulkar
Version: 7.9   
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: kernel-3.10.0-1160.8.1.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-12-15 11:13:26 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1892561    

Description Tom Deseyn 2020-10-08 07:09:12 UTC
Description of problem:

connect to AF_UNSPEC to cancel an on-going connect does not work for AF_INET6 socket.

How reproducible:

Always

Steps to Reproduce:

```
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <pthread.h>
#include <unistd.h>
#include <stdio.h>
#include <assert.h>

static void* connect_socket(void* arg)
{
    int s = (int)(long)arg;

    struct sockaddr_in6 address;
    address.sin6_family = AF_INET6;
    inet_pton(AF_INET6, "::ffff:1.1.1.1", &address.sin6_addr);
    address.sin6_port = htons(23);

    int rv = connect(s, (struct sockaddr*)&address, sizeof(address));
    assert(rv != 0);

    return NULL;
}

int main()
{
    // create AF_INET6 socket
    int s = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);

    // on-going connect to 1.1.1.1:23
    pthread_t connect_thread;
    int rv = pthread_create(&connect_thread, NULL, connect_socket, (void*)(long)s);
    assert(rv == 0);
    sleep(1); // sleep to wait until connect is on-going.

    // connect to AF_UNSPEC
    struct sockaddr address;
    address.sa_family = AF_UNSPEC;
    rv = connect(s, &address, sizeof(address));

    // wait for thread
    rv = pthread_join(connect_thread, NULL);
    assert(rv == 0);

    return 0;
}

```

```
$ gcc main.c -lpthread
$ ./a.out
```

Actual results:

On RHEL7 this program hangs.
connect to AF_UNSPEC returns EINVAL.

Expected results:

On other Linux systems the program completes.
connect to AF_UNSPEC returns 0.
connect to AF_INET6 returns ECONNRESET.

Additional info:

This issue was discovered as part of .NET Core CI testing: https://github.com/dotnet/runtime/issues/42686.

Comment 3 Augusto Caringi 2020-11-10 02:56:01 UTC
Patch(es) committed on kernel-3.10.0-1160.8.1.el7

Comment 13 errata-xmlrpc 2020-12-15 11:13:26 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (Important: kernel security and bug fix update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2020:5437

Comment 14 errata-xmlrpc 2020-12-15 11:17:48 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (Important: kernel security and bug fix update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2020:5437