Skip to contentSkip to conversation

tracing: fix splice return too large

PATCH In review Lai Jiangshan 3 participants 6 messages Apr 2, 2009 – Apr 13, 2009 Tracing

lore
Share & tools
lore
#0 lore raw

PATCH 4/4 tracing: fix splice return too large

I got these from strace:

splice(0x3, 0, 0x5, 0, 0x1000, 0x1) = 12288
splice(0x3, 0, 0x5, 0, 0x1000, 0x1) = 12288
splice(0x3, 0, 0x5, 0, 0x1000, 0x1) = 12288
splice(0x3, 0, 0x5, 0, 0x1000, 0x1) = 16384
splice(0x3, 0, 0x5, 0, 0x1000, 0x1) = 8192
splice(0x3, 0, 0x5, 0, 0x1000, 0x1) = 8192
splice(0x3, 0, 0x5, 0, 0x1000, 0x1) = 8192

I wanted to splice_read 4096 bytes, but it returns 8192 or larger.

It is because the return value of tracing_buffers_splice_read() is not include "zero out any left over data" bytes. But tracing_buffers_read() include these bytes, we make them consistent.

---

kernel/trace/trace.c +14 -2
index d101c12..a7ea047 100644
@@ -3408,7 +3408,19 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos,
 	int size, i;
 	size_t ret;
 
