Skip to content

Commit 7151062

Browse files
pseidererkuba-moo
authored andcommitted
net: pktgen: add strict buffer parsing index check
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 <[email protected]> Closes: https://lore.kernel.org/netdev/[email protected]/ Signed-off-by: Peter Seiderer <[email protected]> Reviewed-by: Simon Horman <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent fd88253 commit 7151062

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

net/core/pktgen.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,9 @@ static ssize_t get_imix_entries(const char __user *buffer,
856856
if (pkt_dev->n_imix_entries >= MAX_IMIX_ENTRIES)
857857
return -E2BIG;
858858

859+
if (i >= maxlen)
860+
return -EINVAL;
861+
859862
max = min(10, maxlen - i);
860863
len = num_arg(&buffer[i], max, &size);
861864
if (len < 0)
@@ -869,6 +872,8 @@ static ssize_t get_imix_entries(const char __user *buffer,
869872
if (c != ',')
870873
return -EINVAL;
871874
i++;
875+
if (i >= maxlen)
876+
return -EINVAL;
872877

873878
if (size < 14 + 20 + 8)
874879
size = 14 + 20 + 8;
@@ -911,6 +916,9 @@ static ssize_t get_labels(const char __user *buffer,
911916
if (n >= MAX_MPLS_LABELS)
912917
return -E2BIG;
913918

919+
if (i >= maxlen)
920+
return -EINVAL;
921+
914922
max = min(8, maxlen - i);
915923
len = hex32_arg(&buffer[i], max, &tmp);
916924
if (len < 0)

0 commit comments

Comments
 (0)