From nobody Tue Aug 02 14:51:10 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Lxyby35pNz4YJMD; Tue, 2 Aug 2022 14:51:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Lxyby2fpPz3cvS; Tue, 2 Aug 2022 14:51:10 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1659451870; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=aRqcPtAGHFVrcj9HH+pybx9sjTadZov9qDnvGRWWngw=; b=RJTdJB/oE46iGo9W1vVPkgRGLZb9lcSVAZGwtbYHI6oc+IXzRH4IV2fJcOYIHRS7pK8133 FfMoHldrkaeAVSHO2mftuTJqg8Jk3mvjL5LlSv9nzDJQ61Zdd9xeGc2XmkVcxv/p3XIkeM 9lZ87GOTaizFXO0KL2K6Uofi9TckQyFxqu9Gl38+OCTfX8dM2VQDlpWSbpR/p6ws6ekccX 4V9keGyDw0+cw5nN9o6q6H++87Eg5LwOUw9rTwtX66PlDhDusHUH2GJ8T+ODT1rS/EEeBG rzneUK2wZbljoGATZ6efWpVR1w/kAYaxAviPHhd2Zu/CyopVcnMbGh33ud2r2g== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Lxyby1kGLzGX9; Tue, 2 Aug 2022 14:51:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 272EpA3M027111; Tue, 2 Aug 2022 14:51:10 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 272EpAVq027110; Tue, 2 Aug 2022 14:51:10 GMT (envelope-from git) Date: Tue, 2 Aug 2022 14:51:10 GMT Message-Id: <202208021451.272EpAVq027110@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mike Karels Subject: git: 637f317c6d9c - main - IPv6: fix problem with duplicate port assignment with v4-mapped addrs List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: karels X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 637f317c6d9c0c689677f499fc78ac545b192071 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1659451870; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=aRqcPtAGHFVrcj9HH+pybx9sjTadZov9qDnvGRWWngw=; b=vCTG+OZI3JUjidjN0vJstOSHdiwnhW5L6WkFidp2k7IJjIm1AsTEryGwJOrKzlw5ZwEfwS jZ2L2KQdVMXAAXSfgx9q1rIps3TGn6SZWG+3IX3uaSQW46xYg6u2x1yxsIfajxCf0nwSbZ mnYRZLgEXGniNuHWVzd9TSk2zMH0HK0oblYDeCj1IPVw7knLK4DZPJYvNr5K48RDmAOYLQ ki7rROxlCV0MP02cmOfKo4jhFdRT6uZPEhlKuPkyRivhVDMLyaznybAccjxfRYk5wASvLg Fp7o3lWydGvQbzcLKXwkLBTawwX5fKCCiCScJoljnn5wKMQuB9oOeiUq/6U1Sw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1659451870; a=rsa-sha256; cv=none; b=gCltmXi/rV+The9PK13ybZEWCghf/vMRwiEfYgJNJlGvU3X/O52JAKwPTWTmPqlVDxHV/o vzsYT5PISKEKl4+xbhs2yrGIl5vQEz/vfBm/VL/FMs0xXdu5CoVE/B9zq6XNglQ7d+plPl EPZTycW7Ek2vxHBs/yrkHrKzTyWN2DJWlxFaA+IcSulKv8LuZS/363iBNUtF54rXhQmKlS 73ZPFcH0XjLDEaBlnZKRbmbwyiVeZUyuh2OY+pMlZszm3A0ZDVWXfY2EwfGys1HJElwjAs uvxStKvWSXsjsLjnIpNtv0SCevYRgUjGc7ibf4qS1qzWtmiFM6ApZQXdth+WTQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by karels: URL: https://cgit.FreeBSD.org/src/commit/?id=637f317c6d9c0c689677f499fc78ac545b192071 commit 637f317c6d9c0c689677f499fc78ac545b192071 Author: Mike Karels AuthorDate: 2022-07-29 14:23:23 +0000 Commit: Mike Karels CommitDate: 2022-08-02 14:49:46 +0000 IPv6: fix problem with duplicate port assignment with v4-mapped addrs In in_pcb_lport_dest(), if an IPv6 socket does not match any other IPv6 socket using in6_pcblookup_local(), and if the socket can also connect to IPv4 (the INP_IPV4 vflag is set), check for IPv4 matches as well. Otherwise, we can allocate a port that is used by an IPv4 socket (possibly one created from IPv6 via the same procedure), and then connect() can fail with EADDRINUSE, when it could have succeeded if the bound port was not in use. PR: 265064 Submitted by: firk at cantconnect.ru (with modifications) Reviewed by: bz, melifaro Differential Revision: https://reviews.freebsd.org/D36012 --- sys/netinet/in_pcb.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index 63b5f39f7577..321af17a4767 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -784,7 +784,7 @@ in_pcb_lport_dest(struct inpcb *inp, struct sockaddr *lsa, u_short *lportp, } #ifdef INET - laddr.s_addr = INADDR_ANY; + laddr.s_addr = INADDR_ANY; /* used by INET6+INET below too */ if ((inp->inp_vflag & (INP_IPV4|INP_IPV6)) == INP_IPV4) { if (lsa != NULL) laddr = ((struct sockaddr_in *)lsa)->sin_addr; @@ -835,9 +835,16 @@ in_pcb_lport_dest(struct inpcb *inp, struct sockaddr *lsa, u_short *lportp, #endif } else { #ifdef INET6 - if ((inp->inp_vflag & INP_IPV6) != 0) + if ((inp->inp_vflag & INP_IPV6) != 0) { tmpinp = in6_pcblookup_local(pcbinfo, &inp->in6p_laddr, lport, lookupflags, cred); +#ifdef INET + if (tmpinp == NULL && + (inp->inp_vflag & INP_IPV4)) + tmpinp = in_pcblookup_local(pcbinfo, + laddr, lport, lookupflags, cred); +#endif + } #endif #if defined(INET) && defined(INET6) else