From owner-freebsd-emulation@freebsd.org Tue Feb 26 04:59:46 2019 Return-Path: Delivered-To: freebsd-emulation@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C0FCD150A3A8 for ; Tue, 26 Feb 2019 04:59:46 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mailman.ysv.freebsd.org (mailman.ysv.freebsd.org [IPv6:2001:1900:2254:206a::50:5]) by mx1.freebsd.org (Postfix) with ESMTP id 51D846A20B for ; Tue, 26 Feb 2019 04:59:46 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: by mailman.ysv.freebsd.org (Postfix) id 1243B150A3A7; Tue, 26 Feb 2019 04:59:46 +0000 (UTC) Delivered-To: emulation@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E1B7C150A3A6 for ; Tue, 26 Feb 2019 04:59:45 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mxrelay.ysv.freebsd.org (mxrelay.ysv.freebsd.org [IPv6:2001:1900:2254:206a::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.ysv.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 5AE0A6A206 for ; Tue, 26 Feb 2019 04:59:45 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2001:1900:2254:206a::16:76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.ysv.freebsd.org (Postfix) with ESMTPS id 663D518DBC for ; Tue, 26 Feb 2019 04:59:44 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.118]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id x1Q4xia7094285 for ; Tue, 26 Feb 2019 04:59:44 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id x1Q4xipx094284 for emulation@FreeBSD.org; Tue, 26 Feb 2019 04:59:44 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: emulation@FreeBSD.org Subject: [Bug 232920] linuxulator: linux_to_bsd_sockaddr and bsd_to_linux_sockaddr are unsafe Date: Tue, 26 Feb 2019 04:59:44 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: kern X-Bugzilla-Version: CURRENT X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: weike_chen@dell.com X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: emulation@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: freebsd-emulation@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development of Emulators of other operating systems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Feb 2019 04:59:47 -0000 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D232920 Vic Chen changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |weike_chen@dell.com --- Comment #1 from Vic Chen --- Another related issue is: The function 'linux_getsockname' in 'linux_socket.c' calls 'bsd_to_linux_sockaddr', and it calls 'bsd_to_linux_domain' to convert 'sa_family' from BSD domain to Linux domain. But after calling 'bsd_to_linux_sockaddr', 'linux_sa_put' is called, and = it calls 'bsd_to_linux_domain' to convert 'sa_family' from BSD domain to Linux domain again. But the 'sa_family' has already been converted. Since the value of AF_INTE6 and LINUX_AF_INET6 is different, and converting twice will cause issue.=20 Test Case below: get_sock_name_case.c #include #include #include #include #include int main() { int sock; int len =3D sizeof(struct sockaddr_in6); struct sockaddr_in6 add; if ((sock=3Dsocket(AF_INET6, SOCK_STREAM, 0)) < 0) { perror("sock"); return 1; } memset(&add, 0, len); add.sin6_family =3D AF_INET6; add.sin6_port =3D htons(10000); printf("bind address type:%d-port:%d\n", add.sin6_family, ntohs(add.sin6_port)); if (bind(sock, (struct sockaddr *)&add, len)<0) { perror("bind"); return 1; } memset(&add, 0, len); getsockname(sock, (struct sockaddr *)&add, &len); printf("getsockname address type:%d-port:%d\n", add.sin6_family, ntohs(add.sin6_port)); return 0; } result: case in linux user@~/:uname -a Linux CentOS 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_= 64 x86_64 x86_64 GNU/Linux user@~/:cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core) bind address type:10-port:10000 getsockname address type:10-port:10000 case in freebsd [user@host ~]# uname -a FreeBSD host 12.0-RELEASE FreeBSD 12.0-RELEASE #94 308a36af9(master)-dirty:= Mon Feb 25 16:33:41 CST 2019 KERNCONF amd64 [user@host ~]# ./case bind address type:10-port:10000 getsockname address type:3-port:10000 --=20 You are receiving this mail because: You are the assignee for the bug.=