From: David Yang <mmyangfl@gmail.com>
To: netdev@vger.kernel.org
Cc: David Yang <mmyangfl@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
linux-kernel@vger.kernel.org
Subject: [PATCH net-next] net: netlink: warn on overwriting extack message
Date: Wed, 13 May 2026 22:32:16 +0800 [thread overview]
Message-ID: <20260513143219.3327287-1-mmyangfl@gmail.com> (raw)
When NL_SET_ERR_MSG is called more than once on the same extack, the
existing message is silently overwritten. This is hard to detect via
static analysis. Emit a rate-limited warning so these cases become
visible.
Signed-off-by: David Yang <mmyangfl@gmail.com>
---
include/linux/netlink.h | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/include/linux/netlink.h b/include/linux/netlink.h
index 882e9c1b6c1d..f6538304745f 100644
--- a/include/linux/netlink.h
+++ b/include/linux/netlink.h
@@ -90,6 +90,13 @@ struct netlink_ext_ack {
char _msg_buf[NETLINK_MAX_FMTMSG_LEN];
};
+#define __NL_SET_MSG(__extack, __msg) do { \
+ if (__extack->_msg) \
+ net_warn_ratelimited("overriding extack: %s", \
+ __extack->_msg); \
+ __extack->_msg = __msg; \
+} while (0)
+
/* Always use this macro, this allows later putting the
* message into a separate section or such for things
* like translation or listing all possible messages.
@@ -102,7 +109,7 @@ struct netlink_ext_ack {
do_trace_netlink_extack(__msg); \
\
if (__extack) \
- __extack->_msg = __msg; \
+ __NL_SET_MSG(__extack, __msg); \
} while (0)
/* We splice fmt with %s at each end even in the snprintf so that both calls
@@ -121,7 +128,7 @@ struct netlink_ext_ack {
\
do_trace_netlink_extack(__extack->_msg_buf); \
\
- __extack->_msg = __extack->_msg_buf; \
+ __NL_SET_MSG(__extack, __extack->_msg_buf); \
} while (0)
#define NL_SET_ERR_MSG_MOD(extack, msg) \
@@ -156,7 +163,7 @@ struct netlink_ext_ack {
do_trace_netlink_extack(__msg); \
\
if (__extack) { \
- __extack->_msg = __msg; \
+ __NL_SET_MSG(__extack, __msg); \
__extack->bad_attr = (attr); \
__extack->policy = (pol); \
} \
@@ -176,7 +183,7 @@ struct netlink_ext_ack {
\
do_trace_netlink_extack(__extack->_msg_buf); \
\
- __extack->_msg = __extack->_msg_buf; \
+ __NL_SET_MSG(__extack, __extack->_msg_buf); \
__extack->bad_attr = (attr); \
__extack->policy = (pol); \
} while (0)
--
2.53.0
next reply other threads:[~2026-05-13 14:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-13 14:32 David Yang [this message]
2026-05-14 23:57 ` [PATCH net-next] net: netlink: warn on overwriting extack message Jakub Kicinski
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=20260513143219.3327287-1-mmyangfl@gmail.com \
--to=mmyangfl@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.