diff options
author | Mathias Krause <minipli@googlemail.com> | 2014-02-21 15:38:34 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-02-24 18:54:25 -0500 |
commit | 20b0c718c3bb122107bebadbb8ecf4bab76fb392 (patch) | |
tree | 1408cdb798aacbb27a42fe735b6658289c6004ec /net/core | |
parent | 8bfdfbc188ff46f7495ae05a2bc366943b83393f (diff) |
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.
Cc: "David S. Miller" <davem@davemloft.net>
Signed-off-by: Mathias Krause <minipli@googlemail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core')
-rw-r--r-- | net/core/pktgen.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/net/core/pktgen.c b/net/core/pktgen.c index fdac61cac1bd..cc07c434948a 100644 --- a/net/core/pktgen.c +++ b/net/core/pktgen.c | |||
@@ -485,6 +485,9 @@ static ssize_t pgctrl_write(struct file *file, const char __user *buf, | |||
485 | goto out; | 485 | goto out; |
486 | } | 486 | } |
487 | 487 | ||
488 | if (count == 0) | ||
489 | return -EINVAL; | ||
490 | |||
488 | if (count > sizeof(data)) | 491 | if (count > sizeof(data)) |
489 | count = sizeof(data); | 492 | count = sizeof(data); |
490 | 493 | ||
@@ -492,7 +495,7 @@ static ssize_t pgctrl_write(struct file *file, const char __user *buf, | |||
492 | err = -EFAULT; | 495 | err = -EFAULT; |
493 | goto out; | 496 | goto out; |
494 | } | 497 | } |
495 | data[count - 1] = 0; /* Make string */ | 498 | data[count - 1] = 0; /* Strip trailing '\n' and terminate string */ |
496 | 499 | ||
497 | if (!strcmp(data, "stop")) | 500 | if (!strcmp(data, "stop")) |
498 | pktgen_stop_all_threads_ifs(pn); | 501 | pktgen_stop_all_threads_ifs(pn); |