diff options
author | Steven Rostedt <srostedt@redhat.com> | 2009-03-04 19:10:05 -0500 |
---|---|---|
committer | Steven Rostedt <srostedt@redhat.com> | 2009-03-04 19:10:05 -0500 |
commit | 2dc5d12b1f43134e9bc5037f69f4739cfdfab93e (patch) | |
tree | fd1070a750b7f88e01527b3d808e73f7f9fcb45a /kernel/trace/trace.c | |
parent | 4f3640f8a358f2183a8c966f299eeb55ca523e06 (diff) |
tracing: do not return EFAULT if read copied anything
Impact: fix trace read to conform to standards
Andrew Morton, Theodore Tso and H. Peter Anvin brought to my attention
that a userspace read should not return -EFAULT if it succeeded in
copying anything. It should only return -EFAULT if it failed to copy
at all.
This patch modifies the check of copy_from_user and updates the return
code appropriately.
I also used H. Peter Anvin's short cut rule to just test ret == count.
Signed-off-by: Steven Rostedt <srostedt@redhat.com>
Diffstat (limited to 'kernel/trace/trace.c')
-rw-r--r-- | kernel/trace/trace.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index ab5cbcae43a1..57155dc53530 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c | |||
@@ -346,6 +346,9 @@ ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt) | |||
346 | int len; | 346 | int len; |
347 | int ret; | 347 | int ret; |
348 | 348 | ||
349 | if (!cnt) | ||
350 | return 0; | ||
351 | |||
349 | if (s->len <= s->readpos) | 352 | if (s->len <= s->readpos) |
350 | return -EBUSY; | 353 | return -EBUSY; |
351 | 354 | ||
@@ -353,9 +356,11 @@ ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt) | |||
353 | if (cnt > len) | 356 | if (cnt > len) |
354 | cnt = len; | 357 | cnt = len; |
355 | ret = copy_to_user(ubuf, s->buffer + s->readpos, cnt); | 358 | ret = copy_to_user(ubuf, s->buffer + s->readpos, cnt); |
356 | if (ret) | 359 | if (ret == cnt) |
357 | return -EFAULT; | 360 | return -EFAULT; |
358 | 361 | ||
362 | cnt -= ret; | ||
363 | |||
359 | s->readpos += len; | 364 | s->readpos += len; |
360 | return cnt; | 365 | return cnt; |
361 | } | 366 | } |
@@ -3049,6 +3054,9 @@ tracing_buffers_read(struct file *filp, char __user *ubuf, | |||
3049 | ssize_t ret; | 3054 | ssize_t ret; |
3050 | size_t size; | 3055 | size_t size; |
3051 | 3056 | ||
3057 | if (!count) | ||
3058 | return 0; | ||
3059 | |||
3052 | /* Do we have previous read data to read? */ | 3060 | /* Do we have previous read data to read? */ |
3053 | if (info->read < PAGE_SIZE) | 3061 | if (info->read < PAGE_SIZE) |
3054 | goto read; | 3062 | goto read; |
@@ -3073,8 +3081,10 @@ read: | |||
3073 | size = count; | 3081 | size = count; |
3074 | 3082 | ||
3075 | ret = copy_to_user(ubuf, info->spare + info->read, size); | 3083 | ret = copy_to_user(ubuf, info->spare + info->read, size); |
3076 | if (ret) | 3084 | if (ret == size) |
3077 | return -EFAULT; | 3085 | return -EFAULT; |
3086 | size -= ret; | ||
3087 | |||
3078 | *ppos += size; | 3088 | *ppos += size; |
3079 | info->read += size; | 3089 | info->read += size; |
3080 | 3090 | ||