Subject: Re: [PATCH] netconsole: allow selection of egress interface via MAC address

From: Uday Shankar <[email-masked]>
Date: Thu, 12 Dec 2024 14:59:54 -0700

On Thu, Dec 12, 2024 at 01:34:12PM +0100, Paolo Abeni wrote:
> On 12/11/24 03:18, Uday Shankar wrote:
> > +static ssize_t local_mac_store(struct config_item *item, const char *buf,
> > +			       size_t count)
> > +{
> > +	struct netconsole_target *nt = to_target(item);
> > +	u8 local_mac[ETH_ALEN];
> > +	ssize_t ret = -EINVAL;
> > +
> > +	mutex_lock(&dynamic_netconsole_mutex);
> > +	if (nt->enabled) {
> > +		pr_err("target (%s) is enabled, disable to update parameters\n",
> > +		       config_item_name(&nt->group.cg_item));
> > +		goto out_unlock;
> > +	}
> > +
> > +	if (!mac_pton(buf, local_mac))
> > +		goto out_unlock;
> > +	if (buf[3 * ETH_ALEN - 1] && buf[3 * ETH_ALEN - 1] != '\n')
> > +		goto out_unlock;
> 
> I think you should instead check 'count >= 3 * ETH_ALEN', and do such
> check before calling 'mac_pton'.

Is that needed? mac_pton has an internal check based on strnlen, which
is guaranteed to succeed because the kernfs layer will NUL-terminate buf
for us.