diff options
author | Steven Rostedt (Red Hat) <rostedt@goodmis.org> | 2014-11-14 15:49:41 -0500 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2014-11-19 22:01:15 -0500 |
commit | 5ac48378414dccca735897c4d7f4e19987c8977c (patch) | |
tree | 9cf5c11dddd8081327d7e7f8a68a9e47613adcfa /include/linux/trace_seq.h | |
parent | 74f06bb72347302a19aac087314388ebd0e4fee9 (diff) |
tracing: Use trace_seq_used() and seq_buf_used() instead of len
As the seq_buf->len will soon be +1 size when there's an overflow, we
must use trace_seq_used() or seq_buf_used() methods to get the real
length. This will prevent buffer overflow issues if just the len
of the seq_buf descriptor is used to copy memory.
Link: http://lkml.kernel.org/r/20141114121911.09ba3d38@gandalf.local.home
Reported-by: Petr Mladek <pmladek@suse.cz>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'include/linux/trace_seq.h')
-rw-r--r-- | include/linux/trace_seq.h | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/include/linux/trace_seq.h b/include/linux/trace_seq.h index 85d37106be3d..cfaf5a1d4bad 100644 --- a/include/linux/trace_seq.h +++ b/include/linux/trace_seq.h | |||
@@ -24,6 +24,24 @@ trace_seq_init(struct trace_seq *s) | |||
24 | } | 24 | } |
25 | 25 | ||
26 | /** | 26 | /** |
27 | * trace_seq_used - amount of actual data written to buffer | ||
28 | * @s: trace sequence descriptor | ||
29 | * | ||
30 | * Returns the amount of data written to the buffer. | ||
31 | * | ||
32 | * IMPORTANT! | ||
33 | * | ||
34 | * Use this instead of @s->seq.len if you need to pass the amount | ||
35 | * of data from the buffer to another buffer (userspace, or what not). | ||
36 | * The @s->seq.len on overflow is bigger than the buffer size and | ||
37 | * using it can cause access to undefined memory. | ||
38 | */ | ||
39 | static inline int trace_seq_used(struct trace_seq *s) | ||
40 | { | ||
41 | return seq_buf_used(&s->seq); | ||
42 | } | ||
43 | |||
44 | /** | ||
27 | * trace_seq_buffer_ptr - return pointer to next location in buffer | 45 | * trace_seq_buffer_ptr - return pointer to next location in buffer |
28 | * @s: trace sequence descriptor | 46 | * @s: trace sequence descriptor |
29 | * | 47 | * |
@@ -35,7 +53,7 @@ trace_seq_init(struct trace_seq *s) | |||
35 | static inline unsigned char * | 53 | static inline unsigned char * |
36 | trace_seq_buffer_ptr(struct trace_seq *s) | 54 | trace_seq_buffer_ptr(struct trace_seq *s) |
37 | { | 55 | { |
38 | return s->buffer + s->seq.len; | 56 | return s->buffer + seq_buf_used(&s->seq); |
39 | } | 57 | } |
40 | 58 | ||
41 | /** | 59 | /** |