Page MenuHomeFreeBSD

Unlock inp when handling TCP_MD5SIG socket options
ClosedPublic

Authored by thj on Jun 20 2022, 1:15 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Oct 19, 2:26 PM
Unknown Object (File)
Sat, Oct 19, 2:26 PM
Unknown Object (File)
Sat, Oct 19, 2:26 PM
Unknown Object (File)
Sat, Oct 19, 2:25 PM
Unknown Object (File)
Sat, Oct 19, 2:25 PM
Unknown Object (File)
Sat, Oct 19, 2:08 PM
Unknown Object (File)
Tue, Oct 15, 3:35 AM
Unknown Object (File)
Oct 1 2024, 1:39 PM

Details

Summary

Unlock the inp when hanlding TCP_MD5SIG socket options. tcp_ipsec_pcbctl
handles locking the inp when the option is being modified.

This was found by Claudio Jeker while OpenBGPd and the fix is from him.

On 14 we get a panic when trying to call getsockopt, on 13.1 the process locks
up using 100% CPU.

Test Plan

The following test case exercises the behaviour with the tcpmd5 kernel module
loaded.

#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>

#include <err.h>

int
main(int argc, char **argv)
{
        struct sockaddr_in s = { 0 };
        socklen_t len;
        int fd, opt;

        if ((fd = socket(PF_INET, SOCK_STREAM, 0)) == -1)
                err(1, "socket");

        s.sin_family = AF_INET;
        s.sin_len = sizeof(s);
        s.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
        s.sin_port = htons(22);
        if (connect(fd, (struct sockaddr *)&s, sizeof(s)) == -1)
                err(1, "connect");

        if (getsockopt(fd, IPPROTO_TCP, TCP_MD5SIG, &opt, &len) == -1)
                err(1, "getsockopt");

        return opt;
}

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

thj requested review of this revision.Jun 20 2022, 1:15 PM
This revision is now accepted and ready to land.Jun 20 2022, 1:35 PM

Would it be possible to add the testcase for both IPv4 and IPv6?

  • Add test cases for getsockopt
This revision now requires review to proceed.Jun 22 2022, 3:06 PM
This revision is now accepted and ready to land.Jun 22 2022, 4:29 PM
This revision now requires review to proceed.Jun 23 2022, 2:48 PM
This revision was not accepted when it landed; it landed in state Needs Review.Jun 23 2022, 2:59 PM
This revision was automatically updated to reflect the committed changes.