-	for (i = 0; i < PIPE_BUFFERS && len; i++, len -= size) {
+	if (*ppos & (PAGE_SIZE - 1)) {
+		WARN_ONCE(1, "Ftrace: previous read must page-align\n");
+		return -EINVAL;
+	}
+
+	if (len & (PAGE_SIZE - 1)) {
+		WARN_ONCE(1, "Ftrace: splice_read should page-align\n");
+		if (len < PAGE_SIZE)
+			return -EINVAL;
+		len &= PAGE_MASK;
+	}
+
+	for (i = 0; i < PIPE_BUFFERS && len; i++, len -= PAGE_SIZE) {
 		struct page *page;
 		int r;
 
@@ -3447,7 +3459,7 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos,
 		spd.partial[i].offset = 0;
 		spd.partial[i].private = (unsigned long)ref;
 		spd.nr_pages++;
-		*ppos += size;
+		*ppos += PAGE_SIZE;
 	}
 
 	spd.nr_pages = i;
#1 lore raw

kernel/trace/trace.c tracing_buffers_splice_read(struct file *file, loff_t *ppos, · line 3421

Quoted 12 lines · Lai Jiangshan
kernel/trace/trace.c +11 -1
-	for (i = 0; i < PIPE_BUFFERS && len; i++, len -= size) {
+	if (*ppos & (PAGE_SIZE - 1)) {
+		WARN_ONCE(1, "Ftrace: previous read must page-align\n");
+		return -EINVAL;
+	}
+
+	if (len & (PAGE_SIZE - 1)) {
+		WARN_ONCE(1, "Ftrace: splice_read should page-align\n");
+		if (len < PAGE_SIZE)
+			return -EINVAL;
+		len &= PAGE_MASK;
+	}

Hm, the fix looks good, but is it a good idea to allow the triggering of this message from user-space?

Ingo

#2 lore raw
Quoted 18 lines · Ingo Molnar

kernel/trace/trace.c tracing_buffers_splice_read(struct file *file, loff_t *ppos, · line 3421

Quoted 12 lines · Lai Jiangshan
kernel/trace/trace.c +11 -1
-	for (i = 0; i < PIPE_BUFFERS && len; i++, len -= size) {
+	if (*ppos & (PAGE_SIZE - 1)) {
+		WARN_ONCE(1, "Ftrace: previous read must page-align\n");
+		return -EINVAL;
+	}
+
+	if (len & (PAGE_SIZE - 1)) {
+		WARN_ONCE(1, "Ftrace: splice_read should page-align\n");
+		if (len < PAGE_SIZE)
+			return -EINVAL;
+		len &= PAGE_MASK;
+	}

Hm, the fix looks good, but is it a good idea to allow the triggering of this message from user-space?

But it is only triggered once.

If user get content from trace_pipe_raw with non-page-align, the content is garbage. It's wasting, the kernel disallows it. This message tell user why he read failed.

These 4 patches make trace_pipe_raw more robustious and consistent (read by read(2) and splice). I focus on handling raw ftrace data in userspace, these raw ftrace data should be trustiness.

Thanks.
Lai.

#3 lore raw
Quoted 22 lines · Lai Jiangshan
Quoted 18 lines · Ingo Molnar

kernel/trace/trace.c tracing_buffers_splice_read(struct file *file, loff_t *ppos, · line 3421

Quoted 12 lines · Lai Jiangshan
kernel/trace/trace.c +11 -1
-	for (i = 0; i < PIPE_BUFFERS && len; i++, len -= size) {
+	if (*ppos & (PAGE_SIZE - 1)) {
+		WARN_ONCE(1, "Ftrace: previous read must page-align\n");
+		return -EINVAL;
+	}
+
+	if (len & (PAGE_SIZE - 1)) {
+		WARN_ONCE(1, "Ftrace: splice_read should page-align\n");
+		if (len < PAGE_SIZE)
+			return -EINVAL;
+		len &= PAGE_MASK;
+	}

Hm, the fix looks good, but is it a good idea to allow the triggering of this message from user-space?

But it is only triggered once.

Quoted 7 lines

If user get content from trace_pipe_raw with non-page-align, the content is garbage. It's wasting, the kernel disallows it. This message tell user why he read failed.

These 4 patches make trace_pipe_raw more robustious and consistent (read by read(2) and splice). I focus on handling raw ftrace data in userspace, these raw ftrace data should be trustiness.

Ok, agreed.

i've applied these four fixes from you to tip:tracing/splice, thanks. Steve: i think they are tracing/urgent material - do you agree?

Ingo

#5 lore raw
In reply to Lai Jiangshan
Commit-ID:  93cfb3c9fd83d877a8f1ffad9ff862b617b32828
Gitweb:     http://git.kernel.org/tip/93cfb3c9fd83d877a8f1ffad9ff862b617b32828
Author:     Lai Jiangshan <[email protected]>
AuthorDate: Thu, 2 Apr 2009 15:17:08 +0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 10 Apr 2009 12:44:46 +0200

tracing: fix splice return too large

I got these from strace:

splice(0x3, 0, 0x5, 0, 0x1000, 0x1) = 12288
splice(0x3, 0, 0x5, 0, 0x1000, 0x1) = 12288
splice(0x3, 0, 0x5, 0, 0x1000, 0x1) = 12288
splice(0x3, 0, 0x5, 0, 0x1000, 0x1) = 16384
splice(0x3, 0, 0x5, 0, 0x1000, 0x1) = 8192
splice(0x3, 0, 0x5, 0, 0x1000, 0x1) = 8192
splice(0x3, 0, 0x5, 0, 0x1000, 0x1) = 8192

I wanted to splice_read 4096 bytes, but it returns 8192 or larger.

It is because the return value of tracing_buffers_splice_read() does not include "zero out any left over data" bytes.

But tracing_buffers_read() includes these bytes, we make them consistent.

Cc Frederic Weisbecker <[email protected]>
Cc Steven Rostedt <[email protected]>

LKML-Reference: <[email protected]>

---
 kernel/trace/trace.c |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)
kernel/trace/trace.c +14 -2
index 9462976..1ce5dc6 100644
@@ -3428,7 +3428,19 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos,
 	int size, i;
 	size_t ret;
 
-	for (i = 0; i < PIPE_BUFFERS && len; i++, len -= size) {
+	if (*ppos & (PAGE_SIZE - 1)) {
+		WARN_ONCE(1, "Ftrace: previous read must page-align\n");
+		return -EINVAL;
+	}
+
+	if (len & (PAGE_SIZE - 1)) {
+		WARN_ONCE(1, "Ftrace: splice_read should page-align\n");
+		if (len < PAGE_SIZE)
+			return -EINVAL;
+		len &= PAGE_MASK;
+	}
+
+	for (i = 0; i < PIPE_BUFFERS && len; i++, len -= PAGE_SIZE) {
 		struct page *page;
 		int r;
 
@@ -3467,7 +3479,7 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos,
 		spd.partial[i].offset = 0;
 		spd.partial[i].private = (unsigned long)ref;
 		spd.nr_pages++;
-		*ppos += size;
+		*ppos += PAGE_SIZE;
 	}
 
 	spd.nr_pages = i;
#4 lore raw
In reply to Ingo Molnar
Quoted 8 lines · Ingo Molnar
Quoted 6 lines · Lai Jiangshan
Quoted 5 lines · Ingo Molnar

kernel/trace/trace.c tracing_buffers_splice_read(struct file *file, loff_t *ppos, · line 3412

Quoted 3 lines · Lai Jiangshan
kernel/trace/trace.c +2 -1
-	for (i = 0; i < PIPE_BUFFERS && len; i++, len -= size) {
+	if (*ppos & (PAGE_SIZE - 1)) {
+		WARN_ONCE(1, "Ftrace: previous read must page-align\n");

Small English grammar nit,

"Ftrace: previous read must be page-aligned"

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

kernel/trace/trace.c tracing_buffers_splice_read(struct file *file, loff_t *ppos, · line 3417

Quoted 5 lines
kernel/trace/trace.c +5 -0
+		return -EINVAL;
+	}
+
+	if (len & (PAGE_SIZE - 1)) {
+		WARN_ONCE(1, "Ftrace: splice_read should page-align\n");

"Ftrace: splice_read should be page-aligned"

Quoted 19 lines
Quoted 11 lines
Quoted 8 lines

kernel/trace/trace.c tracing_buffers_splice_read(struct file *file, loff_t *ppos, · line 3421

Quoted 4 lines
kernel/trace/trace.c +4 -0
+		if (len < PAGE_SIZE)
+			return -EINVAL;
+		len &= PAGE_MASK;
+	}

Hm, the fix looks good, but is it a good idea to allow the triggering of this message from user-space?

But it is only triggered once.

Quoted 7 lines

If user get content from trace_pipe_raw with non-page-align, the content is garbage. It's wasting, the kernel disallows it. This message tell user why he read failed.

These 4 patches make trace_pipe_raw more robustious and consistent (read by read(2) and splice). I focus on handling raw ftrace data in userspace, these raw ftrace data should be trustiness.

Quoted 5 lines

Ok, agreed.

i've applied these four fixes from you to tip:tracing/splice, thanks. Steve: i think they are tracing/urgent material - do you agree?

Agreed. With my comments above:

-- Steve