diff mbox series

[net-next,v1,1/2] net: pktgen: add strict buffer parsing index check

Message ID 20250317090401.1240704-1-ps.report@gmx.net (mailing list archive)
State New
Delegated to: Netdev Maintainers
Headers show
Series [net-next,v1,1/2] net: pktgen: add strict buffer parsing index check | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 26 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Peter Seiderer March 17, 2025, 9:04 a.m. UTC
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 mbox series

Patch

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)