Change in openvpn[master]: sitnl: replace NLMSG_TAIL macro with nlmsg_tail() function
A message that is not in the archive (sent off-list or not yet received): gerrit.1730209445000.I9306a590a10a7d5cba32abe06d269494fec41ba6@...2715...
Attention is currently required from: flichtenheld, plaisthos.
Hello plaisthos, flichtenheld,
I'd like you to do a code review.
Please visit
http://gerrit.openvpn.net/c/openvpn/+/788?usp=email
to review the following change.
Change subject: sitnl: replace NLMSG_TAIL macro with nlmsg_tail() function
......................................................................
sitnl: replace NLMSG_TAIL macro with nlmsg_tail() function
The NLMSG_TAIL macro never had any reason to exist, because libnl already provides a function doing exactly the same: nlmsg_tail().
Moreover, this macro was found to confuse gcc when compiling with -O3, which would result in subsequent warnings like:
networking_sitnl.c:143:9: warning: writing 4 bytes into a region of size 0 [-Wstringop-overflow=]
143 | memcpy(RTA_DATA(rta), data, alen);
| ^networking_sitnl.c:101:21: note: at offset [72, 88] into destination object ‘n’ of size 16
101 | struct nlmsghdr n;
| ^
(Above warnings are critical on Fedora 40 as they are turned into errors)
Delete the macro, replace it with nlmsg_tail() and get rid of the warnings.
---
M src/openvpn/networking_sitnl.c
1 file changed, 4 insertions(+), 6 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/88/788/1
src/openvpn/networking_sitnl.c +4 -6
@@ -40,6 +40,7 @@#include <sys/socket.h> #include <linux/netlink.h> #include <linux/rtnetlink.h> +#include <netlink/msg.h> #define SNDBUF_SIZE (1024 * 2)#define RCVBUF_SIZE (1024 * 4)
@@ -52,19 +53,16 @@ } \ } -#define NLMSG_TAIL (nmsg) \ - ((struct rtattr *)(((uint8_t *)(nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len))) -#define SITNL_NEST (_msg, _max_size, _attr) \ ({ \ - struct rtattr *_nest = NLMSG_TAIL(_msg); \ + struct rtattr *_nest = nlmsg_tail(_msg); \ SITNL_ADDATTR(_msg, _max_size, _attr, NULL, 0); \ _nest; \ })#define SITNL_NEST_END (_msg, _nest) \ { \ - _nest->rta_len = (void *)NLMSG_TAIL(_msg) - (void *)_nest; \ + _nest->rta_len = (void *)nlmsg_tail(_msg) - (void *)_nest; \ }/**
@@ -130,7 +128,7 @@return -EMSGSIZE ; } - rta =NLMSG_TAIL (n); + rta =nlmsg_tail (n); rta->rta_type = type; rta->rta_len = len;
Signature · 15 lines
To view, visit http://gerrit.openvpn.net/c/openvpn/+/788?usp=email To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I9306a590a10a7d5cba32abe06d269494fec41ba6 Gerrit-Change-Number: 788 Gerrit-PatchSet: 1 Gerrit-Owner: ordex <[email protected]...> Gerrit-Reviewer: flichtenheld <[email protected]...> Gerrit-Reviewer: plaisthos <[email protected]...> Gerrit-CC: openvpn-devel <[email protected]> Gerrit-Attention: plaisthos <[email protected]...> Gerrit-Attention: flichtenheld <[email protected]...> Gerrit-MessageType: newchange
[Openvpn-devel] [S] Change in openvpn[master]: sitnl: replace NLMSG_TAIL macro with noinline function
In reply to a message not in the archiveAttention is currently required from: flichtenheld, plaisthos.
Hello flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/788?usp=email
to look at the new patch set (#2).
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=]
143 | memcpy(RTA_DATA(rta), data, alen);
| ^networking_sitnl.c:101:21: note: at offset [72, 88] into destination object ‘n’ 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.
---
M src/openvpn/networking_sitnl.c
1 file changed, 11 insertions(+), 8 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/88/788/2
src/openvpn/networking_sitnl.c +11 -8
@@ -52,21 +52,24 @@ } \ } -#define NLMSG_TAIL (nmsg) \ - ((struct rtattr *)(((uint8_t *)(nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len))) -#define SITNL_NEST (_msg, _max_size, _attr) \ ({ \ - struct rtattr *_nest = NLMSG_TAIL(_msg); \ + struct rtattr *_nest = sitnl_nlmsg_tail(_msg); \ SITNL_ADDATTR(_msg, _max_size, _attr, NULL, 0); \ _nest; \ }) -#define SITNL_NEST_END (_msg, _nest) \ - { \ - _nest->rta_len = (void *)NLMSG_TAIL(_msg) - (void *)_nest; \ +#define SITNL_NEST_END (_msg, _nest) \ + { \ + _nest->rta_len = (void *)sitnl_nlmsg_tail(_msg) - (void *)_nest;\ } +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 +133,7 @@return -EMSGSIZE ; } - rta =NLMSG_TAIL (n); + rta =sitnl_nlmsg_tail (n); rta->rta_type = type; rta->rta_len = len;
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/788?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I9306a590a10a7d5cba32abe06d269494fec41ba6
Gerrit-Change-Number: 788
Gerrit-PatchSet: 2
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
[Openvpn-devel] [S] Change in openvpn[master]: sitnl: replace NLMSG_TAIL macro with noinline function
In reply to a message not in the archiveAttention is currently required from: ordex, plaisthos.
flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/788?usp=email )
Change subject: sitnl: replace NLMSG_TAIL macro with noinline function
......................................................................
Patch Set 2: Code-Review-1
(1 comment)
Patchset:
PS2:
Please fix uncrustify error
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/788?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I9306a590a10a7d5cba32abe06d269494fec41ba6
Gerrit-Change-Number: 788
Gerrit-PatchSet: 2
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Tue, 29 Oct 2024 17:20:36 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
[Openvpn-devel] [S] Change in openvpn[master]: sitnl: replace NLMSG_TAIL macro with noinline function
In reply to a message not in the archiveAttention 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=email
to look at the new patch set (#3).
The following approvals got outdated and were removed:
Code-Review-1 by flichtenheld
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=]
143 | memcpy(RTA_DATA(rta), data, alen);
| ^networking_sitnl.c:101:21: note: at offset [72, 88] into destination object ‘n’ 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.
---
M src/openvpn/networking_sitnl.c
1 file changed, 11 insertions(+), 8 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/88/788/3
src/openvpn/networking_sitnl.c +11 -8
@@ -52,21 +52,24 @@ } \ } -#define NLMSG_TAIL (nmsg) \ - ((struct rtattr *)(((uint8_t *)(nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len))) -#define SITNL_NEST (_msg, _max_size, _attr) \ ({ \ - struct rtattr *_nest = NLMSG_TAIL(_msg); \ + struct rtattr *_nest = sitnl_nlmsg_tail(_msg); \ SITNL_ADDATTR(_msg, _max_size, _attr, NULL, 0); \ _nest; \ }) -#define SITNL_NEST_END (_msg, _nest) \ - { \ - _nest->rta_len = (void *)NLMSG_TAIL(_msg) - (void *)_nest; \ +#define SITNL_NEST_END (_msg, _nest) \ + { \ + _nest->rta_len = (void *)sitnl_nlmsg_tail(_msg) - (void *)_nest; \ } +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 +133,7 @@return -EMSGSIZE ; } - rta =NLMSG_TAIL (n); + rta =sitnl_nlmsg_tail (n); rta->rta_type = type; rta->rta_len = len;
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/788?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I9306a590a10a7d5cba32abe06d269494fec41ba6
Gerrit-Change-Number: 788
Gerrit-PatchSet: 3
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-MessageType: newpatchset
[Openvpn-devel] [S] Change in openvpn[master]: sitnl: replace NLMSG_TAIL macro with noinline function
In reply to a message not in the archiveAttention is currently required from: ordex, plaisthos.
flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/788?usp=email )
Change subject: sitnl: replace NLMSG_TAIL macro with noinline function
......................................................................
Patch Set 3: Code-Review+2
(2 comments)
Commit Message:
http://gerrit.openvpn.net/c/openvpn/+/788/comment/cc4a5a68_3ea32735 :
PS3, Line 19: (Above warnings are critical on Fedora 40 as they are turned into errors) This is misleading. The warning is turned into an error due to -Werror, not due to new GCC version.
Patchset:
PS3:
Patch fixes the issue. Commit message is not completely right, but we might also fix that on submission.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/788?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I9306a590a10a7d5cba32abe06d269494fec41ba6
Gerrit-Change-Number: 788
Gerrit-PatchSet: 3
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Wed, 30 Oct 2024 13:56:57 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
[Openvpn-devel] [S] Change in openvpn[master]: sitnl: replace NLMSG_TAIL macro with noinline function
In reply to a message not in the archiveAttention 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=email
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~ChecksSubmitRule 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=]
143 | memcpy(RTA_DATA(rta), data, alen);
| ^networking_sitnl.c:101:21: note: at offset [72, 88] into destination object ‘n’ 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.
---
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
src/openvpn/networking_sitnl.c +21 -8
@@ -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 = NLMSG_TAIL(_msg); \ + struct rtattr *_nest = sitnl_nlmsg_tail(_msg); \ SITNL_ADDATTR(_msg, _max_size, _attr, NULL, 0); \ _nest; \ }) -#define SITNL_NEST_END (_msg, _nest) \ - { \ - _nest->rta_len = (void *)NLMSG_TAIL(_msg) - (void *)_nest; \ +#define SITNL_NEST_END (_msg, _nest) \ + { \ + _nest->rta_len = (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 =NLMSG_TAIL (n); + rta =sitnl_nlmsg_tail (n); rta->rta_type = type; rta->rta_len = len;
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/788?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I9306a590a10a7d5cba32abe06d269494fec41ba6
Gerrit-Change-Number: 788
Gerrit-PatchSet: 4
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-MessageType: newpatchset
[Openvpn-devel] [S] Change in openvpn[master]: sitnl: replace NLMSG_TAIL macro with noinline function
In reply to a message not in the archiveAttention is currently required from: flichtenheld, plaisthos.
ordex has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/788?usp=email )
Change subject: sitnl: replace NLMSG_TAIL macro with noinline function
......................................................................
Patch Set 4:
(1 comment)
Commit Message:
http://gerrit.openvpn.net/c/openvpn/+/788/comment/23b0d192_044e4c4d :
PS3, Line 19: (Above warnings are critical on Fedora 40 as they are turned into errors)
Quoted 1 line
This is misleading. The warning is turned into an error due to -Werror, not due to new GCC version.
my intent was to say that this is turned into an error on Fedora by default - the reason resides in Fedora. But I can mention -Werror and drop Fedora.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/788?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I9306a590a10a7d5cba32abe06d269494fec41ba6
Gerrit-Change-Number: 788
Gerrit-PatchSet: 4
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Thu, 31 Oct 2024 10:06:52 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Gerrit-MessageType: comment
[Openvpn-devel] [S] Change in openvpn[master]: sitnl: replace NLMSG_TAIL macro with noinline function
In reply to a message not in the archiveAttention is currently required from: flichtenheld, plaisthos.
Hello flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/788?usp=email
to look at the new patch set (#5).
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=]
143 | memcpy(RTA_DATA(rta), data, alen);
| ^networking_sitnl.c:101:21: note: at offset [72, 88] into destination object ‘n’ of size 16
101 | struct nlmsghdr n;
| ^
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.
---
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/5
src/openvpn/networking_sitnl.c +21 -8
@@ -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 = NLMSG_TAIL(_msg); \ + struct rtattr *_nest = sitnl_nlmsg_tail(_msg); \ SITNL_ADDATTR(_msg, _max_size, _attr, NULL, 0); \ _nest; \ }) -#define SITNL_NEST_END (_msg, _nest) \ - { \ - _nest->rta_len = (void *)NLMSG_TAIL(_msg) - (void *)_nest; \ +#define SITNL_NEST_END (_msg, _nest) \ + { \ + _nest->rta_len = (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 =NLMSG_TAIL (n); + rta =sitnl_nlmsg_tail (n); rta->rta_type = type; rta->rta_len = len;
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/788?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I9306a590a10a7d5cba32abe06d269494fec41ba6
Gerrit-Change-Number: 788
Gerrit-PatchSet: 5
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
[Openvpn-devel] [S] Change in openvpn[master]: sitnl: replace NLMSG_TAIL macro with noinline function
In reply to a message not in the archiveAttention is currently required from: flichtenheld, plaisthos.
ordex has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/788?usp=email )
Change subject: sitnl: replace NLMSG_TAIL macro with noinline function
......................................................................
Patch Set 5:
(1 comment)
Commit Message:
http://gerrit.openvpn.net/c/openvpn/+/788/comment/cbc959de_21931c3f :
PS3, Line 19: (Above warnings are critical on Fedora 40 as they are turned into errors)
Quoted 1 line
my intent was to say that this is turned into an error on Fedora by default - the reason resides in […]
I decided to drop that sentence at all. We all know that -Werror will make warnings critical.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/788?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I9306a590a10a7d5cba32abe06d269494fec41ba6
Gerrit-Change-Number: 788
Gerrit-PatchSet: 5
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Thu, 31 Oct 2024 10:17:34 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Comment-In-Reply-To: ordex <[email protected]...>
Gerrit-MessageType: comment
[Openvpn-devel] [S] Change in openvpn[master]: sitnl: replace NLMSG_TAIL macro with noinline function
In reply to a message not in the archiveAttention is currently required from: ordex, plaisthos.
flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/788?usp=email )
Change subject: sitnl: replace NLMSG_TAIL macro with noinline function
......................................................................
Patch Set 5: Code-Review+2
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/788?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I9306a590a10a7d5cba32abe06d269494fec41ba6
Gerrit-Change-Number: 788
Gerrit-PatchSet: 5
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Wed, 06 Nov 2024 13:12:22 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
PATCH v5 1/1 sitnl: replace NLMSG_TAIL macro with noinline function
In reply to a message not in the archiveFrom: Antonio Quartulli <[email protected]...>
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=]
143 | memcpy(RTA_DATA(rta), data, alen);
| ^networking_sitnl.c:101:21: note: at offset [72, 88] into destination object ‘n’ of size 16
101 | struct nlmsghdr n;
| ^
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.
---
This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/788
This mail reflects revision 5 of this Change.
Acked-by according to Gerrit (reflected above):
Frank Lichtenheld <[email protected]...>
src/openvpn/networking_sitnl.c +21 -8
@@ -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 = NLMSG_TAIL(_msg); \ + struct rtattr *_nest = sitnl_nlmsg_tail(_msg); \ SITNL_ADDATTR(_msg, _max_size, _attr, NULL, 0); \ _nest; \ }) -#define SITNL_NEST_END (_msg, _nest) \ - { \ - _nest->rta_len = (void *)NLMSG_TAIL(_msg) - (void *)_nest; \ +#define SITNL_NEST_END (_msg, _nest) \ + { \ + _nest->rta_len = (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 =NLMSG_TAIL (n); + rta =sitnl_nlmsg_tail (n); rta->rta_type = type; rta->rta_len = len;
[Openvpn-devel] [PATCH applied] Re: sitnl: replace NLMSG_TAIL macro with noinline function
I'm generally not very much in favour of working around compiler silliness, but this gets in the way of testing on Linux with -Werror, so what shall we do... - it's not time critical, so inline/noinline does not really matter much here. Tested on Gentoo and Ubuntu, client / server side, with and without DCO. So I claim it's a working replacement :-)
Your patch has been applied to the master branch.
commit 648e1606496adc6ec37a9d862810e465dab64dc0
Author: Antonio Quartulli Date: Wed Nov 6 14:17:03 2024 +0100
sitnl: replace NLMSG_TAIL macro with noinline function
Signed-off-by: Antonio Quartulli <[email protected]...>
Acked-by: Frank Lichtenheld <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg29710.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
[Openvpn-devel] [S] Change in openvpn[master]: sitnl: replace NLMSG_TAIL macro with noinline function
In reply to a message not in the archivecron2 has uploaded a new patch set (#6) to the change originally created by ordex. ( http://gerrit.openvpn.net/c/openvpn/+/788?usp=email )
The following approvals got outdated and were removed:
Code-Review+2 by flichtenheld
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=]
143 | memcpy(RTA_DATA(rta), data, alen);
| ^networking_sitnl.c:101:21: note: at offset [72, 88] into destination object ‘n’ of size 16
101 | struct nlmsghdr n;
| ^
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.
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg29710.html
---
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/6
src/openvpn/networking_sitnl.c +21 -8
@@ -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 = NLMSG_TAIL(_msg); \ + struct rtattr *_nest = sitnl_nlmsg_tail(_msg); \ SITNL_ADDATTR(_msg, _max_size, _attr, NULL, 0); \ _nest; \ }) -#define SITNL_NEST_END (_msg, _nest) \ - { \ - _nest->rta_len = (void *)NLMSG_TAIL(_msg) - (void *)_nest; \ +#define SITNL_NEST_END (_msg, _nest) \ + { \ + _nest->rta_len = (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 =NLMSG_TAIL (n); + rta =sitnl_nlmsg_tail (n); rta->rta_type = type; rta->rta_len = len;
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/788?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I9306a590a10a7d5cba32abe06d269494fec41ba6
Gerrit-Change-Number: 788
Gerrit-PatchSet: 6
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: newpatchset
[Openvpn-devel] [S] Change in openvpn[master]: sitnl: replace NLMSG_TAIL macro with noinline function
In reply to a message not in the archivecron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/788?usp=email )
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=]
143 | memcpy(RTA_DATA(rta), data, alen);
| ^networking_sitnl.c:101:21: note: at offset [72, 88] into destination object ‘n’ of size 16
101 | struct nlmsghdr n;
| ^
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.
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg29710.html
---
M src/openvpn/networking_sitnl.c
1 file changed, 21 insertions(+), 8 deletions(-)
src/openvpn/networking_sitnl.c +21 -8
@@ -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 = NLMSG_TAIL(_msg); \ + struct rtattr *_nest = sitnl_nlmsg_tail(_msg); \ SITNL_ADDATTR(_msg, _max_size, _attr, NULL, 0); \ _nest; \ }) -#define SITNL_NEST_END (_msg, _nest) \ - { \ - _nest->rta_len = (void *)NLMSG_TAIL(_msg) - (void *)_nest; \ +#define SITNL_NEST_END (_msg, _nest) \ + { \ + _nest->rta_len = (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 =NLMSG_TAIL (n); + rta =sitnl_nlmsg_tail (n); rta->rta_type = type; rta->rta_len = len;
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/788?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I9306a590a10a7d5cba32abe06d269494fec41ba6
Gerrit-Change-Number: 788
Gerrit-PatchSet: 6
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: merged