From: Stefano Brivio <sbrivio@redhat.com>
To: passt-dev@passt.top
Subject: [PATCH v2] udp: Ignore bogus -Wstringop-overread for write() from gcc 12.1
Date: Thu, 19 May 2022 16:08:06 +0200 [thread overview]
Message-ID: <20220519140806.1979431-1-sbrivio@redhat.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 2639 bytes --]
With current OpenSUSE Tumbleweed on aarch64 (gcc-12-1.3.aarch64) and
on x86_64 (gcc-12-1.4.x86_64), but curiously not on armv7hl
(gcc-12-1.3.armv7hl), gcc warns about using the _pointer_ to the
802.3 header to write the whole frame to the tap descriptor:
reading between 62 and 4294967357 bytes from a region of size 14
which is bogus:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103483
Probably declaring udp_sock_fill_data_v{4,6}() as noinline would
"fix" this, but that's on the data path, so I'd rather not. Use
a gcc pragma instead.
Signed-off-by: Stefano Brivio <sbrivio(a)redhat.com>
---
v2: LLVM 13.0.1 doesn't know about -Wstringop-overread, and clang-tidy
warns about the unknown diagnostic pragma: make it conditional
udp.c | 4 ++++
util.h | 18 ++++++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/udp.c b/udp.c
index f425d14..98e3eaa 100644
--- a/udp.c
+++ b/udp.c
@@ -714,8 +714,10 @@ static void udp_sock_fill_data_v4(const struct ctx *c, int n,
b->uh.len = htons(udp4_l2_mh_sock[n].msg_len + sizeof(b->uh));
if (c->mode == MODE_PASTA) {
+ PRAGMA_STRINGOP_OVERREAD_IGNORE
if (write(c->fd_tap, &b->eh, sizeof(b->eh) + ip_len) < 0)
debug("tap write: %s", strerror(errno));
+ PRAGMA_STRINGOP_OVERREAD_IGNORE_POP
pcap((char *)&b->eh, sizeof(b->eh) + ip_len);
return;
@@ -813,8 +815,10 @@ static void udp_sock_fill_data_v6(const struct ctx *c, int n,
b->ip6h.hop_limit = 255;
if (c->mode == MODE_PASTA) {
+ PRAGMA_STRINGOP_OVERREAD_IGNORE
if (write(c->fd_tap, &b->eh, sizeof(b->eh) + ip_len) < 0)
debug("tap write: %s", strerror(errno));
+ PRAGMA_STRINGOP_OVERREAD_IGNORE_POP
pcap((char *)&b->eh, sizeof(b->eh) + ip_len);
return;
diff --git a/util.h b/util.h
index f85a87a..3ccd208 100644
--- a/util.h
+++ b/util.h
@@ -102,6 +102,24 @@ enum {
(void *)(arg)); \
} while (0)
+
+#ifdef __has_warning
+# if __has_warning("-Wstringop-overread")
+# define PRAGMA_STRINGOP_OVERREAD_IGNORE \
+ _Pragma("GCC diagnostic ignored \"-Wstringop-overread\"")
+# define PRAGMA_STRINGOP_OVERREAD_IGNORE_POP \
+ _Pragma("GCC diagnostic pop")
+# else
+# define PRAGMA_STRINGOP_OVERREAD_IGNORE
+# define PRAGMA_STRINGOP_OVERREAD_IGNORE_POP
+# endif
+#else
+# define PRAGMA_STRINGOP_OVERREAD_IGNORE \
+ _Pragma("GCC diagnostic ignored \"-Wstringop-overread\"")
+# define PRAGMA_STRINGOP_OVERREAD_IGNORE_POP \
+ _Pragma("GCC diagnostic pop")
+#endif
+
#if __BYTE_ORDER == __BIG_ENDIAN
#define L2_BUF_ETH_IP4_INIT \
{ \
--
@@ -102,6 +102,24 @@ enum {
(void *)(arg)); \
} while (0)
+
+#ifdef __has_warning
+# if __has_warning("-Wstringop-overread")
+# define PRAGMA_STRINGOP_OVERREAD_IGNORE \
+ _Pragma("GCC diagnostic ignored \"-Wstringop-overread\"")
+# define PRAGMA_STRINGOP_OVERREAD_IGNORE_POP \
+ _Pragma("GCC diagnostic pop")
+# else
+# define PRAGMA_STRINGOP_OVERREAD_IGNORE
+# define PRAGMA_STRINGOP_OVERREAD_IGNORE_POP
+# endif
+#else
+# define PRAGMA_STRINGOP_OVERREAD_IGNORE \
+ _Pragma("GCC diagnostic ignored \"-Wstringop-overread\"")
+# define PRAGMA_STRINGOP_OVERREAD_IGNORE_POP \
+ _Pragma("GCC diagnostic pop")
+#endif
+
#if __BYTE_ORDER == __BIG_ENDIAN
#define L2_BUF_ETH_IP4_INIT \
{ \
--
2.35.1
reply other threads:[~2022-05-19 14:08 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220519140806.1979431-1-sbrivio@redhat.com \
--to=sbrivio@redhat.com \
--cc=passt-dev@passt.top \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).