Skip to contentSkip to conversation

tracing: use seq_buf_used() in seq_buf_to_user() instead of len

PATCH In review Jerry Snitselaar 2 participants 2 messages Nov 16, 2015 – Dec 23, 2015 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tracing: use seq_buf_used() in seq_buf_to_user() instead of len

commit 5ac48378414d ("tracing: Use trace_seq_used() and seq_buf_used() instead of len") changed the tracing code to use trace_seq_used() and seq_buf_used() instead of using the seq_buf len directly to avoid overflow issues, but missed a spot in seq_buf_to_user() that makes use of s->len.

Cleaned up the code a bit as well per suggestion of Steve Rostedt.

Cc "Steven Rostedt (Red Hat)" <[email protected]>
---
 lib/seq_buf.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
lib/seq_buf.c +4 -2
index 5c94e10..cb18469 100644
@@ -306,10 +306,12 @@ int seq_buf_to_user(struct seq_buf *s, char __user *ubuf, int cnt)
 	if (!cnt)
 		return 0;
 
-	if (s->len <= s->readpos)
+	len = seq_buf_used(s);
+
+	if (len <= s->readpos)
 		return -EBUSY;
 
-	len = seq_buf_used(s) - s->readpos;
+	len -= s->readpos;
 	if (cnt > len)
 		cnt = len;
 	ret = copy_to_user(ubuf, s->buffer + s->readpos, cnt);
Signature · 1 line
2.6.1
#1 lore raw
Quoted 10 lines · On Mon, 16 Nov 2015 12:57:28 -0700 Jerry Snitselaar <[email protected]> wrote:

commit 5ac48378414d ("tracing: Use trace_seq_used() and seq_buf_used() instead of len") changed the tracing code to use trace_seq_used() and seq_buf_used() instead of using the seq_buf len directly to avoid overflow issues, but missed a spot in seq_buf_to_user() that makes use of s->len.

Cleaned up the code a bit as well per suggestion of Steve Rostedt.

Cc "Steven Rostedt (Red Hat)" <[email protected]>

I finally got around to applying this. Thanks!

-- Steve

Quoted 23 lines
---
 lib/seq_buf.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
lib/seq_buf.c +4 -2
index 5c94e10..cb18469 100644
@@ -306,10 +306,12 @@ int seq_buf_to_user(struct seq_buf *s, char __user *ubuf, int cnt)
 	if (!cnt)
 		return 0;
 
-	if (s->len <= s->readpos)
+	len = seq_buf_used(s);
+
+	if (len <= s->readpos)
 		return -EBUSY;
 
-	len = seq_buf_used(s) - s->readpos;
+	len -= s->readpos;
 	if (cnt > len)
 		cnt = len;
 	ret = copy_to_user(ubuf, s->buffer + s->readpos, cnt);