public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Simon Horman <horms@kernel.org>
To: Breno Leitao <leitao@debian.org>
Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com,
	kuba@kernel.org, pabeni@redhat.com, k-keiichi@bx.jp.nec.com,
	satyam@infradead.org, akpm@linux-foundation.org,
	thepacketgeek@gmail.com, asantostc@gmail.com,
	gustavold@gmail.com, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, kernel-team@meta.com
Subject: Re: [PATCH net 3/3] netconsole: propagate device name truncation in dev_name_store()
Date: Tue, 28 Apr 2026 10:23:12 +0100	[thread overview]
Message-ID: <20260428092312.GO900403@horms.kernel.org> (raw)
In-Reply-To: <ae85UEWf7dgJtmeS@gmail.com>

On Mon, Apr 27, 2026 at 03:26:29AM -0700, Breno Leitao wrote:
> On Sun, Apr 26, 2026 at 09:39:05AM +0100, Simon Horman wrote:
> > From: 'Simon Horman' <horms@kernel.org>
> > 
> > This is an AI-generated review of your patch. The human sending this
> > email has considered the AI review valid, or at least plausible.
> > Full review at: https://sashiko.dev
> > ---
> > netconsole: propagate device name truncation in dev_name_store()
> > 
> > This commit rejects interface name writes that exceed the size of the
> > destination buffer to avoid silently truncating names and binding to
> > unintended devices.
> > 
> > > diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
> > > index 4bef003d9df64..3914fb90f9afd 100644
> > > --- a/drivers/net/netconsole.c
> > > +++ b/drivers/net/netconsole.c
> > > @@ -816,6 +816,9 @@ static ssize_t dev_name_store(struct config_item *item, const char *buf,
> > >  {
> > >  	struct netconsole_target *nt = to_target(item);
> > >  
> > > +	if (count >= IFNAMSIZ)
> > > +		return -ENAMETOOLONG;
> > > +
> > 
> > Does this check incorrectly reject valid maximum-length interface names when
> > written with a trailing newline?
> > 
> > Standard userspace tools like echo append a trailing newline when writing to
> > configfs attributes. If userspace writes a 15-character name, the count will
> > be exactly 16 bytes.
> > 
> > Since IFNAMSIZ is 16, the condition count >= IFNAMSIZ evaluates to true,
> > causing dev_name_store() to reject the valid input with -ENAMETOOLONG.
> > 
> > Prior to this patch, strscpy() safely truncated the trailing newline by
> > copying the 15 characters and a NUL terminator.
> 
> That is a valid issue, if someone is using a 16-byte ifname, it will fail, for
> instance:
> 
> echo eth0123456789012 (15 chars) writes 16 bytes including the trailing \n
> 
> With IFNAMSIZ=16, a valid 15-character interface name written via echo arrives
> as 16 bytes (15 chars + \n), and the count >= IFNAMSIZ check rejects it — a
> regression compared to the prior strscpy() + trim_newline() behavior, which
> silently dropped the newline.
> 
> I think a better approach would be:
> 
>   size_t len = count;
> 
>   if (len && buf[len - 1] == '\n')
>       len--;
>   if (len >= IFNAMSIZ)
>       return -ENAMETOOLONG;
> 
> That keeps the length check consistent with what trim_newline() does to the
> stored string.
> 
> I will send a v2.

Thanks. The approach above looks good to me.

      reply	other threads:[~2026-04-28  9:23 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-23  9:41 [PATCH net 0/3] netconsole: configfs store callback fixes Breno Leitao
2026-04-23  9:41 ` [PATCH net 1/3] netconsole: return count instead of strnlen(buf, count) from store callbacks Breno Leitao
2026-04-26  8:46   ` Simon Horman
2026-04-27 10:00     ` Breno Leitao
2026-04-23  9:41 ` [PATCH net 2/3] netconsole: avoid clobbering userdatum value on truncated write Breno Leitao
2026-04-26  8:35   ` Simon Horman
2026-04-27 10:51     ` Breno Leitao
2026-04-23  9:41 ` [PATCH net 3/3] netconsole: propagate device name truncation in dev_name_store() Breno Leitao
2026-04-26  8:39   ` Simon Horman
2026-04-27 10:26     ` Breno Leitao
2026-04-28  9:23       ` Simon Horman [this message]

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=20260428092312.GO900403@horms.kernel.org \
    --to=horms@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=asantostc@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gustavold@gmail.com \
    --cc=k-keiichi@bx.jp.nec.com \
    --cc=kernel-team@meta.com \
    --cc=kuba@kernel.org \
    --cc=leitao@debian.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=satyam@infradead.org \
    --cc=thepacketgeek@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox