From patchwork Mon Jan 30 17:29:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arne Schwabe X-Patchwork-Id: 3027 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7300:c95:b0:82:e4b3:40a0 with SMTP id p21csp3397587dyk; Mon, 30 Jan 2023 09:30:07 -0800 (PST) X-Google-Smtp-Source: AK7set8sdUbzhQDpERvo+Iz+YDcLPKYTvI3BoGHCcGWxOba800JXYtuZUFqyo7OrEtbDKNLegScQ X-Received: by 2002:a05:6a20:9388:b0:bc:8c17:32a9 with SMTP id x8-20020a056a20938800b000bc8c1732a9mr11847830pzh.4.1675099807810; Mon, 30 Jan 2023 09:30:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675099807; cv=none; d=google.com; s=arc-20160816; b=GSbBAGVAwR+FLP+uJt2Lke2FRCC0vT9kWYCDVTAw/WixEIvWSq+89tn0iUAOxQY2Sz 8PBBRylr06qxC2qGSFBnzO5sPPcI1ZldwPhpo4BApR241ObYVBCNxDcnLvgiLP7SFF37 5VNCUWDcGB5oesmRwZvB7louKHrE2lsa7xpbQk1jgmzt/GqDgEgKWimzu/GkEKlygCcz pNU7kodu7KhJ+ooxAmuNpLiTgDzIqHc9IetwYT+C8NsN+Nfg3/atlhzon7IbeGKMZ3yP khuejlpksVIEMJoTs2X7qukwZruFThS6VXQ68WIW2SpZGCTiCb1X5QoWVX3IxOXcW2cM s0fA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature; bh=OJM4HDCyYTlKkrq5h5UbCYTt0WGxzInoKAPU3tMgkQQ=; b=QtYuNYYJIm5GyfY8W2Bm1GVYIhzmLNJxHdxUUSZ+v5UV0oDXsnU0mlQCLJk+sa9gRh DfbTVYvAuIEpGBt5dov4LY534CrsqgR1gTJzktPhQo23Jz+ITgBe4P7y7/fDClI0BUsw UahLUma4NTNlb53m2mmsRCCiKRn+0q7FqvA+1/xgmXG2Q8CTXgvHSy4iiFL1O4ALxBfx vMDfWkfLuEYZdoLKvh42c0DM6FKym3KyMlFIPI9IJDx35tlgDZRB59YcUaZllc0Jp1w6 /KqxK6z6Vmg8EzJHEGiZAgI45PaerIKjQChYFCv4RBSwi2WOEkmOrZB7NUOc6qP/UBIP IVpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=O7QJ9pbe; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=DakJRcMc; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id o7-20020a656a47000000b0047874cf7b40si16110824pgu.178.2023.01.30.09.30.07 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Jan 2023 09:30:07 -0800 (PST) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=O7QJ9pbe; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=DakJRcMc; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1pMXyY-0005PJ-Ra; Mon, 30 Jan 2023 17:29:49 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pMXyV-0005PC-Dq for openvpn-devel@lists.sourceforge.net; Mon, 30 Jan 2023 17:29:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=9Kc3KNr1mZPqZ6ohVHJTcfRU7oUqYtEpScMrMTjgCAI=; b=O7QJ9pbe/oX4wnjJ1kFIgZxtSj Dgi/VCtMDkrFwjbyhlmy/tXmF7OyN3+zKYQY2z3RM7bt3VA+nIceEJ87k9mZHD158U8noObrowqsk NEj+QJbnSngvBOYGazOsRXzqLxDPGR8nSJ6guub6PYum9c60RRHPDlH6Moeb82c5ZwGA=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=9Kc3KNr1mZPqZ6ohVHJTcfRU7oUqYtEpScMrMTjgCAI=; b=DakJRcMcNZbEZT/0fxeNnY8N0u 6/xQKNUvnDH2AJNzjW7HU4f5Pc7DiWVnUF/lZCfLKUnjMQbQhjz7rUg/RsWxJcyzCr9Nc6fqgh0IW yKflGwG1GS12Yczi5LDN0dJcJhL19KOF7At2flRBA2HW2Z4XR51H23oDAzOwI97HkgqI=; Received: from mail.blinkt.de ([192.26.174.232]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1pMXyR-0005SZ-GG for openvpn-devel@lists.sourceforge.net; Mon, 30 Jan 2023 17:29:45 +0000 Received: from kamera.blinkt.de ([2001:638:502:390:20c:29ff:fec8:535c]) by mail.blinkt.de with smtp (Exim 4.95 (FreeBSD)) (envelope-from ) id 1pMXyK-000JyO-Sf for openvpn-devel@lists.sourceforge.net; Mon, 30 Jan 2023 18:29:36 +0100 Received: (nullmailer pid 3444891 invoked by uid 10006); Mon, 30 Jan 2023 17:29:36 -0000 From: Arne Schwabe To: openvpn-devel@lists.sourceforge.net Date: Mon, 30 Jan 2023 18:29:33 +0100 Message-Id: <20230130172936.3444840-2-arne@rfc2549.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230130172936.3444840-1-arne@rfc2549.org> References: <20230130172936.3444840-1-arne@rfc2549.org> MIME-Version: 1.0 X-Spam-Score: 0.3 (/) X-Spam-Report: Spam detection software, running on the system "util-spamd-2.v13.lw.sourceforge.com", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: The undefined behaviour USAN clang checker found this. This fix is a bit messy but so are the original structures. Signed-off-by: Arne Schwabe --- src/openvpn/route.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) Content analysis details: (0.3 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.2 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail domains are different X-Headers-End: 1pMXyR-0005SZ-GG Subject: [Openvpn-devel] [PATCH 2/5] Fix unaligned access in macOS/Solaris hwaddr X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1756469456398997560?= X-GMAIL-MSGID: =?utf-8?q?1756469456398997560?= The undefined behaviour USAN clang checker found this. This fix is a bit messy but so are the original structures. Signed-off-by: Arne Schwabe Acked-By: Frank Lichtenheld --- src/openvpn/route.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/openvpn/route.c b/src/openvpn/route.c index 82519c94b..06bfb799c 100644 --- a/src/openvpn/route.c +++ b/src/openvpn/route.c @@ -3637,7 +3637,7 @@ get_default_gateway(struct route_gateway_info *rgi, openvpn_net_ctx_t *ctx) if (rgi->flags & RGI_IFACE_DEFINED) { struct ifconf ifc; - struct ifreq *ifr; + struct ifreq ifr; const int bufsize = 4096; char *buffer; @@ -3662,23 +3662,37 @@ get_default_gateway(struct route_gateway_info *rgi, openvpn_net_ctx_t *ctx) for (cp = buffer; cp <= buffer + ifc.ifc_len - sizeof(struct ifreq); ) { - ifr = (struct ifreq *)cp; + /* this is not always using an 8byte alignment that struct ifr + * requires */ + memcpy(&ifr, cp, sizeof(struct ifreq)); #if defined(TARGET_SOLARIS) - const size_t len = sizeof(ifr->ifr_name) + sizeof(ifr->ifr_addr); + const size_t len = sizeof(ifr.ifr_name) + sizeof(ifr.ifr_addr); #else - const size_t len = sizeof(ifr->ifr_name) + max(sizeof(ifr->ifr_addr), ifr->ifr_addr.sa_len); + const size_t len = sizeof(ifr.ifr_name) + max(sizeof(ifr.ifr_addr), ifr.ifr_addr.sa_len); #endif - if (!ifr->ifr_addr.sa_family) + if (!ifr.ifr_addr.sa_family) { break; } - if (!strncmp(ifr->ifr_name, rgi->iface, IFNAMSIZ)) + if (!strncmp(ifr.ifr_name, rgi->iface, IFNAMSIZ)) { - if (ifr->ifr_addr.sa_family == AF_LINK) + if (ifr.ifr_addr.sa_family == AF_LINK) { - struct sockaddr_dl *sdl = (struct sockaddr_dl *)&ifr->ifr_addr; - memcpy(rgi->hwaddr, LLADDR(sdl), 6); + /* This is a broken member access. struct sockaddr_dl has + * 20 bytes while if_addr has only 16 bytes. So casting if_addr + * to struct sockaddr_dl gives (legitimate) warnings + * + * sockaddr_dl has 12 bytes space for the hw address and + * Ethernet only uses 6 bytes. So the last 4 that are + * truncated and not in if_addr can be ignored here. + * + * So we use a memcpy here to avoid the warnings with ASAN + * that we are doing a very nasty cast here + */ + struct sockaddr_dl sdl = { 0 }; + memcpy(&sdl, &ifr.ifr_addr, sizeof(ifr.ifr_addr)); + memcpy(rgi->hwaddr, LLADDR(&sdl), 6); rgi->flags |= RGI_HWADDR_DEFINED; } }