From patchwork Tue Nov 21 16:06:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "ralf_lici (Code Review)" X-Patchwork-Id: 3470 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7300:53c1:b0:f2:62eb:61c1 with SMTP id u1csp480639dye; Tue, 21 Nov 2023 08:07:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IEEYymWG3QGfgDTtwHBPIqIsnAXFJurUeB2eBUHTTHfTuvnkZQnk2+G5zzo0Bi5SXB4ULqV X-Received: by 2002:a05:6a20:d04e:b0:18a:febe:7af4 with SMTP id hv14-20020a056a20d04e00b0018afebe7af4mr1518298pzb.6.1700582876844; Tue, 21 Nov 2023 08:07:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700582876; cv=none; d=google.com; s=arc-20160816; b=dADT1sSwOxtPSegPeoidBoUs3ssz0B3AknyrOH8QtxFwnlXgx/UMj1CcODkCTLfoYE eHFDzXgzWPiq+VG2sSWYUasDMhb6Ggf4pUQF8KkB3Fs1IVtNZ6ZWr0e6pQG4frbabFPG RKICfc5ps/smACdfv5a9meATjRPhDgz0GKEWSFRbxlv/nCNSo1Qz92MpxAaK3p7fjgOh F2SdlC+Zqkp6ESpIbLgw0mOOnL0ify92CHJWdymiucKeAiOAnvJ64/24p1BkYuc22E37 d4L+PjufHU3+cUcTj+FHp86Fu/3d1rTT5/PK/QNC2OELQqf2jvIYe+ddbJE2Lw1bga3n cIyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:cc:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:user-agent :mime-version:message-id:references:auto-submitted:to:date:from :dkim-signature:dkim-signature:dkim-signature; bh=BkEg7AWjX6WahpW5IoOld0I7r0AE03Rcc4+JAo4k8s4=; fh=lm0MLPW7DntlrDqRECIiC9JlE1uPxhepE0URYHIf+eE=; b=gKu4lDa6Ll4JlEAnClDf4wwRmG8Bk9TtX5rwi1N08Ut4jFIetv6iAwq2NlgEC1W06K VBNora1C9NSNBY+6UzH4A3OoAwu4xlzU++zFQSLx7WahuQFrmg7tUn1LHQpIo/vAyqux ks+mkif+i+/nY1zaFrnfPHsp6/ifo6EflHTtUff3thwwZ3MwlOPwgijHoP0VL4eBvdnx JOu3OTvfCub9JQo1I0RG5trFapHtY9VJEMyB5QMZ8oco61t7dKzhBikU8rO0IU+Mo5O0 d9nM/xG2KJgbznyY6usMfvvbN5OzKbn9sE4BAj9WH5Pdy40VKmY6FYOA8+wRwhsYodoE opEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=BPfjl3IY; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=klIiZBlZ; dkim=neutral (body hash did not verify) header.i=@openvpn.net header.s=google header.b=c6HXxRFs; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=openvpn.net Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id f13-20020aa79d8d000000b006be0e90200dsi10279366pfq.374.2023.11.21.08.07.56 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Nov 2023 08:07:56 -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=BPfjl3IY; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=klIiZBlZ; dkim=neutral (body hash did not verify) header.i=@openvpn.net header.s=google header.b=c6HXxRFs; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=openvpn.net Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1r5THE-0000eX-WE; Tue, 21 Nov 2023 16:07:03 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1r5THB-0000e2-A7 for openvpn-devel@lists.sourceforge.net; Tue, 21 Nov 2023 16:07:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:Content-Transfer-Encoding:MIME-Version :Message-ID:Reply-To:References:Subject:List-Unsubscribe:List-Id:Cc:To:Date: From:Sender:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:List-Help: List-Subscribe:List-Post:List-Owner:List-Archive; bh=qKMy6DBsT0cAYAQ1vf7JwrLCMSPsaUNINYylZGuz7vQ=; b=BPfjl3IY4jJsJzNlGZPoykv6M2 oQoUIsg1KADefHa2kK5loXXfyU5072UQQ4PQR/Un2z/KslRafUOLOiDOsUqJuVHfkl/SM62RrtxBj tmX9NAd3pbHUcX7SWW8D2PbwnfPZ0cPBcWEeEfDWg/OkAsEh0tft+YUPzt5Qad4ZOCC0=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Type:Content-Transfer-Encoding:MIME-Version:Message-ID:Reply-To: References:Subject:List-Unsubscribe:List-Id:Cc:To:Date:From:Sender:Content-ID :Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To: Resent-Cc:Resent-Message-ID:In-Reply-To:List-Help:List-Subscribe:List-Post: List-Owner:List-Archive; bh=qKMy6DBsT0cAYAQ1vf7JwrLCMSPsaUNINYylZGuz7vQ=; b=k lIiZBlZmAvKF47GkqSwfJtcMjgdDc3L5ou2Czd1o2FbSwCvp13j+OSgCTdygOs5RO2etUaoN4bh91 dkcGjTMYvk+HxrwoD2uvDuXxtAJPAti6gN9qqy4YqCZ2Xp7dFTtqyv3AMp/qR9mBg5h1EsIM6fFxm 8MCiItvWgu8A4Md4=; Received: from mail-wr1-f48.google.com ([209.85.221.48]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1r5TH5-00C1sq-HD for openvpn-devel@lists.sourceforge.net; Tue, 21 Nov 2023 16:06:59 +0000 Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-3316a4bc37dso2874065f8f.2 for ; Tue, 21 Nov 2023 08:06:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvpn.net; s=google; t=1700582809; x=1701187609; darn=lists.sourceforge.net; h=user-agent:content-disposition:content-transfer-encoding :mime-version:message-id:reply-to:references:subject :list-unsubscribe:list-id:auto-submitted:cc:to:date:from:from:to:cc :subject:date:message-id:reply-to; bh=qKMy6DBsT0cAYAQ1vf7JwrLCMSPsaUNINYylZGuz7vQ=; b=c6HXxRFsz3Ds9bhf3M7skfpA5UdPhiZeMPugMeanJgWLJVLAid6BzAswFlaZuitdnZ GB6/aDsTbs7B6ygd/9R+kc4YkY+vEplF5drUXCbgNrCv3a0qKlsxAntkZezAOOxbrRWx aq+3d9YSXerFOmtBgjsaqp+ruXknG0PAjQTrfdBaigvRyZPnOoW4LHcBY5Pz0pO6rgO9 bauRv5WTemDuwqjfvtmOO10HHy474rrpPsaKnMo+4rarpvYGBxwls81god4W2N0LDe6d X7nie8XVALvp/ma5AqGKygtrtT8suEHvY/pAGF8a1W4twiXDIPMkmpMUUeVS1vTtWHpT iA5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700582809; x=1701187609; h=user-agent:content-disposition:content-transfer-encoding :mime-version:message-id:reply-to:references:subject :list-unsubscribe:list-id:auto-submitted:cc:to:date:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=qKMy6DBsT0cAYAQ1vf7JwrLCMSPsaUNINYylZGuz7vQ=; b=shT9ytFkCPPejAGpW46ZoHsyaxuVtBA+kkNyETC3SPlXBc0y0L8IGabrz91YGTmXRD R4UyqqruO5/HWM8jLDgkfTR5TtMKjOq7/S+QYvkg7WKLqmQtalvZkXFB/h0ez3KDHgQI S9kGDKXhZnyqCvEsPAwG2f4pSAmulF3Z+mBlFS8uK9/h8iff3KV2O2tmT/oE+VGDFC0K ndKt49d3TWaVbdcbLhonMi4VCpjDVT+wmEez39duYZtza3br49OmwEssVJkaaNGA3AWv dl8NAe5cqLUGHj8x9yrjFUFbLWCF/H9YSPtA9HHmMks+FZyu+Nki6+Mo2JKpH3+2O5t8 OlrQ== X-Gm-Message-State: AOJu0YzbB7Y/6geFrCPho1K4PG0rnE6DLFrbUT0WvSjhBREgNune8FEH 3CubO/wQqQu/I0WnhhjyszooWEh7wRKVBKjmKLw= X-Received: by 2002:a5d:6885:0:b0:332:cb51:34eb with SMTP id h5-20020a5d6885000000b00332cb5134ebmr3451327wru.41.1700582808013; Tue, 21 Nov 2023 08:06:48 -0800 (PST) Received: from gerrit.openvpn.in (ec2-18-159-0-78.eu-central-1.compute.amazonaws.com. [18.159.0.78]) by smtp.gmail.com with ESMTPSA id r15-20020a5d6c6f000000b00332cb17f87csm5088116wrz.5.2023.11.21.08.06.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 08:06:47 -0800 (PST) From: "plaisthos (Code Review)" X-Google-Original-From: "plaisthos (Code Review)" X-Gerrit-PatchSet: 1 Date: Tue, 21 Nov 2023 16:06:46 +0000 To: flichtenheld Auto-Submitted: auto-generated X-Gerrit-MessageType: newchange X-Gerrit-Change-Id: Ia797c8801fa9a9bc10b6674efde5fdbd7132e4a8 X-Gerrit-Change-Number: 454 X-Gerrit-Project: openvpn X-Gerrit-ChangeURL: X-Gerrit-Commit: 48621e1f08fa009181d05e1aacee93cfcf2e98bd References: Message-ID: <83c5e06d672c765f7d6bd8646088869e8a4e04da-HTML@gerrit.openvpn.net> MIME-Version: 1.0 User-Agent: Gerrit/3.8.2 X-Spam-Score: -0.2 (/) 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: Attention is currently required from: flichtenheld. Hello flichtenheld, I'd like you to do a code review. Please visit Content analysis details: (-0.2 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.221.48 listed in wl.mailspike.net] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [209.85.221.48 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 WEIRD_PORT URI: Uses non-standard port number for HTTP 0.0 HTML_MESSAGE BODY: HTML included in message -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.0 T_SCC_BODY_TEXT_LINE No description available. 0.0 T_KAM_HTML_FONT_INVALID Test for Invalidly Named or Formatted Colors in HTML X-Headers-End: 1r5TH5-00C1sq-HD Subject: [Openvpn-devel] [S] Change in openvpn[master]: 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: , Reply-To: arne-openvpn@rfc2549.org, openvpn-devel@lists.sourceforge.net, frank@lichtenheld.com Cc: openvpn-devel Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1783190390597761912?= X-GMAIL-MSGID: =?utf-8?q?1783190390597761912?= X-getmail-filter-classifier: gerrit message type newchange Attention is currently required from: flichtenheld. Hello flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/454?usp=email to review the following change. Change subject: Fix unaligned access in macOS/Solaris hwaddr ...................................................................... Fix unaligned access in macOS/Solaris hwaddr The undefined behaviour USAN clang checker found this. This fix is a bit messy but so are the original structures. Change-Id: Ia797c8801fa9a9bc10b6674efde5fdbd7132e4a8 --- M src/openvpn/route.c 1 file changed, 33 insertions(+), 8 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/54/454/1 diff --git a/src/openvpn/route.c b/src/openvpn/route.c index ff64938..ab5bff7 100644 --- a/src/openvpn/route.c +++ b/src/openvpn/route.c @@ -3643,7 +3643,6 @@ if (rgi->flags & RGI_IFACE_DEFINED) { struct ifconf ifc; - struct ifreq *ifr; const int bufsize = 4096; char *buffer; @@ -3668,22 +3667,48 @@ for (cp = buffer; cp <= buffer + ifc.ifc_len - sizeof(struct ifreq); ) { - ifr = (struct ifreq *)cp; + struct ifreq ifr = { 0 }; + /* this is not always using an 8 byte 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; + /* This is a confusing member access on multiple levels. + * + * struct sockaddr_dl is 20 bytes in size and has + * 12 bytes space for the hw address (6 bytes) + * and Ethernet interface name (max 16 bytes) + * + * So if the interface name is more than 6 byte, it + * extends beyond the struct. + * + * This struct is embedded into ifreq that has + * 16 bytes for a sockaddr and also expects this + * struct to potentially extend beyond the bounds of + * the struct. + * + * Since we only copied 32 bytes from cp to ifr but sdl + * might extend after ifr's end, we need to copy from + * cp directly to avoid missing out on extra bytes + * behind the struct + */ + const size_t sock_dl_len = max_int((int) (sizeof(struct sockaddr_dl)), + (int) (ifr.ifr_addr.sa_len)); + + struct sockaddr_dl *sdl = gc_malloc(sock_dl_len, true, &gc); + memcpy(sdl, cp + offsetof(struct ifreq, ifr_addr), sock_dl_len); memcpy(rgi->hwaddr, LLADDR(sdl), 6); rgi->flags |= RGI_HWADDR_DEFINED; }