From: "ordex (Code Review)" Date: Thu, 31 Oct 2024 09:18:22 +0000 In-Reply-To: References: Reply-To: a@...2181..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="X0w/ZfhwsK0="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: sitnl: replace NLMSG_TAIL macro with noinline function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --X0w/ZfhwsK0= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, ordex, plaisthos. Hello flichtenheld, plaisthos, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/788?usp=3Demail to look at the new patch set (#4). The following approvals got outdated and were removed: Code-Review+2 by flichtenheld The change is no longer submittable: Code-Review and checks~ChecksSubmitRul= e are unsatisfied now. Change subject: sitnl: replace NLMSG_TAIL macro with noinline function ...................................................................... sitnl: replace NLMSG_TAIL macro with noinline function The NLMSG_TAIL macro is confusing gcc when compiling with -O3, leading to warnings like: networking_sitnl.c:143:9: warning: writing 4 bytes into a region of size 0 = [-Wstringop-overflow=3D] 143 | memcpy(RTA_DATA(rta), data, alen); | ^ networking_sitnl.c:101:21: note: at offset [72, 88] into destination object= =E2=80=98n=E2=80=99 of size 16 101 | struct nlmsghdr n; | ^ (Above warnings are critical on Fedora 40 as they are turned into errors) Replacing the macro with a function is also not effective because gcc will inline it and get confused again. The only way out is to write a function that never gets inline'd and replace the macro with it. Tested on linux with gcc and clang. Change-Id: I9306a590a10a7d5cba32abe06d269494fec41ba6 Signed-off-by: Antonio Quartulli --- M src/openvpn/networking_sitnl.c 1 file changed, 21 insertions(+), 8 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/88/788/4 diff --git a/src/openvpn/networking_sitnl.c b/src/openvpn/networking_sitnl.c index f53f5ee..6b750e8 100644 --- a/src/openvpn/networking_sitnl.c +++ b/src/openvpn/networking_sitnl.c @@ -52,21 +52,34 @@ } \ } -#define NLMSG_TAIL(nmsg) \ - ((struct rtattr *)(((uint8_t *)(nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len= ))) - #define SITNL_NEST(_msg, _max_size, _attr) \ ({ \ - struct rtattr *_nest =3D NLMSG_TAIL(_msg); \ + struct rtattr *_nest =3D sitnl_nlmsg_tail(_msg); \ SITNL_ADDATTR(_msg, _max_size, _attr, NULL, 0); \ _nest; \ }) -#define SITNL_NEST_END(_msg, _nest) \ - { \ - _nest->rta_len =3D (void *)NLMSG_TAIL(_msg) - (void *)_nest; \ +#define SITNL_NEST_END(_msg, _nest) \ + { \ + _nest->rta_len =3D (void *)sitnl_nlmsg_tail(_msg) - (void *)_nest;= \ } +/* This function was originally implemented as a macro, but compiling with + * gcc and -O3 was getting confused about the math and thus raising + * security warnings on subsequent memcpy() calls. + * + * Converting the macro to a function was not enough, because gcc was still + * inlining it and falling in the same math trap. + * + * The only way out to avoid any warning/error is to force the function to + * not be inline'd. + */ +static __attribute__ ((noinline)) void * +sitnl_nlmsg_tail(const struct nlmsghdr *nlh) +{ + return (unsigned char *)nlh + NLMSG_ALIGN(nlh->nlmsg_len); +} + /** * Generic address data structure used to pass addresses and prefixes as * argument to AF family agnostic functions @@ -130,7 +143,7 @@ return -EMSGSIZE; } - rta =3D NLMSG_TAIL(n); + rta =3D sitnl_nlmsg_tail(n); rta->rta_type =3D type; rta->rta_len =3D len; -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/788?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: I9306a590a10a7d5cba32abe06d269494fec41ba6 Gerrit-Change-Number: 788 Gerrit-PatchSet: 4 Gerrit-Owner: ordex Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-Attention: ordex Gerrit-MessageType: newpatchset --X0w/ZfhwsK0= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, ordex, plaisthos. <= /p>

ordex uploaded patch set #4 to this change.

View Change

The following approvals got outdated and were removed: Code-Review+2 by flichtenheld

The change is no longer submittable: Co= de-Review and checks~ChecksSubmitRule are unsatisfied now.

sitnl: replace N=
LMSG_TAIL macro with noinline function

The NLMSG_TAIL macro is confu= sing gcc when compiling with -O3, leading
to warnings like:

netwo= rking_sitnl.c:143:9: warning: writing 4 bytes into a region of size 0 [-Wst= ringop-overflow=3D]
143 | memcpy(RTA_DATA(rta), data, alen); | ^
networking_sitnl.c:101:21: note: at offset [72, 88] = into destination object =E2=80=98n=E2=80=99 of size 16
101 | struc= t nlmsghdr n;
| ^

(Above warnings are c= ritical on Fedora 40 as they are turned into errors)

Replacing the m= acro with a function is also not effective because gcc
will inline it an= d get confused again.

The only way out is to write a function that n= ever gets inline'd and
replace the macro with it.

Tested on l= inux with gcc and clang.

Change-Id: I9306a590a10a7d5cba32abe06d26949= 4fec41ba6
Signed-off-by: Antonio Quartulli <antonio@...2726...>---
M src/openvpn/networking_sitnl.c
1 file changed, 21 insertions(+= ), 8 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn=
 refs/changes/88/788/4
diff --git a/src/openvpn/networking_sitnl.c =
b/src/openvpn/networking_sitnl.c
index f53f5ee..6b750e8 100= 644
--- a/src/openvpn/networking_sitnl.c
++= + b/src/openvpn/networking_sitnl.c
@@ -52,21 +52,34 @@
} = \
}

