Some pktgen fixes/improvments
Subsystems (3)
v3 cover Some pktgen fixes/improvments
While taking a look at '[PATCH net] pktgen: Avoid out-of-range in get_imix_entries' ([1]) and '[PATCH net v2] pktgen: Avoid out-of-bounds access in get_imix_entries' ([2], [3]) and doing some tests and code review I detected that the /proc/net/pktgen/... parsing logic does not honour the user given buffer bounds (resulting in out-of-bounds access).
This can be observed e.g. by the following simple test (sometimes the old/'longer' previous value is re-read from the buffer):
$ echo add_device lo@0 > /proc/net/pktgen/kpktgend_0
$ echo "min_pkt_size 12345" > /proc/net/pktgen/lo\@0 && grep min_pkt_size /proc/net/pktgen/lo\@0 Params: count 1000 min_pkt_size: 12345 max_pkt_size: 0 Result: OK: min_pkt_size=12345
$ echo -n "min_pkt_size 123" > /proc/net/pktgen/lo\@0 && grep min_pkt_size /proc/net/pktgen/lo\@0 Params: count 1000 min_pkt_size: 12345 max_pkt_size: 0 Result: OK: min_pkt_size=12345
$ echo "min_pkt_size 123" > /proc/net/pktgen/lo\@0 && grep min_pkt_size /proc/net/pktgen/lo\@0 Params: count 1000 min_pkt_size: 123 max_pkt_size: 0 Result: OK: min_pkt_size=123
So fix the out-of-bounds access (and some minor findings) and add a simple proc_net_pktgen selftest...
Regards,
Peter
Changes v2 -> v3:
- new patch: 'net: pktgen: fix ctrl interface command parsing'
- new patch: 'net: pktgen: fix mpls reset parsing'
- tools/testing/selftests/net/proc_net_pktgen.c:
- fix typo in change description ('v1 -> v1' and tyop)
- rename some vars to better match usage
add_loopback_0 -> thr_cmd_add_loopback_0
rm_loopback_0 -> thr_cmd_rm_loopback_0
wrong_ctrl_cmd -> wrong_thr_cmd
legacy_ctrl_cmd -> legacy_thr_cmd
ctrl_fd -> thr_fd- add ctrl interface tests
Changes v1 -> v2:
- new patch: 'net: pktgen: fix hex32_arg parsing for short reads'
- new patch: 'net: pktgen: fix 'rate 0' error handling (return -EINVAL)'
- new patch: 'net: pktgen: fix 'ratep 0' error handling (return -EINVAL)'
- net/core/pktgen.c: additional fix get_imix_entries() and get_labels()
- tools/testing/selftests/net/proc_net_pktgen.c:
- fix tyop not vs. nod (suggested by Jakub Kicinski)
- fix misaligned line (suggested by Jakub Kicinski)
- enable fomerly commented out CONFIG_XFRM dependent test (command spi), as CONFIG_XFRM is enabled via tools/testing/selftests/net/config CONFIG_XFRM_INTERFACE/CONFIG_XFRM_USER (suggestex by Jakub Kicinski)
- add CONFIG_NET_PKTGEN=m to tools/testing/selftests/net/config (suggested by Jakub Kicinski)
- add modprobe pktgen to FIXTURE_SETUP() (suggested by Jakub Kicinski)
- fix some checkpatch warnings (Missing a blank line after declarations)
- shrink line length by re-naming some variables (command -> cmd,
device -> dev)
- add 'rate 0' testcase
- add 'ratep 0' testcase
[1] https://lore.kernel.org/netdev/[email protected]/
[2] https://lore.kernel.org/netdev/[email protected]/
[3] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=76201b5979768500bca362871db66d77cb4c225e
Peter Seiderer (10):
net: pktgen: replace ENOTSUPP with EOPNOTSUPP
net: pktgen: enable 'param=value' parsing
net: pktgen: fix hex32_arg parsing for short reads
net: pktgen: fix 'rate 0' error handling (return -EINVAL)
net: pktgen: fix 'ratep 0' error handling (return -EINVAL)
net: pktgen: fix ctrl interface command parsing
net: pktgen: fix access outside of user given buffer in
pktgen_thread_write()
net: pktgen: fix access outside of user given buffer in
pktgen_if_write()
net: pktgen: fix mpls reset parsing
selftest: net: add proc_net_pktgen
net/core/pktgen.c | 257 ++++--- tools/testing/selftests/net/Makefile | 1 + tools/testing/selftests/net/config | 1 + tools/testing/selftests/net/proc_net_pktgen.c | 650 ++++++++++++++++++ 4 files changed, 819 insertions(+), 90 deletions(-) create mode 100644 tools/testing/selftests/net/proc_net_pktgen.c
Signature · 1 line
2.48.1
PATCH v3 1/10 net: pktgen: replace ENOTSUPP with EOPNOTSUPP
Replace ENOTSUPP with EOPNOTSUPP, fixes checkpatch hint
WARNING: ENOTSUPP is not a SUSV4 error code, prefer EOPNOTSUPP
and e.g.
$ echo "clone_skb 1" > /proc/net/pktgen/lo\@0 -bash: echo: write error: Unknown error 524
---
Changes v2 -> v3
- no changes
Changes v1 -> v2
- no changes
--- net/core/pktgen.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/core/pktgen.c +3 -3
@@ -1198,7 +1198,7 @@ static ssize_t pktgen_if_write(struct file *file,if ((value >0 ) && ((pkt_dev->xmit_mode ==M_NETIF_RECEIVE ) || !(pkt_dev->odev->priv_flags &IFF_TX_SKB_SHARING ))) -return -ENOTSUPP ; +return -EOPNOTSUPP ;if (value >0 && (pkt_dev->n_imix_entries >0 || !(pkt_dev->flags &F_SHARED )))return -EINVAL ;
@@ -1258,7 +1258,7 @@ static ssize_t pktgen_if_write(struct file *file, ((pkt_dev->xmit_mode ==M_QUEUE_XMIT ) || ((pkt_dev->xmit_mode ==M_START_XMIT ) && (!(pkt_dev->odev->priv_flags & IFF_TX_SKB_SHARING))))) - return -ENOTSUPP; + return -EOPNOTSUPP;if (value >1 && !(pkt_dev->flags &F_SHARED ))return -EINVAL ;
@@ -1303,7 +1303,7 @@ static ssize_t pktgen_if_write(struct file *file, }else if (strcmp (f,"netif_receive" ) ==0 ) {/* clone_skb set earlier, not supported in this mode */ if (pkt_dev->clone_skb >0 ) -return -ENOTSUPP ; +return -EOPNOTSUPP ; pkt_dev->xmit_mode =M_NETIF_RECEIVE ;
Signature · 1 line
2.48.1
Re: [PATCH net-next v3 01/10] net: pktgen: replace ENOTSUPP with EOPNOTSUPP
Quoted 10 lines · Peter Seiderer
Replace ENOTSUPP with EOPNOTSUPP, fixes checkpatch hint
WARNING: ENOTSUPP is not a SUSV4 error code, prefer EOPNOTSUPP
and e.g.
$ echo "clone_skb 1" > /proc/net/pktgen/lo\@0 -bash: echo: write error: Unknown error 524Signed-off-by Peter Seiderer <[email protected]>
PATCH v3 2/10 net: pktgen: enable 'param=value' parsing
In reply to Peter SeidererEnable additional to 'parm value' the 'param=value' parsing (otherwise skipping '=' in count_trail_chars() is useless).
Tested with:
$ echo "min_pkt_size 999" > /proc/net/pktgen/lo\@0 $ echo "min_pkt_size=999" > /proc/net/pktgen/lo\@0 $ echo "min_pkt_size =999" > /proc/net/pktgen/lo\@0 $ echo "min_pkt_size= 999" > /proc/net/pktgen/lo\@0 $ echo "min_pkt_size = 999" > /proc/net/pktgen/lo\@0
---
Changes v2 -> v3:
- no changes
Changes v1 -> v2:
- no changes
--- net/core/pktgen.c | 1 + 1 file changed, 1 insertion(+)
net/core/pktgen.c +1 -0
@@ -823,6 +823,7 @@ static int strn_len(const char __user * user_buffer, unsigned int maxlen)case '\r' :case '\t' :case ' ' : +case '=' : goto done_str;default :break ;
Signature · 1 line
2.48.1
Paolo Abeni
maintainerRe: [PATCH net-next v3 02/10] net: pktgen: enable 'param=value' parsing
Quoted 1 line · Peter Seiderer
Enable additional to 'parm value' the 'param=value' parsing
It could be language bias on my side, by I find the above statement hard to parse. Could you please rephrase it?
IMHO something alike:
"""
Enable more flexible parameters syntax, allowing "param=value" in addition to the already supported "param value" pattern. """
Thanks,
Paolo
Re: [PATCH net-next v3 02/10] net: pktgen: enable 'param=value' parsing
Hello Paolo,
Quoted 6 lines · Paolo Abeni
Quoted 1 line · Peter Seiderer
Enable additional to 'parm value' the 'param=value' parsing
It could be language bias on my side, by I find the above statement hard to parse. Could you please rephrase it?
Quoted 6 lines
IMHO something alike:
"""
Enable more flexible parameters syntax, allowing "param=value" in addition to the already supported "param value" pattern. """
You are right, thanks for review and improved commit description, will fix it in the next patch iteration...
Regards,
Peter
Quoted 5 lines
Thanks,
Paolo
PATCH v3 3/10 net: pktgen: fix hex32_arg parsing for short reads
In reply to Peter SeidererFix hex32_arg parsing for short reads (here 7 hex digits instead of the expected 8), shift result only on successful input parsing.
- before the patch
$ echo "mpls 0000123" > /proc/net/pktgen/lo\@0 $ grep mpls /proc/net/pktgen/lo\@0 mpls: 00001230 Result: OK: mpls=00001230
- with patch applied
$ echo "mpls 0000123" > /proc/net/pktgen/lo\@0 $ grep mpls /proc/net/pktgen/lo\@0 mpls: 00000123 Result: OK: mpls=00000123
---
Changes v1 -> v2:
- no changes
Changes v1 -> v2:
- new patch
--- net/core/pktgen.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
net/core/pktgen.c +4 -3
@@ -753,14 +753,15 @@ static int hex32_arg(const char __user *user_buffer, unsigned long maxlen,for (; i < maxlen; i++) {int value;char c; - *num <<=4 ;if (get_user (c, &user_buffer[i]))return -EFAULT ; value =hex_to_bin (c); -if (value >=0 ) +if (value >=0 ) { + *num <<=4 ; *num |= value; -else + }else {break ; + } }return i; }
Signature · 1 line
2.48.1
Re: [PATCH net-next v3 03/10] net: pktgen: fix hex32_arg parsing for short reads
Quoted 10 lines · Peter Seiderer
Fix
hex32_argparsing for short reads (here 7 hex digits instead of the expected 8), shift result only on successful input parsing.- before the patch
$ echo "mpls 0000123" > /proc/net/pktgen/lo\@0 $ grep mpls /proc/net/pktgen/lo\@0 mpls: 00001230 Result: OK: mpls=00001230
Quoted 8 lines
- with patch applied
$ echo "mpls 0000123" > /proc/net/pktgen/lo\@0 $ grep mpls /proc/net/pktgen/lo\@0 mpls: 00000123 Result: OK: mpls=00000123Signed-off-by Peter Seiderer <[email protected]>
PATCH v3 4/10 net: pktgen: fix 'rate 0' error handling (return -EINVAL)
In reply to Peter SeidererGiven an invalid 'rate' command e.g. 'rate 0' the return value is '1', leading to the following misleading output:
- the good case
$ echo "rate 100" > /proc/net/pktgen/lo\@0 $ grep "Result:" /proc/net/pktgen/lo\@0 Result: OK: rate=100
- the bad case (before the patch)
$ echo "rate 0" > /proc/net/pktgen/lo\@0" -bash: echo: write error: Invalid argument $ grep "Result:" /proc/net/pktgen/lo\@0 Result: No such parameter "ate"
- with patch applied
$ echo "rate 0" > /proc/net/pktgen/lo\@0 -bash: echo: write error: Invalid argument $ grep "Result:" /proc/net/pktgen/lo\@0 Result: Idle
---
Changes v2 -> v3:
- no changes
Changes v1 -> v2:
- new patch
--- net/core/pktgen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/pktgen.c +1 -1
@@ -1115,7 +1115,7 @@ static ssize_t pktgen_if_write(struct file *file, i += len;if (!value) -return len; +return -EINVAL ; pkt_dev->delay = pkt_dev->min_pkt_size*8 *NSEC_PER_USEC /value;if (debug)pr_info ("Delay set at: %llu ns\n" , pkt_dev->delay);
Signature · 1 line
2.48.1
Re: [PATCH net-next v3 04/10] net: pktgen: fix 'rate 0' error handling (return -EINVAL)
Quoted 16 lines · Peter Seiderer
Given an invalid 'rate' command e.g. 'rate 0' the return value is '1', leading to the following misleading output:
- the good case
$ echo "rate 100" > /proc/net/pktgen/lo\@0 $ grep "Result:" /proc/net/pktgen/lo\@0 Result: OK: rate=100- the bad case (before the patch)
$ echo "rate 0" > /proc/net/pktgen/lo\@0" -bash: echo: write error: Invalid argument $ grep "Result:" /proc/net/pktgen/lo\@0 Result: No such parameter "ate"
Quoted 8 lines
- with patch applied
$ echo "rate 0" > /proc/net/pktgen/lo\@0 -bash: echo: write error: Invalid argument $ grep "Result:" /proc/net/pktgen/lo\@0 Result: IdleSigned-off-by Peter Seiderer <[email protected]>
PATCH v3 5/10 net: pktgen: fix 'ratep 0' error handling (return -EINVAL)
In reply to Peter SeidererGiven an invalid 'ratep' command e.g. 'ratep 0' the return value is '1', leading to the following misleading output:
- the good case
$ echo "ratep 100" > /proc/net/pktgen/lo\@0 $ grep "Result:" /proc/net/pktgen/lo\@0 Result: OK: ratep=100
- the bad case (before the patch)
$ echo "ratep 0" > /proc/net/pktgen/lo\@0" -bash: echo: write error: Invalid argument $ grep "Result:" /proc/net/pktgen/lo\@0 Result: No such parameter "atep"
- with patch applied
$ echo "ratep 0" > /proc/net/pktgen/lo\@0 -bash: echo: write error: Invalid argument $ grep "Result:" /proc/net/pktgen/lo\@0 Result: Idle
---
Changes v2 -> v3:
- no changes
Changes v1 -> v2:
- new patch
--- net/core/pktgen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/pktgen.c +1 -1
@@ -1130,7 +1130,7 @@ static ssize_t pktgen_if_write(struct file *file, i += len;if (!value) -return len; +return -EINVAL ; pkt_dev->delay =NSEC_PER_SEC /value;if (debug)pr_info ("Delay set at: %llu ns\n" , pkt_dev->delay);
Signature · 1 line
2.48.1
Re: [PATCH net-next v3 05/10] net: pktgen: fix 'ratep 0' error handling (return -EINVAL)
Quoted 16 lines · Peter Seiderer
Given an invalid 'ratep' command e.g. 'ratep 0' the return value is '1', leading to the following misleading output:
- the good case
$ echo "ratep 100" > /proc/net/pktgen/lo\@0 $ grep "Result:" /proc/net/pktgen/lo\@0 Result: OK: ratep=100- the bad case (before the patch)
$ echo "ratep 0" > /proc/net/pktgen/lo\@0" -bash: echo: write error: Invalid argument $ grep "Result:" /proc/net/pktgen/lo\@0 Result: No such parameter "atep"
Quoted 8 lines
- with patch applied
$ echo "ratep 0" > /proc/net/pktgen/lo\@0 -bash: echo: write error: Invalid argument $ grep "Result:" /proc/net/pktgen/lo\@0 Result: IdleSigned-off-by Peter Seiderer <[email protected]>
PATCH v3 6/10 net: pktgen: fix ctrl interface command parsing
In reply to Peter SeidererEnable 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
---
Changes v2 -> v3:
- new patch
--- net/core/pktgen.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
net/core/pktgen.c +8 -6
@@ -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);
Signature · 1 line
2.48.1
Re: [PATCH net-next v3 06/10] net: pktgen: fix ctrl interface command parsing
Quoted 8 lines · Peter Seiderer
Enable command writing without trailing '\n':
- the good case
$ echo "reset" > /proc/net/pktgen/pgctrl- the bad case (before the patch)
Quoted 8 lines
$ echo -n "reset" > /proc/net/pktgen/pgctrl -bash: echo: write error: Invalid argument- with patch applied
$ echo -n "reset" > /proc/net/pktgen/pgctrlSigned-off-by Peter Seiderer <[email protected]>
PATCH v3 7/10 net: pktgen: fix access outside of user given buffer in pktgen_thread_write()
In reply to Peter SeidererHonour the user given buffer size for the strn_len() calls (otherwise strn_len() will access memory outside of the user given buffer).
---
Changes v2 -> v3:
- no changes
Changes v1 -> v2:
- no changes
--- net/core/pktgen.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
net/core/pktgen.c +4 -3
@@ -1900,8 +1900,8 @@ static ssize_t pktgen_thread_write(struct file *file, i = len;/* Read variable name */ - - len =strn_len (&user_buffer[i],sizeof (name) -1 ); + max =min (sizeof (name) -1 , count - i); + len =strn_len (&user_buffer[i], max);if (len <0 )return len;
@@ -1931,7 +1931,8 @@ static ssize_t pktgen_thread_write(struct file *file,if (!strcmp (name,"add_device" )) {char f[32 ];memset (f,0 ,32 ); - len =strn_len (&user_buffer[i],sizeof (f) -1 ); + max =min (sizeof (f) -1 , count - i); + len =strn_len (&user_buffer[i], max);if (len <0 ) { ret = len; goto out;
Signature · 1 line
2.48.1
Re: [PATCH net-next v3 07/10] net: pktgen: fix access outside of user given buffer in pktgen_thread_write()
Quoted 4 lines · Peter Seiderer
Honour the user given buffer size for the
strn_len()calls (otherwisestrn_len()will access memory outside of the user given buffer).Signed-off-by Peter Seiderer <[email protected]>
PATCH v3 8/10 net: pktgen: fix access outside of user given buffer in pktgen_if_write()
In reply to Peter SeidererHonour the user given buffer size for the hex32_arg(), num_arg(), strn_len(), get_imix_entries() and get_labels() calls (otherwise they will access memory outside of the user given buffer).
In hex32_arg(), num_arg(), strn_len() error out in case no characters are available (maxlen = 0), in num_arg() additional error out in case no valid character is parsed.
In get_labels() additional enable parsing labels up to MAX_IMIX_ENTRIES instead of (MAX_IMIX_ENTRIES - 1).
Additional remove some superfluous variable initializing and align some variable declarations to the most common pattern.
---
Changes v2 -> v3:
- no changes
Changes v1 -> v2:
- additional fix get_imix_entries() and get_labels()
--- net/core/pktgen.c | 211 ++++++++++++++++++++++++++++++---------------- 1 file changed, 139 insertions(+), 72 deletions(-)
net/core/pktgen.c +139 -72
@@ -752,6 +752,9 @@ static int hex32_arg(const char __user *user_buffer, unsigned long maxlen,int i =0 ; *num =0 ; +if (!maxlen) +return -EINVAL ; +for (; i < maxlen; i++) {int value;char c;
@@ -799,6 +802,9 @@ static long num_arg(const char __user *user_buffer, unsigned long maxlen,int i; *num =0 ; +if (!maxlen) +return -EINVAL ; +for (i =0 ; i < maxlen; i++) {char c;if (get_user (c, &user_buffer[i]))
@@ -806,6 +812,9 @@ static long num_arg(const char __user *user_buffer, unsigned long maxlen,if ((c >='0' ) && (c <='9' )) { *num *=10 ; *num += c -'0' ; + }else if (i ==0 ) { +// no valid character parsed, error out +return -EINVAL ; }else break ; }
@@ -816,6 +825,9 @@ static int strn_len(const char __user * user_buffer, unsigned int maxlen) {int i; +if (!maxlen) +return -EINVAL ; +for (i =0 ; i < maxlen; i++) {char c;if (get_user (c, &user_buffer[i]))
@@ -842,11 +854,10 @@ static int strn_len(const char __user * user_buffer, unsigned int maxlen)* "size1,weight_1 size2,weight_2 ... size_n,weight_n" for example. */ static ssize_t get_imix_entries (const char __user *buffer, +unsigned int maxlen,struct pktgen_dev *pkt_dev) { -const int max_digits =10 ; -int i =0 ; -long len; +int i =0 , max, len;char c; pkt_dev->n_imix_entries =0 ;
@@ -858,10 +869,13 @@ static ssize_t get_imix_entries(const char __user *buffer,if (pkt_dev->n_imix_entries >=MAX_IMIX_ENTRIES )return -E2BIG ; - len =num_arg (&buffer[i], max_digits, &size); + max =min (10 , maxlen - i); + len =num_arg (&buffer[i], max, &size);if (len <0 )return len; i += len; +if (i >= maxlen) +return -EINVAL ;if (get_user (c, &buffer[i]))return -EFAULT ;/* Check for comma between size_i and weight_i */
@@ -872,7 +886,8 @@ static ssize_t get_imix_entries(const char __user *buffer,if (size <14 +20 +8 ) size =14 +20 +8 ; - len =num_arg (&buffer[i], max_digits, &weight); + max =min (10 , maxlen - i); + len =num_arg (&buffer[i], max, &weight);if (len <0 )return len;if (weight <=0 )
@@ -882,39 +897,45 @@ static ssize_t get_imix_entries(const char __user *buffer, pkt_dev->imix_entries[pkt_dev->n_imix_entries].weight = weight; i += len; + pkt_dev->n_imix_entries++; + +if (i >= maxlen) +break ;if (get_user (c, &buffer[i]))return -EFAULT ; - i++; - pkt_dev->n_imix_entries++; }while (c ==' ' );return i; } -static ssize_t get_labels (const char __user *buffer,struct pktgen_dev *pkt_dev) +static ssize_t get_labels (const char __user *buffer,int maxlen,struct pktgen_dev *pkt_dev) {unsigned int n =0 ;char c; -ssize_t i =0 ; -int len; +int i =0 , max, len; pkt_dev->nr_labels =0 ;do {__u32 tmp; - len =hex32_arg (&buffer[i],8 , &tmp); + +if (n >=MAX_MPLS_LABELS ) +return -E2BIG ; + + max =min (8 , maxlen - i); + len =hex32_arg (&buffer[i], max, &tmp);if (len <=0 )return len; pkt_dev->labels[n] =htonl (tmp);if (pkt_dev->labels[n] &MPLS_STACK_BOTTOM ) pkt_dev->flags |=F_MPLS_RND ; i += len; + n++; +if (i >= maxlen) +break ;if (get_user (c, &buffer[i]))return -EFAULT ; i++; - n++; -if (n >=MAX_MPLS_LABELS ) -return -E2BIG ; }while (c ==',' ); pkt_dev->nr_labels = n;
@@ -960,7 +981,6 @@ static ssize_t pktgen_if_write(struct file *file,char name[16 ], valstr[32 ];unsigned long value =0 ;char *pg_result =NULL ; -int tmp =0 ;char buf[128 ]; pg_result = &(pkt_dev->result[0 ]);
@@ -970,17 +990,16 @@ static ssize_t pktgen_if_write(struct file *file,return -EINVAL ; } - max = count; - tmp =count_trail_chars (user_buffer, max); -if (tmp <0 ) { + len =count_trail_chars (user_buffer, count); +if (len <0 ) {pr_warn ("illegal format\n" ); -return tmp; +return len; } - i = tmp; + i = len;/* Read variable name */ - - len =strn_len (&user_buffer[i],sizeof (name) -1 ); + max =min (sizeof (name) -1 , count - i); + len =strn_len (&user_buffer[i], max);if (len <0 )return len;
@@ -1008,7 +1027,8 @@ static ssize_t pktgen_if_write(struct file *file, }if (!strcmp (name,"min_pkt_size" )) { - len =num_arg (&user_buffer[i],10 , &value); + max =min (10 , count - i); + len =num_arg (&user_buffer[i], max, &value);if (len <0 )return len;
@@ -1025,7 +1045,8 @@ static ssize_t pktgen_if_write(struct file *file, }if (!strcmp (name,"max_pkt_size" )) { - len =num_arg (&user_buffer[i],10 , &value); + max =min (10 , count - i); + len =num_arg (&user_buffer[i], max, &value);if (len <0 )return len;
@@ -1044,7 +1065,8 @@ static ssize_t pktgen_if_write(struct file *file,/* Shortcut for min = max */ if (!strcmp (name,"pkt_size" )) { - len =num_arg (&user_buffer[i],10 , &value); + max =min (10 , count - i); + len =num_arg (&user_buffer[i], max, &value);if (len <0 )return len;
@@ -1064,7 +1086,8 @@ static ssize_t pktgen_if_write(struct file *file,if (pkt_dev->clone_skb >0 )return -EINVAL ; - len =get_imix_entries (&user_buffer[i], pkt_dev); + max = count - i; + len =get_imix_entries (&user_buffer[i], max, pkt_dev);if (len <0 )return len;
@@ -1075,7 +1098,8 @@ static ssize_t pktgen_if_write(struct file *file, }if (!strcmp (name,"debug" )) { - len =num_arg (&user_buffer[i],10 , &value); + max =min (10 , count - i); + len =num_arg (&user_buffer[i], max, &value);if (len <0 )return len;
@@ -1086,7 +1110,8 @@ static ssize_t pktgen_if_write(struct file *file, }if (!strcmp (name,"frags" )) { - len =num_arg (&user_buffer[i],10 , &value); + max =min (10 , count - i); + len =num_arg (&user_buffer[i], max, &value);if (len <0 )return len;
@@ -1096,7 +1121,8 @@ static ssize_t pktgen_if_write(struct file *file,return count; }if (!strcmp (name,"delay" )) { - len =num_arg (&user_buffer[i],10 , &value); + max =min (10 , count - i); + len =num_arg (&user_buffer[i], max, &value);if (len <0 )return len;
@@ -1111,7 +1137,8 @@ static ssize_t pktgen_if_write(struct file *file,return count; }if (!strcmp (name,"rate" )) { - len =num_arg (&user_buffer[i],10 , &value); + max =min (10 , count - i); + len =num_arg (&user_buffer[i], max, &value);if (len <0 )return len;
@@ -1126,7 +1153,8 @@ static ssize_t pktgen_if_write(struct file *file,return count; }if (!strcmp (name,"ratep" )) { - len =num_arg (&user_buffer[i],10 , &value); + max =min (10 , count - i); + len =num_arg (&user_buffer[i], max, &value);if (len <0 )return len;
@@ -1141,7 +1169,8 @@ static ssize_t pktgen_if_write(struct file *file,return count; }if (!strcmp (name,"udp_src_min" )) { - len =num_arg (&user_buffer[i],10 , &value); + max =min (10 , count - i); + len =num_arg (&user_buffer[i], max, &value);if (len <0 )return len;
@@ -1154,7 +1183,8 @@ static ssize_t pktgen_if_write(struct file *file,return count; }if (!strcmp (name,"udp_dst_min" )) { - len =num_arg (&user_buffer[i],10 , &value); + max =min (10 , count - i); + len =num_arg (&user_buffer[i], max, &value);if (len <0 )return len;
@@ -1167,7 +1197,8 @@ static ssize_t pktgen_if_write(struct file *file,return count; }if (!strcmp (name,"udp_src_max" )) { - len =num_arg (&user_buffer[i],10 , &value); + max =min (10 , count - i); + len =num_arg (&user_buffer[i], max, &value);if (len <0 )return len;
@@ -1180,7 +1211,8 @@ static ssize_t pktgen_if_write(struct file *file,return count; }if (!strcmp (name,"udp_dst_max" )) { - len =num_arg (&user_buffer[i],10 , &value); + max =min (10 , count - i); + len =num_arg (&user_buffer[i], max, &value);if (len <0 )return len;
@@ -1193,7 +1225,8 @@ static ssize_t pktgen_if_write(struct file *file,return count; }if (!strcmp (name,"clone_skb" )) { - len =num_arg (&user_buffer[i],10 , &value); + max =min (10 , count - i); + len =num_arg (&user_buffer[i], max, &value);if (len <0 )return len;/* clone_skb is not supported for netif_receive xmit_mode and
@@ -1214,7 +1247,8 @@ static ssize_t pktgen_if_write(struct file *file,return count; }if (!strcmp (name,"count" )) { - len =num_arg (&user_buffer[i],10 , &value); + max =min (10 , count - i); + len =num_arg (&user_buffer[i], max, &value);if (len <0 )return len;
@@ -1225,7 +1259,8 @@ static ssize_t pktgen_if_write(struct file *file,return count; }if (!strcmp (name,"src_mac_count" )) { - len =num_arg (&user_buffer[i],10 , &value); + max =min (10 , count - i); + len =num_arg (&user_buffer[i], max, &value);if (len <0 )return len;
@@ -1239,7 +1274,8 @@ static ssize_t pktgen_if_write(struct file *file,return count; }if (!strcmp (name,"dst_mac_count" )) { - len =num_arg (&user_buffer[i],10 , &value); + max =min (10 , count - i); + len =num_arg (&user_buffer[i], max, &value);if (len <0 )return len;
@@ -1253,7 +1289,8 @@ static ssize_t pktgen_if_write(struct file *file,return count; }if (!strcmp (name,"burst" )) { - len =num_arg (&user_buffer[i],10 , &value); + max =min (10 , count - i); + len =num_arg (&user_buffer[i], max, &value);if (len <0 )return len;
@@ -1272,7 +1309,8 @@ static ssize_t pktgen_if_write(struct file *file,return count; }if (!strcmp (name,"node" )) { - len =num_arg (&user_buffer[i],10 , &value); + max =min (10 , count - i); + len =num_arg (&user_buffer[i], max, &value);if (len <0 )return len;
@@ -1293,11 +1331,12 @@ static ssize_t pktgen_if_write(struct file *file,if (!strcmp (name,"xmit_mode" )) {char f[32 ]; -memset (f,0 ,32 ); - len =strn_len (&user_buffer[i],sizeof (f) -1 ); + max =min (sizeof (f) -1 , count - i); + len =strn_len (&user_buffer[i], max);if (len <0 )return len; +memset (f,0 ,sizeof (f));if (copy_from_user (f, &user_buffer[i], len))return -EFAULT ; i += len;
@@ -1333,11 +1372,12 @@ static ssize_t pktgen_if_write(struct file *file,char f[32 ];char *end; -memset (f,0 ,32 ); - len =strn_len (&user_buffer[i],sizeof (f) -1 ); + max =min (sizeof (f) -1 , count - i); + len =strn_len (&user_buffer[i], max);if (len <0 )return len; +memset (f,0 ,32 );if (copy_from_user (f, &user_buffer[i], len))return -EFAULT ; i += len;
@@ -1382,7 +1422,8 @@ static ssize_t pktgen_if_write(struct file *file,return count; }if (!strcmp (name,"dst_min" ) || !strcmp (name,"dst" )) { - len =strn_len (&user_buffer[i],sizeof (pkt_dev->dst_min) -1 ); + max =min (sizeof (pkt_dev->dst_min) -1 , count - i); + len =strn_len (&user_buffer[i], max);if (len <0 )return len;
@@ -1402,7 +1443,8 @@ static ssize_t pktgen_if_write(struct file *file,return count; }if (!strcmp (name,"dst_max" )) { - len =strn_len (&user_buffer[i],sizeof (pkt_dev->dst_max) -1 ); + max =min (sizeof (pkt_dev->dst_max) -1 , count - i); + len =strn_len (&user_buffer[i], max);if (len <0 )return len;
@@ -1422,7 +1464,8 @@ static ssize_t pktgen_if_write(struct file *file,return count; }if (!strcmp (name,"dst6" )) { - len =strn_len (&user_buffer[i],sizeof (buf) -1 ); + max =min (sizeof (buf) -1 , count - i); + len =strn_len (&user_buffer[i], max);if (len <0 )return len;
@@ -1445,7 +1488,8 @@ static ssize_t pktgen_if_write(struct file *file,return count; }if (!strcmp (name,"dst6_min" )) { - len =strn_len (&user_buffer[i],sizeof (buf) -1 ); + max =min (sizeof (buf) -1 , count - i); + len =strn_len (&user_buffer[i], max);if (len <0 )return len;
@@ -1467,7 +1511,8 @@ static ssize_t pktgen_if_write(struct file *file,return count; }if (!strcmp (name,"dst6_max" )) { - len =strn_len (&user_buffer[i],sizeof (buf) -1 ); + max =min (sizeof (buf) -1 , count - i); + len =strn_len (&user_buffer[i], max);if (len <0 )return len;
@@ -1488,7 +1533,8 @@ static ssize_t pktgen_if_write(struct file *file,return count; }if (!strcmp (name,"src6" )) { - len =strn_len (&user_buffer[i],sizeof (buf) -1 ); + max =min (sizeof (buf) -1 , count - i); + len =strn_len (&user_buffer[i], max);if (len <0 )return len;
@@ -1511,7 +1557,8 @@ static ssize_t pktgen_if_write(struct file *file,return count; }if (!strcmp (name,"src_min" )) { - len =strn_len (&user_buffer[i],sizeof (pkt_dev->src_min) -1 ); + max =min (sizeof (pkt_dev->src_min) -1 , count - i); + len =strn_len (&user_buffer[i], max);if (len <0 )return len;
@@ -1531,7 +1578,8 @@ static ssize_t pktgen_if_write(struct file *file,return count; }if (!strcmp (name,"src_max" )) { - len =strn_len (&user_buffer[i],sizeof (pkt_dev->src_max) -1 ); + max =min (sizeof (pkt_dev->src_max) -1 , count - i); + len =strn_len (&user_buffer[i], max);if (len <0 )return len;
@@ -1551,7 +1599,8 @@ static ssize_t pktgen_if_write(struct file *file,return count; }if (!strcmp (name,"dst_mac" )) { - len =strn_len (&user_buffer[i],sizeof (valstr) -1 ); + max =min (sizeof (valstr) -1 , count - i); + len =strn_len (&user_buffer[i], max);if (len <0 )return len;
@@ -1568,7 +1617,8 @@ static ssize_t pktgen_if_write(struct file *file,return count; }if (!strcmp (name,"src_mac" )) { - len =strn_len (&user_buffer[i],sizeof (valstr) -1 ); + max =min (sizeof (valstr) -1 , count - i); + len =strn_len (&user_buffer[i], max);if (len <0 )return len;
@@ -1592,7 +1642,8 @@ static ssize_t pktgen_if_write(struct file *file, }if (!strcmp (name,"flows" )) { - len =num_arg (&user_buffer[i],10 , &value); + max =min (10 , count - i); + len =num_arg (&user_buffer[i], max, &value);if (len <0 )return len;
@@ -1606,7 +1657,8 @@ static ssize_t pktgen_if_write(struct file *file, }#ifdef CONFIG_XFRM if (!strcmp (name,"spi" )) { - len =num_arg (&user_buffer[i],10 , &value); + max =min (10 , count - i); + len =num_arg (&user_buffer[i], max, &value);if (len <0 )return len;
@@ -1617,7 +1669,8 @@ static ssize_t pktgen_if_write(struct file *file, }#endif if (!strcmp (name,"flowlen" )) { - len =num_arg (&user_buffer[i],10 , &value); + max =min (10 , count - i); + len =num_arg (&user_buffer[i], max, &value);if (len <0 )return len;
@@ -1628,7 +1681,8 @@ static ssize_t pktgen_if_write(struct file *file, }if (!strcmp (name,"queue_map_min" )) { - len =num_arg (&user_buffer[i],5 , &value); + max =min (5 , count - i); + len =num_arg (&user_buffer[i], max, &value);if (len <0 )return len;
@@ -1639,7 +1693,8 @@ static ssize_t pktgen_if_write(struct file *file, }if (!strcmp (name,"queue_map_max" )) { - len =num_arg (&user_buffer[i],5 , &value); + max =min (5 , count - i); + len =num_arg (&user_buffer[i], max, &value);if (len <0 )return len;
@@ -1652,7 +1707,8 @@ static ssize_t pktgen_if_write(struct file *file,if (!strcmp (name,"mpls" )) {unsigned int n, cnt; - len =get_labels (&user_buffer[i], pkt_dev); + max = count - i; + len =get_labels (&user_buffer[i], max, pkt_dev);if (len <0 )return len; i += len;
@@ -1673,7 +1729,8 @@ static ssize_t pktgen_if_write(struct file *file, }if (!strcmp (name,"vlan_id" )) { - len =num_arg (&user_buffer[i],4 , &value); + max =min (4 , count - i); + len =num_arg (&user_buffer[i], max, &value);if (len <0 )return len;
@@ -1700,7 +1757,8 @@ static ssize_t pktgen_if_write(struct file *file, }if (!strcmp (name,"vlan_p" )) { - len =num_arg (&user_buffer[i],1 , &value); + max =min (1 , count - i); + len =num_arg (&user_buffer[i], max, &value);if (len <0 )return len;
@@ -1715,7 +1773,8 @@ static ssize_t pktgen_if_write(struct file *file, }if (!strcmp (name,"vlan_cfi" )) { - len =num_arg (&user_buffer[i],1 , &value); + max =min (1 , count - i); + len =num_arg (&user_buffer[i], max, &value);if (len <0 )return len;
@@ -1730,7 +1789,8 @@ static ssize_t pktgen_if_write(struct file *file, }if (!strcmp (name,"svlan_id" )) { - len =num_arg (&user_buffer[i],4 , &value); + max =min (4 , count - i); + len =num_arg (&user_buffer[i], max, &value);if (len <0 )return len;
@@ -1757,7 +1817,8 @@ static ssize_t pktgen_if_write(struct file *file, }if (!strcmp (name,"svlan_p" )) { - len =num_arg (&user_buffer[i],1 , &value); + max =min (1 , count - i); + len =num_arg (&user_buffer[i], max, &value);if (len <0 )return len;
@@ -1772,7 +1833,8 @@ static ssize_t pktgen_if_write(struct file *file, }if (!strcmp (name,"svlan_cfi" )) { - len =num_arg (&user_buffer[i],1 , &value); + max =min (1 , count - i); + len =num_arg (&user_buffer[i], max, &value);if (len <0 )return len;
@@ -1787,8 +1849,10 @@ static ssize_t pktgen_if_write(struct file *file, }if (!strcmp (name,"tos" )) { -__u32 tmp_value =0 ; - len =hex32_arg (&user_buffer[i],2 , &tmp_value); +__u32 tmp_value; + + max =min (2 , count - i); + len =hex32_arg (&user_buffer[i], max, &tmp_value);if (len <0 )return len;
@@ -1803,8 +1867,10 @@ static ssize_t pktgen_if_write(struct file *file, }if (!strcmp (name,"traffic_class" )) { -__u32 tmp_value =0 ; - len =hex32_arg (&user_buffer[i],2 , &tmp_value); +__u32 tmp_value; + + max =min (2 , count - i); + len =hex32_arg (&user_buffer[i], max, &tmp_value);if (len <0 )return len;
@@ -1819,7 +1885,8 @@ static ssize_t pktgen_if_write(struct file *file, }if (!strcmp (name,"skb_priority" )) { - len =num_arg (&user_buffer[i],9 , &value); + max =min (9 , count - i); + len =num_arg (&user_buffer[i], max, &value);if (len <0 )return len;
Signature · 1 line
2.48.1
Paolo Abeni
maintainerRe: [PATCH net-next v3 08/10] net: pktgen: fix access outside of user given buffer in pktgen_if_write()
Hi,
net/core/pktgen.c static long num_arg(const char __user *user_buffer, unsigned long maxlen, · line 816
Quoted 6 lines · Peter Seiderer
net/core/pktgen.c +2
-0@@ -806,6 +812,9 @@ static long num_arg(const char __user *user_buffer, unsigned long maxlen,if ((c >='0' ) && (c <='9' )) { *num *=10 ; *num += c -'0' ; + }else if (i ==0 ) { +// no valid character parsed, error out
Minor nit: please don't use C99 comments, even for single line one.
net/core/pktgen.c static int strn_len(const char __user * user_buffer, unsigned int maxlen) · line 829
Quoted 10 lines
net/core/pktgen.c +3
-0+return -EINVAL ; }else break ; }@@ -816,6 +825,9 @@ static int strn_len(const char __user * user_buffer, unsigned int maxlen) {int i; +if (!maxlen) +return -EINVAL ;
It looks like this check is not needed? strn_len() will return 0 and the caller will read 0 bytes from the user_buffer.
Quoted 16 lines
net/core/pktgen.c +4
-2@@ -882,39 +897,45 @@ static ssize_t get_imix_entries(const char __user *buffer, pkt_dev->imix_entries[pkt_dev->n_imix_entries].weight = weight; i += len; + pkt_dev->n_imix_entries++; + +if (i >= maxlen) +break ;if (get_user (c, &buffer[i]))return -EFAULT ; - i++; - pkt_dev->n_imix_entries++; }while (c ==' ' );return i;
net/core/pktgen.c static ssize_t get_imix_entries(const char __user *buffer, · line 916
Quoted 10 lines
net/core/pktgen.c +2
-3} -static ssize_t get_labels (const char __user *buffer,struct pktgen_dev *pkt_dev) +static ssize_t get_labels (const char __user *buffer,int maxlen,struct pktgen_dev *pkt_dev) {unsigned int n =0 ;char c; -ssize_t i =0 ; -int len; +int i =0 , max, len;
Minor nit: since you are touching the variables declaration, please fix them to respect the reverse christmas tree order.
This patch is quite large and mixes several things. I'll split out at least the strn_len() caller fixes (possibly even the num_arg() and hex32_arg() ones) and the refactoring in pktgen_if_write().
/P
Re: [PATCH net-next v3 08/10] net: pktgen: fix access outside of user given buffer in pktgen_if_write()
Hello Paolo,
Quoted 11 lines · Paolo Abeni
Hi,
net/core/pktgen.c static long num_arg(const char __user *user_buffer, unsigned long maxlen, · line 816
Quoted 6 lines · Peter Seiderer
net/core/pktgen.c +2
-0@@ -806,6 +812,9 @@ static long num_arg(const char __user *user_buffer, unsigned long maxlen,if ((c >='0' ) && (c <='9' )) { *num *=10 ; *num += c -'0' ; + }else if (i ==0 ) { +// no valid character parsed, error out Minor nit: please don't use C99 comments, even for single line one.
Fixed...
Quoted 9 lines
Quoted 9 lines
net/core/pktgen.c +1
-0+return -EINVAL ; }else break ; }@@ -816,6 +825,9 @@ static int strn_len(const char __user * user_buffer, unsigned int maxlen) {int i;
Quoted 5 lines
Review static int strn_len(const char __user * user_buffer, unsigned int maxlen) · line 829
Quoted 2 lines
(quoted diff) +2
-0+ if (!maxlen) + return -EINVAL;It looks like this check is not needed?
strn_len()will return 0 and the caller will read 0 bytes from theuser_buffer.
Checked all call sites, your are right, fixed in next patch iteration...
Quoted 19 lines
Quoted 19 lines
net/core/pktgen.c +4
-2@@ -882,39 +897,45 @@ static ssize_t get_imix_entries(const char __user *buffer, pkt_dev->imix_entries[pkt_dev->n_imix_entries].weight = weight; i += len; + pkt_dev->n_imix_entries++; + +if (i >= maxlen) +break ;if (get_user (c, &buffer[i]))return -EFAULT ; - i++; - pkt_dev->n_imix_entries++; }while (c ==' ' );return i; }
Quoted 11 lines
net/core/pktgen.c static ssize_t get_imix_entries(const char __user *buffer, · line 916
Quoted 8 lines
net/core/pktgen.c +2
-3-static ssize_t get_labels (const char __user *buffer,struct pktgen_dev *pkt_dev) +static ssize_t get_labels (const char __user *buffer,int maxlen,struct pktgen_dev *pkt_dev) {unsigned int n =0 ;char c; -ssize_t i =0 ; -int len; +int i =0 , max, len;Minor nit: since you are touching the variables declaration, please fix them to respect the reverse christmas tree order.
Fixed...
Quoted 4 lines
This patch is quite large and mixes several things. I'll split out at least the
strn_len()caller fixes (possibly even thenum_arg()andhex32_arg()ones) and the refactoring inpktgen_if_write().
Done in the next patch iteration....
Thanks for review!
Regards,
Peter
Quoted 3 lines
/P
Simon Horman
reviewerRe: [PATCH net-next v3 08/10] net: pktgen: fix access outside of user given buffer in pktgen_if_write()
In reply to Peter SeidererQuoted 15 lines · Peter Seiderer
Honour the user given buffer size for the
hex32_arg(),num_arg(),strn_len(),get_imix_entries()andget_labels()calls (otherwise they will access memory outside of the user given buffer).In
hex32_arg(),num_arg(),strn_len()error out in case no characters are available (maxlen = 0), innum_arg()additional error out in case no valid character is parsed.In
get_labels()additional enable parsing labels up toMAX_IMIX_ENTRIESinstead of (MAX_IMIX_ENTRIES- 1).Additional remove some superfluous variable initializing and align some variable declarations to the most common pattern.
Signed-off-by Peter Seiderer <[email protected]>
...
Quoted 1 line
net/core/pktgen.c +0
-0
...
net/core/pktgen.c static ssize_t get_imix_entries(const char __user *buffer, · line 889
Quoted 6 lines
net/core/pktgen.c +1
-1@@ -872,7 +886,8 @@ static ssize_t get_imix_entries(const char __user *buffer,if (size <14 +20 +8 ) size =14 +20 +8 ; - len =num_arg (&buffer[i], max_digits, &weight); + max =min (10 , maxlen - i);
Hi Peter,
10 is used as a magic value here. I think it would be best if it were a #define so it has a name. Likewise for other constants used as arguments to min() in this patch.
...
Re: [PATCH net-next v3 08/10] net: pktgen: fix access outside of user given buffer in pktgen_if_write()
Hello Simon,
Quoted 32 lines · Simon Horman
Quoted 15 lines · Peter Seiderer
Honour the user given buffer size for the
hex32_arg(),num_arg(),strn_len(),get_imix_entries()andget_labels()calls (otherwise they will access memory outside of the user given buffer).In
hex32_arg(),num_arg(),strn_len()error out in case no characters are available (maxlen = 0), innum_arg()additional error out in case no valid character is parsed.In
get_labels()additional enable parsing labels up toMAX_IMIX_ENTRIESinstead of (MAX_IMIX_ENTRIES- 1).Additional remove some superfluous variable initializing and align some variable declarations to the most common pattern.
Signed-off-by Peter Seiderer <[email protected]>...
Quoted 1 line
net/core/pktgen.c +0
-0...
net/core/pktgen.c static ssize_t get_imix_entries(const char __user *buffer, · line 889
Quoted 6 lines
net/core/pktgen.c +1
-1@@ -872,7 +886,8 @@ static ssize_t get_imix_entries(const char __user *buffer,if (size <14 +20 +8 ) size =14 +20 +8 ; - len =num_arg (&buffer[i], max_digits, &weight); + max =min (10 , maxlen - i);Hi Peter,
Quoted 5 lines
10 is used as a magic value here. I think it would be best if it were a #define so it has a name. Likewise for other constants used as arguments to
min()in this patch....
O.k, done in the next patch iteration...
Thanks for review!
Regards,
Peter
PATCH v3 9/10 net: pktgen: fix mpls reset parsing
In reply to Peter SeidererFix mpls list reset parsing to work as describe in Documentation/networking/pktgen.rst:
pgset "mpls 0" turn off mpls (or any invalid argument works too!)
- before the patch
$ echo "mpls 00000001,00000002" > /proc/net/pktgen/lo\@0 $ grep mpls /proc/net/pktgen/lo\@0 mpls: 00000001, 00000002 Result: OK: mpls=00000001,00000002
$ echo "mpls 00000001,00000002" > /proc/net/pktgen/lo\@0 $ echo "mpls 0" > /proc/net/pktgen/lo\@0 $ grep mpls /proc/net/pktgen/lo\@0 mpls: 00000000 Result: OK: mpls=00000000
$ echo "mpls 00000001,00000002" > /proc/net/pktgen/lo\@0 $ echo "mpls invalid" > /proc/net/pktgen/lo\@0 $ grep mpls /proc/net/pktgen/lo\@0 Result: OK: mpls=
- after the patch
$ echo "mpls 00000001,00000002" > /proc/net/pktgen/lo\@0 $ grep mpls /proc/net/pktgen/lo\@0 mpls: 00000001, 00000002 Result: OK: mpls=00000001,00000002
$ echo "mpls 00000001,00000002" > /proc/net/pktgen/lo\@0 $ echo "mpls 0" > /proc/net/pktgen/lo\@0 $ grep mpls /proc/net/pktgen/lo\@0 Result: OK: mpls=
$ echo "mpls 00000001,00000002" > /proc/net/pktgen/lo\@0 $ echo "mpls invalid" > /proc/net/pktgen/lo\@0 $ grep mpls /proc/net/pktgen/lo\@0 Result: OK: mpls=
---
Changes v2 -> v3:
- new patch
--- net/core/pktgen.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
net/core/pktgen.c +6 -1
@@ -924,8 +924,13 @@ static ssize_t get_labels(const char __user *buffer, int maxlen, struct pktgen_d max =min (8 , maxlen - i); len =hex32_arg (&buffer[i], max, &tmp); -if (len <=0 ) +if (len <0 )return len; + +// return empty list in case of invalid input and/or zero value +if (len ==0 || tmp ==0 ) +return maxlen; + pkt_dev->labels[n] =htonl (tmp);if (pkt_dev->labels[n] &MPLS_STACK_BOTTOM ) pkt_dev->flags |=F_MPLS_RND ;
Signature · 1 line
2.48.1
Re: [PATCH net-next v3 09/10] net: pktgen: fix mpls reset parsing
Quoted 35 lines · Peter Seiderer
Fix mpls list reset parsing to work as describe in
Documentation/networking/pktgen.rst:pgset "mpls 0" turn off mpls (or any invalid argument works too!)
- before the patch
$ echo "mpls 00000001,00000002" > /proc/net/pktgen/lo\@0 $ grep mpls /proc/net/pktgen/lo\@0 mpls: 00000001, 00000002 Result: OK: mpls=00000001,00000002$ echo "mpls 00000001,00000002" > /proc/net/pktgen/lo\@0 $ echo "mpls 0" > /proc/net/pktgen/lo\@0 $ grep mpls /proc/net/pktgen/lo\@0 mpls: 00000000 Result: OK: mpls=00000000$ echo "mpls 00000001,00000002" > /proc/net/pktgen/lo\@0 $ echo "mpls invalid" > /proc/net/pktgen/lo\@0 $ grep mpls /proc/net/pktgen/lo\@0 Result: OK: mpls=- after the patch
$ echo "mpls 00000001,00000002" > /proc/net/pktgen/lo\@0 $ grep mpls /proc/net/pktgen/lo\@0 mpls: 00000001, 00000002 Result: OK: mpls=00000001,00000002$ echo "mpls 00000001,00000002" > /proc/net/pktgen/lo\@0 $ echo "mpls 0" > /proc/net/pktgen/lo\@0 $ grep mpls /proc/net/pktgen/lo\@0 Result: OK: mpls=
Quoted 6 lines
$ echo "mpls 00000001,00000002" > /proc/net/pktgen/lo\@0 $ echo "mpls invalid" > /proc/net/pktgen/lo\@0 $ grep mpls /proc/net/pktgen/lo\@0 Result: OK: mpls=Signed-off-by Peter Seiderer <[email protected]>
PATCH v3 10/10 selftest: net: add proc_net_pktgen
In reply to Peter SeidererAdd some test for /proc/net/pktgen/... interface.
- enable 'CONFIG_NET_PKTGEN=m' in tools/testing/selftests/net/config
---
Changes v2 -> v3:
- fix typo in change description ('v1 -> v1' and tyop)
- rename some vars to better match usage
add_loopback_0 -> thr_cmd_add_loopback_0
rm_loopback_0 -> thr_cmd_rm_loopback_0
wrong_ctrl_cmd -> wrong_thr_cmd
legacy_ctrl_cmd -> legacy_thr_cmd
ctrl_fd -> thr_fd- add ctrl interface tests
Changes v1 -> v2:
- fix tyop not vs. nod (suggested by Jakub Kicinski)
- fix misaligned line (suggested by Jakub Kicinski)
- enable fomerly commented out CONFIG_XFRM dependent test (command spi), as CONFIG_XFRM is enabled via tools/testing/selftests/net/config CONFIG_XFRM_INTERFACE/CONFIG_XFRM_USER (suggestex by Jakub Kicinski)
- add CONFIG_NET_PKTGEN=m to tools/testing/selftests/net/config (suggested by Jakub Kicinski)
- add modprobe pktgen to FIXTURE_SETUP() (suggested by Jakub Kicinski)
- fix some checkpatch warnings (Missing a blank line after declarations)
- shrink line length by re-naming some variables (command -> cmd,
device -> dev) - add 'rate 0' testcase - add 'ratep 0' testcase --- tools/testing/selftests/net/Makefile | 1 + tools/testing/selftests/net/config | 1 + tools/testing/selftests/net/proc_net_pktgen.c | 650 ++++++++++++++++++ 3 files changed, 652 insertions(+) create mode 100644 tools/testing/selftests/net/proc_net_pktgen.c
tools/testing/selftests/net/Makefile +1 -0
@@ -100,6 +100,7 @@ TEST_PROGS += vlan_bridge_binding.sh TEST_PROGS += bpf_offload.py TEST_PROGS += ipv6_route_update_soft_lockup.sh TEST_PROGS += busy_poll_test.sh +TEST_GEN_PROGS += proc_net_pktgen # YNL files, must be before "include ..lib.mk" YNL_GEN_FILES := busy_poller netlink-dumps
tools/testing/selftests/net/config +1 -0
@@ -107,3 +107,4 @@ CONFIG_XFRM_INTERFACE=m CONFIG_XFRM_USER=m CONFIG_IP_NF_MATCH_RPFILTER=m CONFIG_IP6_NF_MATCH_RPFILTER=m +CONFIG_NET_PKTGEN=m
tools/testing/selftests/net/proc_net_pktgen.c new file +650 -0
650 lines not on this page · raw message
Signature · 1 line
2.48.1