pktgen: small cleanups
Subsystems (3)
cover pktgen: small cleanups
This series is just a set of small cleanups of pktgen code and documentation.
Please apply!
Mathias Krause (3):
pktgen: fix out-of-bounds access in pgctrl_write()
pktgen: simplify error handling in pgctrl_write()
pktgen: document all supported flags
Documentation/networking/pktgen.txt | 24 +++++++++++++++++++----- net/core/pktgen.c | 32 +++++++++++++++++--------------- 2 files changed, 36 insertions(+), 20 deletions(-)
Signature · 1 line
1.7.10.4
PATCH 1/3 pktgen: fix out-of-bounds access in pgctrl_write()
If a privileged user writes an empty string to /proc/net/pktgen/pgctrl the code for stripping the (then non-existent) '\n' actually writes the zero byte at index -1 of data[]. The then still uninitialized array will very likely fail the command matching tests and the pr_warning() at the end will therefore leak stack bytes to the kernel log.
Fix those issues by simply ensuring we're passed a non-empty string as the user API apparently expects a trailing '\n' for all commands.
--- net/core/pktgen.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/core/pktgen.c +4 -1
@@ -485,6 +485,9 @@ static ssize_t pgctrl_write(struct file *file, const char __user *buf, goto out; } +if (count ==0 ) +return -EINVAL ; +if (count >sizeof (data)) count =sizeof (data);
@@ -492,7 +495,7 @@ static ssize_t pgctrl_write(struct file *file, const char __user *buf, err = -EFAULT ; goto out; } - data[count -1 ] =0 ;/* Make string */ + data[count -1 ] =0 ;/* Strip trailing '\n' and terminate string */ if (!strcmp (data,"stop" ))pktgen_stop_all_threads_ifs (pn);
Signature · 1 line
1.7.10.4
PATCH 2/3 pktgen: simplify error handling in pgctrl_write()
In reply to Mathias KrauseThe 'out' label is just a relict from previous times as pgctrl_write() had multiple error paths. Get rid of it and simply return right away on errors.
--- net/core/pktgen.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-)
net/core/pktgen.c +6 -13
@@ -476,14 +476,11 @@ static int pgctrl_show(struct seq_file *seq, void *v)static ssize_t pgctrl_write (struct file *file,const char __user *buf,size_t count,loff_t *ppos) { -int err =0 ;char data[128 ];struct pktgen_net *pn =net_generic (current->nsproxy->net_ns, pg_net_id); -if (!capable (CAP_NET_ADMIN )) { - err = -EPERM ; - goto out; - } +if (!capable (CAP_NET_ADMIN )) +return -EPERM ;if (count ==0 )return -EINVAL ;
@@ -491,10 +488,9 @@ static ssize_t pgctrl_write(struct file *file, const char __user *buf,if (count >sizeof (data)) count =sizeof (data); -if (copy_from_user (data, buf, count)) { - err = -EFAULT ; - goto out; - } +if (copy_from_user (data, buf, count)) +return -EFAULT ; + data[count -1 ] =0 ;/* Strip trailing '\n' and terminate string */ if (!strcmp (data,"stop" ))
@@ -509,10 +505,7 @@ static ssize_t pgctrl_write(struct file *file, const char __user *buf,else pr_warning ("Unknown command: %s\n" , data); - err = count; - -out: -return err; +return count; }static int pgctrl_open (struct inode *inode,struct file *file)
Signature · 1 line
1.7.10.4
PATCH 3/3 pktgen: document all supported flags
In reply to Mathias KrauseThe documentation misses a few of the supported flags. Fix this. Also respect the dependency to CONFIG_XFRM for the IPSEC flag.
--- Documentation/networking/pktgen.txt | 24 +++++++++++++++++++----- net/core/pktgen.c | 8 +++++++- 2 files changed, 26 insertions(+), 6 deletions(-)
Documentation/networking/pktgen.txt +19 -5
@@ -102,13 +102,18 @@ Examples: The 'minimum' MAC is what you set with dstmac. pgset "flag [name]" Set a flag to determine behaviour. Current flags - are: IPSRC_RND #IP Source is random (between min/max), - IPDST_RND, UDPSRC_RND, - UDPDST_RND, MACSRC_RND, MACDST_RND + are: IPSRC_RND # IP source is random (between min/max) + IPDST_RND # IP destination is random + UDPSRC_RND, UDPDST_RND, + MACSRC_RND, MACDST_RND + TXSIZE_RND, IPV6, MPLS_RND, VID_RND, SVID_RND + FLOW_SEQ, QUEUE_MAP_RND # queue map random QUEUE_MAP_CPU # queue map mirrors smp_processor_id() - IPSEC # Make IPsec encapsulation for packet + UDPCSUM, + IPSEC # IPsec encapsulation (needs CONFIG_XFRM) + NODE_ALLOC # node specific memory allocation pgset spi SPI_VALUE Set specific SA used to transform packet.
@@ -233,13 +238,22 @@ udp_dst_max flag IPSRC_RND - TXSIZE_RND IPDST_RND UDPSRC_RND UDPDST_RND MACSRC_RND MACDST_RND + TXSIZE_RND + IPV6 + MPLS_RND + VID_RND + SVID_RND + FLOW_SEQ + QUEUE_MAP_RND + QUEUE_MAP_CPU + UDPCSUM IPSEC + NODE_ALLOC dst_min dst_max
net/core/pktgen.c +7 -1
@@ -1247,7 +1247,13 @@ static ssize_t pktgen_if_write(struct file *file,"Flag -:%s:- unknown\nAvailable flags, (prepend ! to un-set flag):\n%s" , f,"IPSRC_RND, IPDST_RND, UDPSRC_RND, UDPDST_RND, " - "MACSRC_RND, MACDST_RND, TXSIZE_RND, IPV6, MPLS_RND, VID_RND, SVID_RND, FLOW_SEQ, IPSEC, NODE_ALLOC\n"); +"MACSRC_RND, MACDST_RND, TXSIZE_RND, IPV6, " +"MPLS_RND, VID_RND, SVID_RND, FLOW_SEQ, " +"QUEUE_MAP_RND, QUEUE_MAP_CPU, UDPCSUM, " +#ifdef CONFIG_XFRM +"IPSEC, " +#endif + "NODE_ALLOC\n");return count; }sprintf (pg_result,"OK: flags=0x%x" , pkt_dev->flags);
Signature · 1 line
1.7.10.4
David Miller
maintainerFrom: Mathias Krause <[email protected]>
Date: Fri, 21 Feb 2014 21:38:33 +0100
Quoted 4 lines
This series is just a set of small cleanups of pktgen code and documentation.
Please apply!
Series applied, thank you.