Skip to content

Commit 5dab7c7

Browse files
leitaogregkh
authored andcommitted
netconsole: propagate device name truncation in dev_name_store()
[ Upstream commit 92ceb7b ] dev_name_store() calls strscpy(nt->np.dev_name, buf, IFNAMSIZ) without checking the return value. If userspace writes an interface name longer than IFNAMSIZ - 1, strscpy() silently truncates and returns -E2BIG, but the function ignores it and reports a fully successful write back to userspace. If a real interface happens to match the truncated name, netconsole will bind to the wrong device on the next enable, sending kernel logs and panic output to an unintended network segment with no indication to userspace that anything was rewritten. Reject writes whose length cannot fit in nt->np.dev_name up front: if (count >= IFNAMSIZ) return -ENAMETOOLONG; This is not a big deal of a problem, but, it is still the correct approach. Fixes: 0bcc181 ("[NET] netconsole: Support dynamic reconfiguration using configfs") Signed-off-by: Breno Leitao <leitao@debian.org> Link: https://patch.msgid.link/20260427-netconsole_ai_fixes-v2-3-59965f29d9cc@debian.org Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 7b54426 commit 5dab7c7

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

drivers/net/netconsole.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,13 @@ static ssize_t dev_name_store(struct config_item *item, const char *buf,
502502
size_t count)
503503
{
504504
struct netconsole_target *nt = to_target(item);
505+
size_t len = count;
506+
507+
/* Account for a trailing newline appended by tools like echo */
508+
if (len && buf[len - 1] == '\n')
509+
len--;
510+
if (len >= IFNAMSIZ)
511+
return -ENAMETOOLONG;
505512

506513
mutex_lock(&dynamic_netconsole_mutex);
507514
if (nt->enabled) {

0 commit comments

Comments
 (0)