From: Ian Bridges <icb@fastmail.org>
To: Jiri Pirko <jiri@resnulli.us>,
"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>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-hardening@vger.kernel.org
Subject: [PATCH net-next] devlink: Replace strlcat() with seq_buf
Date: Fri, 3 Jul 2026 22:49:08 -0500 [thread overview]
Message-ID: <akiCtALVjd9TF8Xl@dev> (raw)
In preparation for removing the strlcat() API[1], replace its uses in
__devlink_compat_running_version().
The function accumulates a variable number of version strings into a
fixed buffer, which is what seq_buf is for. The seq_buf is anchored at
the end of any existing string in the buffer and each version string
is appended with a single seq_buf_printf(). The output is unchanged,
including under truncation.
Link: https://github.com/KSPP/linux/issues/370 [1]
Signed-off-by: Ian Bridges <icb@fastmail.org>
---
The patch was tested as follows, on top of net-next:
- x86_64 allmodconfig and allyesconfig builds of net/devlink/dev.o at
W=1 produce no warnings.
- A userspace comparison of the old and new construction ran with
randomized version lists and buffer contents across all buffer
fill levels. The outputs are byte-identical in every case,
including on overflow.
- The changed path was exercised in a QEMU guest through the ethtool
GDRVINFO ioctl against a netdevsim device, before and after the
change, with identical fw_version output.
net/devlink/dev.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/net/devlink/dev.c b/net/devlink/dev.c
index 57b2b8f03543..0d4301267171 100644
--- a/net/devlink/dev.c
+++ b/net/devlink/dev.c
@@ -5,6 +5,7 @@
*/
#include <linux/device.h>
+#include <linux/seq_buf.h>
#include <net/genetlink.h>
#include <net/sock.h>
#include "devl_internal.h"
@@ -1188,8 +1189,10 @@ static void __devlink_compat_running_version(struct devlink *devlink,
char *buf, size_t len)
{
struct devlink_info_req req = {};
+ size_t used = strnlen(buf, len);
const struct nlattr *nlattr;
struct sk_buff *msg;
+ struct seq_buf sb;
int rem, err;
msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
@@ -1201,6 +1204,8 @@ static void __devlink_compat_running_version(struct devlink *devlink,
if (err)
goto free_msg;
+ seq_buf_init(&sb, buf + used, len - used);
+
nla_for_each_attr_type(nlattr, DEVLINK_ATTR_INFO_VERSION_RUNNING,
(void *)msg->data, msg->len, rem) {
const struct nlattr *kv;
@@ -1208,8 +1213,8 @@ static void __devlink_compat_running_version(struct devlink *devlink,
nla_for_each_nested_type(kv, DEVLINK_ATTR_INFO_VERSION_VALUE,
nlattr, rem_kv) {
- strlcat(buf, nla_data(kv), len);
- strlcat(buf, " ", len);
+ seq_buf_printf(&sb, "%s ",
+ (const char *)nla_data(kv));
}
}
free_msg:
--
2.47.3
reply other threads:[~2026-07-04 3:49 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=akiCtALVjd9TF8Xl@dev \
--to=icb@fastmail.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=linux-hardening@vger.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.