Skip to content

Commit

Permalink
pktgen: fix out-of-bounds access in pgctrl_write()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Mathias Krause authored and David S. Miller committed Feb 24, 2014
1 parent 8bfdfbc commit 20b0c71
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion net/core/pktgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,14 +485,17 @@ 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);

if (copy_from_user(data, buf, count)) {
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);
Expand Down

0 comments on commit 20b0c71

Please sign in to comment.