]> git.hungrycats.org Git - linux/commitdiff
tracing: Fix panic when lseek() called on "trace" opened for writing
authorSlava Pestov <slavapestov@google.com>
Wed, 24 Nov 2010 23:13:16 +0000 (15:13 -0800)
committerWilly Tarreau <w@1wt.eu>
Wed, 9 Feb 2011 21:15:39 +0000 (22:15 +0100)
commit 364829b1263b44aa60383824e4c1289d83d78ca7 upstream.

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.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
[wt: applied to tracing_lt_fops too /wt]
Signed-off-by: Willy Tarreau <w@1wt.eu>
kernel/trace/trace.c

index dfe39952622bffcf6fc41c84e686bc0e3bc53997..f937f5d719c73a723eefb796a491d2834696fb39 100644 (file)
@@ -2041,17 +2041,25 @@ static int show_traces_open(struct inode *inode, struct file *file)
        return ret;
 }
 
+static loff_t tracing_seek(struct file *file, loff_t offset, int origin)
+{
+       if (file->f_mode & FMODE_READ)
+               return seq_lseek(file, offset, origin);
+       else
+               return 0;
+}
+
 static struct file_operations tracing_fops = {
        .open           = tracing_open,
        .read           = seq_read,
-       .llseek         = seq_lseek,
+       .llseek         = tracing_seek,
        .release        = tracing_release,
 };
 
 static struct file_operations tracing_lt_fops = {
        .open           = tracing_lt_open,
        .read           = seq_read,
-       .llseek         = seq_lseek,
+       .llseek         = tracing_seek,
        .release        = tracing_release,
 };