From: Slava Pestov Date: Wed, 24 Nov 2010 23:13:16 +0000 (-0800) Subject: tracing: Fix panic when lseek() called on "trace" opened for writing X-Git-Tag: v2.6.27.58~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ab42f1f2ba5bea8d266ed383438ad5652617b366;p=thirdparty%2Fkernel%2Fstable.git tracing: Fix panic when lseek() called on "trace" opened for writing 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 LKML-Reference: <1290640396-24179-1-git-send-email-slavapestov@google.com> Signed-off-by: Steven Rostedt Signed-off-by: Greg Kroah-Hartman [wt: applied to tracing_lt_fops too /wt] Signed-off-by: Willy Tarreau --- diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index dfe39952622bf..f937f5d719c73 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -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, };