netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v1 1/2] net: pktgen: add strict buffer parsing index check
@ 2025-03-17  9:04 Peter Seiderer
  2025-03-17  9:04 ` [PATCH net-next v1 2/2] selftest: net: update proc_net_pktgen (add more imix_weights test cases) Peter Seiderer
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Peter Seiderer @ 2025-03-17  9:04 UTC (permalink / raw)
  To: netdev
  Cc: linux-kernel, linux-kselftest, Dan Carpenter, David S . Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
	Shuah Khan, Peter Seiderer

Add strict buffer parsing index check to avoid the following Smatch
warning:

  net/core/pktgen.c:877 get_imix_entries()
  warn: check that incremented offset 'i' is capped

Checking the buffer index i after every get_user/i++ step and returning
with error code immediately avoids the current indirect (but correct)
error handling.

Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/netdev/36cf3ee2-38b1-47e5-a42a-363efeb0ace3@stanley.mountain/
Signed-off-by: Peter Seiderer <ps.report@gmx.net>
---
 net/core/pktgen.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index e850598db3e7..fe7fdefab994 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -856,6 +856,9 @@ static ssize_t get_imix_entries(const char __user *buffer,
 		if (pkt_dev->n_imix_entries >= MAX_IMIX_ENTRIES)
 			return -E2BIG;
 
+		if (i >= maxlen)
+			return -EINVAL;
+
 		max = min(10, maxlen - i);
 		len = num_arg(&buffer[i], max, &size);
 		if (len < 0)
@@ -869,6 +872,8 @@ static ssize_t get_imix_entries(const char __user *buffer,
 		if (c != ',')
 			return -EINVAL;
 		i++;
+		if (i >= maxlen)
+			return -EINVAL;
 
 		if (size < 14 + 20 + 8)
 			size = 14 + 20 + 8;
@@ -911,6 +916,9 @@ static ssize_t get_labels(const char __user *buffer,
 		if (n >= MAX_MPLS_LABELS)
 			return -E2BIG;
 
+		if (i >= maxlen)
+			return -EINVAL;
+
 		max = min(8, maxlen - i);
 		len = hex32_arg(&buffer[i], max, &tmp);
 		if (len < 0)
-- 
2.48.1


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

end of thread, other threads:[~2025-03-24 19:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-17  9:04 [PATCH net-next v1 1/2] net: pktgen: add strict buffer parsing index check Peter Seiderer
2025-03-17  9:04 ` [PATCH net-next v1 2/2] selftest: net: update proc_net_pktgen (add more imix_weights test cases) Peter Seiderer
2025-03-20 11:48   ` Simon Horman
2025-03-20 11:47 ` [PATCH net-next v1 1/2] net: pktgen: add strict buffer parsing index check Simon Horman
2025-03-24 19:20 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).