diff options
author | Vasiliy Kulikov <segoon@openwall.com> | 2010-11-14 02:06:08 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2010-11-17 15:27:46 -0500 |
commit | dda0b38692a7298f433b92b1329867b1ecabb4bb (patch) | |
tree | 87e070e4d51fe128214c838f534afe1c28178f19 /net | |
parent | 9ea19481db31d614f729f346bdcf28e4e60ff14a (diff) |
net: ipv4: tcp_probe: cleanup snprintf() use
snprintf() returns number of bytes that were copied if there is no overflow.
This code uses return value as number of copied bytes. Theoretically format
string '%lu.%09lu %pI4:%u %pI4:%u %d %#x %#x %u %u %u %u\n' may be expanded
up to 163 bytes. In reality tv.tv_sec is just few bytes instead of 20, 2 ports
are just 5 bytes each instead of 10, length is 5 bytes instead of 10. The rest
is an unstrusted input. Theoretically if tv_sec is big then copy_to_user() would
overflow tbuf.
tbuf was increased to fit in 163 bytes. snprintf() is used to follow return
value semantic.
Signed-off-by: Vasiliy Kulikov <segoon@openwall.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r-- | net/ipv4/tcp_probe.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c index 6211e2114173..85ee7eb7e38e 100644 --- a/net/ipv4/tcp_probe.c +++ b/net/ipv4/tcp_probe.c | |||
@@ -154,7 +154,7 @@ static int tcpprobe_sprint(char *tbuf, int n) | |||
154 | struct timespec tv | 154 | struct timespec tv |
155 | = ktime_to_timespec(ktime_sub(p->tstamp, tcp_probe.start)); | 155 | = ktime_to_timespec(ktime_sub(p->tstamp, tcp_probe.start)); |
156 | 156 | ||
157 | return snprintf(tbuf, n, | 157 | return scnprintf(tbuf, n, |
158 | "%lu.%09lu %pI4:%u %pI4:%u %d %#x %#x %u %u %u %u\n", | 158 | "%lu.%09lu %pI4:%u %pI4:%u %d %#x %#x %u %u %u %u\n", |
159 | (unsigned long) tv.tv_sec, | 159 | (unsigned long) tv.tv_sec, |
160 | (unsigned long) tv.tv_nsec, | 160 | (unsigned long) tv.tv_nsec, |
@@ -174,7 +174,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf, | |||
174 | return -EINVAL; | 174 | return -EINVAL; |
175 | 175 | ||
176 | while (cnt < len) { | 176 | while (cnt < len) { |
177 | char tbuf[128]; | 177 | char tbuf[164]; |
178 | int width; | 178 | int width; |
179 | 179 | ||
180 | /* Wait for data in buffer */ | 180 | /* Wait for data in buffer */ |