Re: [PATCH 1/2] sysfs: fix race between readdir and lseek

2013-03-26 Thread Ming Lei
On Tue, Mar 26, 2013 at 10:03 PM, Ming Lei wrote: > > If you mean the test code on link[1], I can't reproduce the > warning with the two sysfs fix patches in 4 hours's test. > > [1], https://patchwork.kernel.org/patch/2160771/ You are right, looks it is not a problem just in theory, and I can rep

Re: [PATCH 1/2] sysfs: fix race between readdir and lseek

2013-03-26 Thread Ming Lei
Hi Zefan, On Tue, Mar 26, 2013 at 4:45 PM, Ming Lei wrote: > On Tue, Mar 26, 2013 at 3:30 PM, Li Zefan wrote: >>> Considered that vfs_read()/vfs_write on sysfs dir is almost doing nothing, >>> the >>> above problem may only exist in theory. >> >> The read() vs readdir() race in sysfs directory

Re: [PATCH 1/2] sysfs: fix race between readdir and lseek

2013-03-26 Thread Ming Lei
On Tue, Mar 26, 2013 at 3:30 PM, Li Zefan wrote: >> Considered that vfs_read()/vfs_write on sysfs dir is almost doing nothing, >> the >> above problem may only exist in theory. > > The read() vs readdir() race in sysfs directory doesn't exist in theory only. Could you let me know if you have app

Re: [PATCH 1/2] sysfs: fix race between readdir and lseek

2013-03-26 Thread Li Zefan
On 2013/3/22 17:31, Ming Lei wrote: > On Fri, Mar 22, 2013 at 1:48 PM, Li Zefan wrote: >> On 2013/3/21 12:48, Ming Lei wrote: >> >> Yes, it can...As I said, it's irrelevant, because it's vfs that changes >> file->f_pos. >> >> SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, coun

Re: [PATCH 1/2] sysfs: fix race between readdir and lseek

2013-03-22 Thread Ming Lei
On Fri, Mar 22, 2013 at 1:48 PM, Li Zefan wrote: > On 2013/3/21 12:48, Ming Lei wrote: > > Yes, it can...As I said, it's irrelevant, because it's vfs that changes > file->f_pos. > > SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count) > { > struct fd f = fdget(fd); >

Re: [PATCH 1/2] sysfs: fix race between readdir and lseek

2013-03-21 Thread Li Zefan
On 2013/3/21 12:48, Ming Lei wrote: > On Thu, Mar 21, 2013 at 11:28 AM, Li Zefan wrote: >> On 2013/3/21 11:17, Ming Lei wrote: >>> On Thu, Mar 21, 2013 at 10:41 AM, Li Zefan wrote: In fact the same race exists between readdir() and read()/write()... >>> >>> Fortunately, no read()/write(

Re: [PATCH 1/2] sysfs: fix race between readdir and lseek

2013-03-20 Thread Ming Lei
On Thu, Mar 21, 2013 at 11:28 AM, Li Zefan wrote: > On 2013/3/21 11:17, Ming Lei wrote: >> On Thu, Mar 21, 2013 at 10:41 AM, Li Zefan wrote: >>> >>> In fact the same race exists between readdir() and read()/write()... >> >> Fortunately, no read()/write() are implemented on sysfs directory, :-) >>

Re: [PATCH 1/2] sysfs: fix race between readdir and lseek

2013-03-20 Thread Li Zefan
On 2013/3/21 11:17, Ming Lei wrote: > On Thu, Mar 21, 2013 at 10:41 AM, Li Zefan wrote: >> >> In fact the same race exists between readdir() and read()/write()... > > Fortunately, no read()/write() are implemented on sysfs directory, :-) > That's irrelevant... See my report: https://patchwork

Re: [PATCH 1/2] sysfs: fix race between readdir and lseek

2013-03-20 Thread Ming Lei
On Thu, Mar 21, 2013 at 10:41 AM, Li Zefan wrote: > > In fact the same race exists between readdir() and read()/write()... Fortunately, no read()/write() are implemented on sysfs directory, :-) Thanks, -- Ming Lei -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the

Re: [PATCH 1/2] sysfs: fix race between readdir and lseek

2013-03-20 Thread Li Zefan
On 2013/3/20 23:25, Ming Lei wrote: > While readdir() is running, lseek() may set filp->f_pos as zero, > then may leave filp->private_data pointing to one sysfs_dirent > object without holding its reference counter, so the sysfs_dirent > object may be used after free in next readdir(). > > This pa

[PATCH 1/2] sysfs: fix race between readdir and lseek

2013-03-20 Thread Ming Lei
While readdir() is running, lseek() may set filp->f_pos as zero, then may leave filp->private_data pointing to one sysfs_dirent object without holding its reference counter, so the sysfs_dirent object may be used after free in next readdir(). This patch holds inode->i_mutex to avoid the problem si