提交 2dc5d12b 编写于 作者: S Steven Rostedt

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: NSteven Rostedt <srostedt@redhat.com>
上级 4f3640f8
...@@ -346,6 +346,9 @@ ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt) ...@@ -346,6 +346,9 @@ ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt)
int len; int len;
int ret; int ret;
if (!cnt)
return 0;
if (s->len <= s->readpos) if (s->len <= s->readpos)
return -EBUSY; return -EBUSY;
...@@ -353,9 +356,11 @@ ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt) ...@@ -353,9 +356,11 @@ ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt)
if (cnt > len) if (cnt > len)
cnt = len; cnt = len;
ret = copy_to_user(ubuf, s->buffer + s->readpos, cnt); ret = copy_to_user(ubuf, s->buffer + s->readpos, cnt);
if (ret) if (ret == cnt)
return -EFAULT; return -EFAULT;
cnt -= ret;
s->readpos += len; s->readpos += len;
return cnt; return cnt;
} }
...@@ -3049,6 +3054,9 @@ tracing_buffers_read(struct file *filp, char __user *ubuf, ...@@ -3049,6 +3054,9 @@ tracing_buffers_read(struct file *filp, char __user *ubuf,
ssize_t ret; ssize_t ret;
size_t size; size_t size;
if (!count)
return 0;
/* Do we have previous read data to read? */ /* Do we have previous read data to read? */
if (info->read < PAGE_SIZE) if (info->read < PAGE_SIZE)
goto read; goto read;
...@@ -3073,8 +3081,10 @@ tracing_buffers_read(struct file *filp, char __user *ubuf, ...@@ -3073,8 +3081,10 @@ tracing_buffers_read(struct file *filp, char __user *ubuf,
size = count; size = count;
ret = copy_to_user(ubuf, info->spare + info->read, size); ret = copy_to_user(ubuf, info->spare + info->read, size);
if (ret) if (ret == size)
return -EFAULT; return -EFAULT;
size -= ret;
*ppos += size; *ppos += size;
info->read += size; info->read += size;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册