-#define NLMSG_TAIL(nmsg) \
- ((struct rtattr *)(((uint8_t *)(nmsg)) = + NLMSG_ALIGN((nmsg)->nlmsg_len)))
-
#define SITNL_NEST(_msg, _max_size, _attr= ) \
({ = \
- = struct rtattr *_nest =3D NLMSG_TAIL(_msg); \
+ struct rtattr *_nest =3D sitnl_n= lmsg_tail(_msg); \
SITNL_ADDATTR(_msg, _max_size,= _attr, NULL, 0); \
_nest; = \
})

-#define SITNL_NEST_END(_msg, _nest)= \

- { = \
- _nest-= >rta_len =3D (void *)NLMSG_TAIL(_msg) - (void *)_nest; \
+#define SITNL_NEST_END(_msg, _nest= ) \
+ { = \
+ = _nest->rta_len =3D (void *)sitnl_nlmsg_tail(_msg) - (void *)_nest= ; \
}

+/* This function was originally implemented as a m= acro, but compiling with
+ * gcc and -O3 was getting confused about the math and thus raising
+ * security warnings o= n subsequent memcpy() calls.
+ *
+ * Conve= rting the macro to a function was not enough, because gcc was still<= br>+ * inlining it and falling = in the same math trap.
+ * The only wa= y out to avoid any warning/error is to force the function to
+ * not be inline'd.

= + */
+static __attribute__ ((noinline)) void *
+sitnl_nlmsg_tail(const st= ruct nlmsghdr *nlh)
+= {
+ return (unsign= ed char *)nlh + NLMSG_ALIGN(nlh->nlmsg_len);
+}
+
/**
* Generic address data st= ructure used to pass addresses and prefixes as
* argument= to AF family agnostic functions
@@ -130,7 +143,7 @@=
return -EMSGSIZE;
}

- rta =3D NLMSG_T= AIL(n);
+ rta =3D = sitnl_nlmsg_tail(n);
rta->rta_type =3D type;=
rta->rta_len =3D len;

<= /span>

To view, visit change 788. To unsubscribe, or for help writin= g mail filters, visit settin= gs.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I9306a590a10a7d5cba32abe06d2= 69494fec41ba6
Gerrit-Change-Number: 788
Gerrit-PatchSet: 4
Gerrit-Owner: ordex <a@...2181...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-Attention: ordex <a@...2181...> <= /div>
Gerrit-MessageType: newpatchset
--X0w/ZfhwsK0=--