diff options
author | Slava Pestov <slavapestov@google.com> | 2010-11-24 18:13:16 -0500 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2010-11-30 12:18:17 -0500 |
commit | 364829b1263b44aa60383824e4c1289d83d78ca7 (patch) | |
tree | daaaf4cecd56ff9f3f9a2eadc69d0cc4f361c607 /kernel | |
parent | 60e677373be9c0bf7c9a22937601d5a40e51c042 (diff) |
tracing: Fix panic when lseek() called on "trace" opened for writing
The file_ops struct for the "trace" special file defined llseek as seq_lseek().
However, if the file was opened for writing only, seq_open() was not called,
and the seek would dereference a null pointer, file->private_data.
This patch introduces a new wrapper for seq_lseek() which checks if the file
descriptor is opened for reading first. If not, it does nothing.
Cc: <stable@kernel.org>
Signed-off-by: Slava Pestov <slavapestov@google.com>
LKML-Reference: <1290640396-24179-1-git-send-email-slavapestov@google.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/trace/trace.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index ee6a7339cf0e..21db0deb5c7d 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c | |||
@@ -2339,11 +2339,19 @@ tracing_write_stub(struct file *filp, const char __user *ubuf, | |||
2339 | return count; | 2339 | return count; |
2340 | } | 2340 | } |
2341 | 2341 | ||
2342 | static loff_t tracing_seek(struct file *file, loff_t offset, int origin) | ||
2343 | { | ||
2344 | if (file->f_mode & FMODE_READ) | ||
2345 | return seq_lseek(file, offset, origin); | ||
2346 | else | ||
2347 | return 0; | ||
2348 | } | ||
2349 | |||
2342 | static const struct file_operations tracing_fops = { | 2350 | static const struct file_operations tracing_fops = { |
2343 | .open = tracing_open, | 2351 | .open = tracing_open, |
2344 | .read = seq_read, | 2352 | .read = seq_read, |
2345 | .write = tracing_write_stub, | 2353 | .write = tracing_write_stub, |
2346 | .llseek = seq_lseek, | 2354 | .llseek = tracing_seek, |
2347 | .release = tracing_release, | 2355 | .release = tracing_release, |
2348 | }; | 2356 | }; |
2349 | 2357 | ||