From: "cron2 (Code Review)" Date: Sat, 30 Dec 2023 15:03:43 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <8299961179fe22a388dd7020a95bbe000bb31897-EmailReviewComments-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="Hrs6lZqZeSM="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Fix unaligned access in macOS, FreeBSD, Solaris hwaddr List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: flichtenheld , openvpn-devel --Hrs6lZqZeSM= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: plaisthos. cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/ope= nvpn/+/454?usp=3Demail ) Change subject: Fix unaligned access in macOS, FreeBSD, Solaris hwaddr ...................................................................... Patch Set 2: Code-Review-1 (5 comments) Patchset: PS2: The ifr memcpy() is well understood and necessary. The sockaddr_dl memcpy(= ) needs at least some better comments, but maybe it's not necessary at all. File src/openvpn/route.c: http://gerrit.openvpn.net/c/openvpn/+/454/comment/b7cb53d2_d5e9c975 : PS2, Line 3677: * requires */ "need to memcpy() to a strict ifr to force 8-byte alignment required for me= mber access" http://gerrit.openvpn.net/c/openvpn/+/454/comment/3ec0b40a_9dd8ee38 : PS2, Line 3691: * struct sockaddr_dl is 20 bytes in si= ze and has On FreeBSD 13 this is ``` struct sockaddr_dl { u_char sdl_len; /* Total length of sockaddr */ u_char sdl_family; /* AF_LINK */ u_short sdl_index; /* if !=3D 0, system given index for interf= ace */ u_char sdl_type; /* interface type */ u_char sdl_nlen; /* interface name length, no trailing 0 req= d. */ u_char sdl_alen; /* link level address length */ u_char sdl_slen; /* link layer selector length */ char sdl_data[46]; /* minimum work area, can be larger; contains both if name and ll address */ }; ``` so the "20 bytes" comment should be qualified "on some of the BSDs" or so (= NetBSD indeed has only 20 bytes). OpenBSD has ``` char sdl_data[24]; /* minimum work area, can be larger; contains both if name and ll address; big enough for IFNAMSIZ plus 8byte ll ad= dr */ ``` http://gerrit.openvpn.net/c/openvpn/+/454/comment/5b60619c_c908b9eb : PS2, Line 3693: * and Ethernet interface name (max 16 = bytes) the wording here confused me ("if it's hw address and interface name, in th= is order, why would we care about size of interface name?") - I'd swap the = order around ("..for interface name (max 16 bytes) and hw address (max 6 by= tes"). http://gerrit.openvpn.net/c/openvpn/+/454/comment/e6546e64_f9ad06e2 : PS2, Line 3703: * Since we only copied 32 bytes from c= p to ifr but sdl If ifr_addr.sa_len is >16 (because "long address") the max() above will mak= e us copy more than 32 bytes. So maybe we already have everything we need = here, and can spare ourselves the double twist? OTOH, the code below does max(sizeof(), sa_len) - so if sa_len is shorter, = we might copy too much with the second copy? -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/454?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Ia797c8801fa9a9bc10b6674efde5fdbd7132e4a8 Gerrit-Change-Number: 454 Gerrit-PatchSet: 2 Gerrit-Owner: plaisthos Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Comment-Date: Sat, 30 Dec 2023 15:03:43 +0000 Gerrit-HasComments: Yes Gerrit-Has-Labels: Yes Gerrit-MessageType: comment --Hrs6lZqZeSM= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: plaisthos.

Patch set 2:Code-Review -1=

Vi= ew Change

5 comments:

  • Patchset:

    • Patch Set #2:

      The ifr memcpy() is well understood and neces= sary. The sockaddr_dl memcpy() needs at least some better comments, but ma= ybe it's not necessary at all.

  • File src/openvpn/route.c:

    • Patch Set #2, Line 3677: * requires */

      "need to memcpy() to a= strict ifr to force 8-byte alignment required for member access"

      <= /li>
    • Patch Set #2, Line 3691: * struct sockaddr_dl is 20 bytes in siz= e and has

      On FreeBSD 13 this is

      ```
      struct sockaddr_dl {
      u_char sd= l_len; /* Total length of sockaddr */
      u_char sdl_family;= /* AF_LINK */
      u_short sdl_index; /* if !=3D 0, system = given index for interface */
      u_char sdl_type; /* interfac= e type */
      u_char sdl_nlen; /* interface name length, no t= railing 0 reqd. */
      u_char sdl_alen; /* link level address= length */
      u_char sdl_slen; /* link layer selector length= */
      char sdl_data[46]; /* minimum work area, can be larger;=
      contains both if name and ll address= */
      };
      ```

      so the "20 bytes" comment should be qualified "on s= ome of the BSDs" or so (NetBSD indeed has only 20 bytes). OpenBSD has=

      ```
      char sdl_data[24]; /* minimum work area, can be larger= ;
      contains both if name and ll addres= s;
      big enough for IFNAMSIZ plus 8byte= ll addr */
      ```
    • =

      Patch Set #2, Line 3693: * and Ethernet= interface name (max 16 bytes)

      the wording here confused me ("if it's hw= address and interface name, in this order, why would we care about size of= interface name?") - I'd swap the order around ("..for interf= ace name (max 16 bytes) and hw address (max 6 bytes").

    • Patch Set #2, Line 3703: * Since we only copied 32 bytes from cp to ifr but= sdl

      I= f ifr_addr.sa_len is >16 (because "long address") the max() ab= ove will make us copy more than 32 bytes. So maybe we already have everyth= ing we need here, and can spare ourselves the double twist?

      OTOH, the code below does ma= x(sizeof(), sa_len) - so if sa_len is shorter, we might copy too much with = the second copy?

To view, visit change 454. To unsubsc= ribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia797c8801fa9a9bc10b6674efde= 5fdbd7132e4a8
Gerrit-Change-Number: 454
Gerrit-PatchSet: 2
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Comment-Date: Sat, 30 Dec 2023 15:03:43= +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
--Hrs6lZqZeSM=--