Subject: Re: [BUG -next] sysfs change breaks userspace

From: Tejun Heo <[email-masked]>
Date: Fri, 1 Nov 2013 10:35:42 -0400

Hello, Heiko.

On Fri, Nov 01, 2013 at 03:13:48PM +0100, Heiko Carstens wrote:
> before your patch it was like this:
> 
> [pid  2888] open("/sys/class/net/eth0/broadcast", O_RDONLY) = 5
> [pid  2888] lseek(5, 0, SEEK_END)       = 4096
> [pid  2888] lseek(5, 0, SEEK_SET)       = 0
> [pid  2888] read(5, "ff:ff:ff:ff:ff:ff\n", 4096) = 18
> [pid  2888] close(5)                    = 0
> 
> With your patch applied I get this:
> 
> [pid  2450] open("/sys/class/net/eth0/broadcast", O_RDONLY) = 5
> [pid  2450] lseek(5, 0, SEEK_END)       = -1 EINVAL (Invalid argument)
> [pid  2450] lseek(5, 0, SEEK_SET)       = 0
> [pid  2450] read(5, 0x557421e8, 4294967295) = -1 EINVAL (Invalid argument)
> [pid  2450] close(5)                    = 0
> 
> So the problem is that lseek with SEEK_END doesn't work.
> Afterwards the process tried to use the return value of lseek as number of
> bytes to be read, which doesn't work ;)
> 
> This is a Fedora 17 like system on s390. It's a bit special since the kernel
> is 64 bit and whole user space is 32 bit.

LOL, that's creative.  I guess we'll have to give up using
seq_lseek().  Can you please test the following?

Thanks.

diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index 382db3c..79b5da2 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -800,7 +800,7 @@ EXPORT_SYMBOL_GPL(sysfs_notify);
 const struct file_operations sysfs_file_operations = {
 	.read		= seq_read,
 	.write		= sysfs_write_file,
-	.llseek		= seq_lseek,
+	.llseek		= generic_file_llseek,
 	.open		= sysfs_open_file,
 	.release	= sysfs_release,
 	.poll		= sysfs_poll,

-- 
tejun