All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] pktgen: use dynamic allocation for debug print buffer
@ 2018-03-13 20:58 Arnd Bergmann
  2018-03-14  0:25 ` David Miller
  0 siblings, 1 reply; 4+ messages in thread
From: Arnd Bergmann @ 2018-03-13 20:58 UTC (permalink / raw)
  To: David S. Miller
  Cc: Gustavo A . R . Silva, Arnd Bergmann, Dmitry Safonov,
	Johannes Berg, Eric Dumazet, netdev, linux-kernel

After the removal of the VLA, we get a harmless warning about a large
stack frame:

net/core/pktgen.c: In function 'pktgen_if_write':
net/core/pktgen.c:1710:1: error: the frame size of 1076 bytes is larger than 1024 bytes [-Werror=frame-larger-than=]

The function was previously shown to be safe despite hitting
the 1024 bye warning level. To get rid of the annoyging warning,
while keeping it readable, this changes it to use strndup_user().

Obviously this is not a fast path, so the kmalloc() overhead
can be disregarded.

Fixes: 35951393bbff ("pktgen: Remove VLA usage")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 net/core/pktgen.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index de17a9f3e1f6..9216cf99b5a0 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -906,13 +906,14 @@ static ssize_t pktgen_if_write(struct file *file,
 	i += len;
 
 	if (debug) {
-		size_t copy = min_t(size_t, count, 1023);
-		char tb[1024];
-		if (copy_from_user(tb, user_buffer, copy))
-			return -EFAULT;
-		tb[copy] = 0;
-		pr_debug("%s,%lu  buffer -:%s:-\n",
-			 name, (unsigned long)count, tb);
+		size_t copy = min_t(size_t, count + 1, 1024);
+		char *tp = strndup_user(user_buffer, copy);
+
+		if (IS_ERR(tp))
+			return PTR_ERR(tp);
+
+		pr_debug("%s,%zu  buffer -:%s:-\n", name, count, tp);
+		kfree(buf);
 	}
 
 	if (!strcmp(name, "min_pkt_size")) {
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] pktgen: use dynamic allocation for debug print buffer
  2018-03-13 20:58 [PATCH] pktgen: use dynamic allocation for debug print buffer Arnd Bergmann
@ 2018-03-14  0:25 ` David Miller
  2018-03-14  3:02   ` Wang Jian
  0 siblings, 1 reply; 4+ messages in thread
From: David Miller @ 2018-03-14  0:25 UTC (permalink / raw)
  To: arnd; +Cc: gustavo, dima, johannes.berg, edumazet, netdev, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>
Date: Tue, 13 Mar 2018 21:58:39 +0100

> After the removal of the VLA, we get a harmless warning about a large
> stack frame:
> 
> net/core/pktgen.c: In function 'pktgen_if_write':
> net/core/pktgen.c:1710:1: error: the frame size of 1076 bytes is larger than 1024 bytes [-Werror=frame-larger-than=]
> 
> The function was previously shown to be safe despite hitting
> the 1024 bye warning level. To get rid of the annoyging warning,
> while keeping it readable, this changes it to use strndup_user().
> 
> Obviously this is not a fast path, so the kmalloc() overhead
> can be disregarded.
> 
> Fixes: 35951393bbff ("pktgen: Remove VLA usage")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Applied, thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] pktgen: use dynamic allocation for debug print buffer
  2018-03-14  0:25 ` David Miller
@ 2018-03-14  3:02   ` Wang Jian
  2018-03-14  8:16     ` Gustavo A. R. Silva
  0 siblings, 1 reply; 4+ messages in thread
From: Wang Jian @ 2018-03-14  3:02 UTC (permalink / raw)
  To: David Miller
  Cc: arnd, gustavo, dima, johannes.berg, edumazet, netdev, linux-kernel

>> +  kfree(buf);
free tb? buf is an array.

On Wed, Mar 14, 2018 at 8:25 AM, David Miller <davem@davemloft.net> wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> Date: Tue, 13 Mar 2018 21:58:39 +0100
>
>> After the removal of the VLA, we get a harmless warning about a large
>> stack frame:
>>
>> net/core/pktgen.c: In function 'pktgen_if_write':
>> net/core/pktgen.c:1710:1: error: the frame size of 1076 bytes is larger than 1024 bytes [-Werror=frame-larger-than=]
>>
>> The function was previously shown to be safe despite hitting
>> the 1024 bye warning level. To get rid of the annoyging warning,
>> while keeping it readable, this changes it to use strndup_user().
>>
>> Obviously this is not a fast path, so the kmalloc() overhead
>> can be disregarded.
>>
>> Fixes: 35951393bbff ("pktgen: Remove VLA usage")
>> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
>
> Applied, thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] pktgen: use dynamic allocation for debug print buffer
  2018-03-14  3:02   ` Wang Jian
@ 2018-03-14  8:16     ` Gustavo A. R. Silva
  0 siblings, 0 replies; 4+ messages in thread
From: Gustavo A. R. Silva @ 2018-03-14  8:16 UTC (permalink / raw)
  To: Wang Jian, David Miller
  Cc: arnd, dima, johannes.berg, edumazet, netdev, linux-kernel

Arnd:

Thanks for the fix.

On 03/13/2018 10:02 PM, Wang Jian wrote:
>>> +  kfree(buf);
> free tb? buf is an array.
> 

Wang:

Thanks for the report. I already sent a patch to fix this: 
https://patchwork.kernel.org/patch/10281587/

--
Gustavo

> On Wed, Mar 14, 2018 at 8:25 AM, David Miller <davem@davemloft.net> wrote:
>> From: Arnd Bergmann <arnd@arndb.de>
>> Date: Tue, 13 Mar 2018 21:58:39 +0100
>>
>>> After the removal of the VLA, we get a harmless warning about a large
>>> stack frame:
>>>
>>> net/core/pktgen.c: In function 'pktgen_if_write':
>>> net/core/pktgen.c:1710:1: error: the frame size of 1076 bytes is larger than 1024 bytes [-Werror=frame-larger-than=]
>>>
>>> The function was previously shown to be safe despite hitting
>>> the 1024 bye warning level. To get rid of the annoyging warning,
>>> while keeping it readable, this changes it to use strndup_user().
>>>
>>> Obviously this is not a fast path, so the kmalloc() overhead
>>> can be disregarded.
>>>
>>> Fixes: 35951393bbff ("pktgen: Remove VLA usage")
>>> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
>>
>> Applied, thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-03-14  8:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-13 20:58 [PATCH] pktgen: use dynamic allocation for debug print buffer Arnd Bergmann
2018-03-14  0:25 ` David Miller
2018-03-14  3:02   ` Wang Jian
2018-03-14  8:16     ` Gustavo A. R. Silva

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.