[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5cf6cfc8f5bc4808b37e21fcfa7cafc7@AcuMS.aculab.com>
Date: Fri, 18 Feb 2022 21:01:15 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'Tom Lendacky' <thomas.lendacky@....com>,
"netdev@...r.kernel.org" <netdev@...r.kernel.org>
CC: David Miller <davem@...emloft.net>,
Shyam-sundar S-k <Shyam-sundar.S-k@....com>,
Anthony Pighin <anthony.pighin@...ia.com>,
"Rasmus Villemoes" <linux@...musvillemoes.dk>
Subject: RE: [PATCH net] net: amd-xgbe: Replace kasprintf() with snprintf()
for debugfs name
From: Tom Lendacky
> Sent: 18 February 2022 20:05
>
> It was reported that using kasprintf() produced a kernel warning as the
> network interface name was being changed by udev rules at the same time
> that the debugfs entry for the device was being created.
What was the error?
I'm guessing the length changed and that made kvasprintf() unhappy??
...
> - buf = kasprintf(GFP_KERNEL, "amd-xgbe-%s", pdata->netdev->name);
> - if (!buf)
> + ret = snprintf(buf, sizeof(buf), "%s%s", XGBE_DIR_PREFIX,
> + pdata->netdev->name);
You can do:
snprintf(buf, sizeof buf, XGBE_DIR_PREFIX "%s", pdata->netdev->name)
> + if (ret >= sizeof(buf))
> return;
Unlike kasnprintf() where kmalloc() can fail, the simple snprintf()
can't really overrun unless pdata->netdev->name isn't '\0' terminated.
Even if it being changed while you look at it that shouldn't happen.
Don't you need to synchronise this anyway?
If the debugfs create and rename can happen at the same time then
the rename can be requested before the create and you get the wrong
name.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Powered by blists - more mailing lists