From: Peter Seiderer <ps.report@gmx.net>
To: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>, Shuah Khan <shuah@kernel.org>,
Nam Cao <namcao@linutronix.de>,
Thomas Gleixner <tglx@linutronix.de>,
Frederic Weisbecker <frederic@kernel.org>,
Artem Chernyshev <artem.chernyshev@red-soft.ru>,
Peter Seiderer <ps.report@gmx.net>
Subject: [PATCH net-next v3 06/10] net: pktgen: fix ctrl interface command parsing
Date: Mon, 3 Feb 2025 18:01:57 +0100 [thread overview]
Message-ID: <20250203170201.1661703-7-ps.report@gmx.net> (raw)
In-Reply-To: <20250203170201.1661703-1-ps.report@gmx.net>
Enable command writing without trailing '\n':
- the good case
$ echo "reset" > /proc/net/pktgen/pgctrl
- the bad case (before the patch)
$ echo -n "reset" > /proc/net/pktgen/pgctrl
-bash: echo: write error: Invalid argument
- with patch applied
$ echo -n "reset" > /proc/net/pktgen/pgctrl
Signed-off-by: Peter Seiderer <ps.report@gmx.net>
---
Changes v2 -> v3:
- new patch
---
net/core/pktgen.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index c8a5b4d17407..f6e35ba035c7 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -517,21 +517,23 @@ static ssize_t pgctrl_write(struct file *file, const char __user *buf,
size_t count, loff_t *ppos)
{
char data[128];
+ size_t max;
struct pktgen_net *pn = net_generic(current->nsproxy->net_ns, pg_net_id);
if (!capable(CAP_NET_ADMIN))
return -EPERM;
- if (count == 0)
+ if (count < 1)
return -EINVAL;
- if (count > sizeof(data))
- count = sizeof(data);
-
- if (copy_from_user(data, buf, count))
+ max = min(count, sizeof(data) - 1);
+ if (copy_from_user(data, buf, max))
return -EFAULT;
- data[count - 1] = 0; /* Strip trailing '\n' and terminate string */
+ if (data[max - 1] == '\n')
+ data[max - 1] = 0; /* strip trailing '\n', terminate string */
+ else
+ data[max] = 0; /* terminate string */
if (!strcmp(data, "stop"))
pktgen_stop_all_threads(pn);
--
2.48.1
next prev parent reply other threads:[~2025-02-03 17:02 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-03 17:01 [PATCH net-next v3 00/10] Some pktgen fixes/improvments Peter Seiderer
2025-02-03 17:01 ` [PATCH net-next v3 01/10] net: pktgen: replace ENOTSUPP with EOPNOTSUPP Peter Seiderer
2025-02-04 14:42 ` Simon Horman
2025-02-03 17:01 ` [PATCH net-next v3 02/10] net: pktgen: enable 'param=value' parsing Peter Seiderer
2025-02-04 10:55 ` Paolo Abeni
2025-02-05 13:06 ` Peter Seiderer
2025-02-03 17:01 ` [PATCH net-next v3 03/10] net: pktgen: fix hex32_arg parsing for short reads Peter Seiderer
2025-02-04 14:43 ` Simon Horman
2025-02-03 17:01 ` [PATCH net-next v3 04/10] net: pktgen: fix 'rate 0' error handling (return -EINVAL) Peter Seiderer
2025-02-04 14:44 ` Simon Horman
2025-02-03 17:01 ` [PATCH net-next v3 05/10] net: pktgen: fix 'ratep " Peter Seiderer
2025-02-04 14:44 ` Simon Horman
2025-02-03 17:01 ` Peter Seiderer [this message]
2025-02-04 14:44 ` [PATCH net-next v3 06/10] net: pktgen: fix ctrl interface command parsing Simon Horman
2025-02-03 17:01 ` [PATCH net-next v3 07/10] net: pktgen: fix access outside of user given buffer in pktgen_thread_write() Peter Seiderer
2025-02-04 14:45 ` Simon Horman
2025-02-03 17:01 ` [PATCH net-next v3 08/10] net: pktgen: fix access outside of user given buffer in pktgen_if_write() Peter Seiderer
2025-02-04 10:40 ` Paolo Abeni
2025-02-05 13:09 ` Peter Seiderer
2025-02-04 10:52 ` Simon Horman
2025-02-05 13:10 ` Peter Seiderer
2025-02-03 17:02 ` [PATCH net-next v3 09/10] net: pktgen: fix mpls reset parsing Peter Seiderer
2025-02-04 14:45 ` Simon Horman
2025-02-03 17:02 ` [PATCH net-next v3 10/10] selftest: net: add proc_net_pktgen Peter Seiderer
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=20250203170201.1661703-7-ps.report@gmx.net \
--to=ps.report@gmx.net \
--cc=artem.chernyshev@red-soft.ru \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=frederic@kernel.org \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=namcao@linutronix.de \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shuah@kernel.org \
--cc=tglx@linutronix.de \
/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