<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux/fs/sysfs/dir.c, branch v3.4.83</title>
<subtitle>Linux kernel source tree</subtitle>
<id>https://git.amat.us/linux/atom/fs/sysfs/dir.c?h=v3.4.83</id>
<link rel='self' href='https://git.amat.us/linux/atom/fs/sysfs/dir.c?h=v3.4.83'/>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/'/>
<updated>2013-05-08T02:51:54Z</updated>
<entry>
<title>sysfs: fix use after free in case of concurrent read/write and readdir</title>
<updated>2013-05-08T02:51:54Z</updated>
<author>
<name>Ming Lei</name>
<email>ming.lei@canonical.com</email>
</author>
<published>2013-04-02T02:12:26Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=6615e6db12bf29ab3d1062c9144c4e0828d2c588'/>
<id>urn:sha1:6615e6db12bf29ab3d1062c9144c4e0828d2c588</id>
<content type='text'>
commit f7db5e7660b122142410dcf36ba903c73d473250 upstream.

The inode-&gt;i_mutex isn't hold when updating filp-&gt;f_pos
in read()/write(), so the filp-&gt;f_pos might be read as
0 or 1 in readdir() when there is concurrent read()/write()
on this same file, then may cause use after free in readdir().

The bug can be reproduced with Li Zefan's test code on the
link:

	https://patchwork.kernel.org/patch/2160771/

This patch fixes the use after free under this situation.

Reported-by: Li Zefan &lt;lizefan@huawei.com&gt;
Signed-off-by: Ming Lei &lt;ming.lei@canonical.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
</entry>
<entry>
<title>sysfs: handle failure path correctly for readdir()</title>
<updated>2013-04-05T17:04:16Z</updated>
<author>
<name>Ming Lei</name>
<email>ming.lei@canonical.com</email>
</author>
<published>2013-03-20T15:25:25Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=cde9833c97c4ad06e569e1f0e7e6b1c84c948aa3'/>
<id>urn:sha1:cde9833c97c4ad06e569e1f0e7e6b1c84c948aa3</id>
<content type='text'>
commit e5110f411d2ee35bf8d202ccca2e89c633060dca upstream.

In case of 'if (filp-&gt;f_pos ==  0 or 1)' of sysfs_readdir(),
the failure from filldir() isn't handled, and the reference counter
of the sysfs_dirent object pointed by filp-&gt;private_data will be
released without clearing filp-&gt;private_data, so use after free
bug will be triggered later.

This patch returns immeadiately under the situation for fixing the bug,
and it is reasonable to return from readdir() when filldir() fails.

Reported-by: Dave Jones &lt;davej@redhat.com&gt;
Tested-by: Sasha Levin &lt;levinsasha928@gmail.com&gt;
Signed-off-by: Ming Lei &lt;ming.lei@canonical.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
</entry>
<entry>
<title>sysfs: fix race between readdir and lseek</title>
<updated>2013-04-05T17:04:16Z</updated>
<author>
<name>Ming Lei</name>
<email>ming.lei@canonical.com</email>
</author>
<published>2013-03-20T15:25:24Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=01fadbb46b6da196c594ac2266674136cda465a6'/>
<id>urn:sha1:01fadbb46b6da196c594ac2266674136cda465a6</id>
<content type='text'>
commit 991f76f837bf22c5bb07261cfd86525a0a96650c upstream.

While readdir() is running, lseek() may set filp-&gt;f_pos as zero,
then may leave filp-&gt;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-&gt;i_mutex to avoid the problem since
the lock is always held in readdir path.

Reported-by: Dave Jones &lt;davej@redhat.com&gt;
Tested-by: Sasha Levin &lt;levinsasha928@gmail.com&gt;
Signed-off-by: Ming Lei &lt;ming.lei@canonical.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
</entry>
<entry>
<title>sysfs: sysfs_pathname/sysfs_add_one: Use strlcat() instead of strcat()</title>
<updated>2012-10-31T17:02:57Z</updated>
<author>
<name>Geert Uytterhoeven</name>
<email>geert@linux-m68k.org</email>
</author>
<published>2012-09-29T20:23:19Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=fa3b39b05f40bf7273bcd6c152f0b59005b83480'/>
<id>urn:sha1:fa3b39b05f40bf7273bcd6c152f0b59005b83480</id>
<content type='text'>
commit 66081a72517a131430dcf986775f3268aafcb546 upstream.

The warning check for duplicate sysfs entries can cause a buffer overflow
when printing the warning, as strcat() doesn't check buffer sizes.
Use strlcat() instead.

Since strlcat() doesn't return a pointer to the passed buffer, unlike
strcat(), I had to convert the nested concatenation in sysfs_add_one() to
an admittedly more obscure comma operator construct, to avoid emitting code
for the concatenation if CONFIG_BUG is disabled.

Signed-off-by: Geert Uytterhoeven &lt;geert@linux-m68k.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
</entry>
<entry>
<title>sysfs: handle 'parent deleted before child added'</title>
<updated>2012-04-10T21:48:51Z</updated>
<author>
<name>Dan Williams</name>
<email>dan.j.williams@intel.com</email>
</author>
<published>2012-04-06T20:41:06Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=3a198886ab5f228fcbebb9ace803d8b99721d49a'/>
<id>urn:sha1:3a198886ab5f228fcbebb9ace803d8b99721d49a</id>
<content type='text'>
In scsi at least two cases of the parent device being deleted before the
child is added have been observed.

1/ scsi is performing async scans and the device is removed prior to the
   async can thread running (can happen with an in-opportune / unlikely
   unplug during initial scan).

2/ libsas discovery event running after the parent port has been torn
   down (this is a bug in libsas).

Result in crash signatures like:
 BUG: unable to handle kernel NULL pointer dereference at 0000000000000098
 IP: [&lt;ffffffff8115e100&gt;] sysfs_create_dir+0x32/0xb6
 ...
 Process scsi_scan_8 (pid: 5417, threadinfo ffff88080bd16000, task ffff880801b8a0b0)
 Stack:
  00000000fffffffe ffff880813470628 ffff88080bd17cd0 ffff88080614b7e8
  ffff88080b45c108 00000000fffffffe ffff88080bd17d20 ffffffff8125e4a8
  ffff88080bd17cf0 ffffffff81075149 ffff88080bd17d30 ffff88080614b7e8
 Call Trace:
  [&lt;ffffffff8125e4a8&gt;] kobject_add_internal+0x120/0x1e3
  [&lt;ffffffff81075149&gt;] ? trace_hardirqs_on+0xd/0xf
  [&lt;ffffffff8125e641&gt;] kobject_add_varg+0x41/0x50
  [&lt;ffffffff8125e70b&gt;] kobject_add+0x64/0x66
  [&lt;ffffffff8131122b&gt;] device_add+0x12d/0x63a

In this scenario the parent is still valid (because we have a
reference), but it has been device_del()'d which means its kobj-&gt;sd
pointer is NULL'd via:

 device_del()-&gt;kobject_del()-&gt;sysfs_remove_dir()

...and then sysfs_create_dir() (without this fix) goes ahead and
de-references parent_sd via sysfs_ns_type():

 return (sd-&gt;s_flags &amp; SYSFS_NS_TYPE_MASK) &gt;&gt; SYSFS_NS_TYPE_SHIFT;

This scenario is being fixed in scsi/libsas, but if other subsystems
present the same ordering the system need not immediately crash.

Cc: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
Cc: James Bottomley &lt;JBottomley@parallels.com&gt;
Signed-off-by: Dan Williams &lt;dan.j.williams@intel.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>sysfs: Update the name hash for an entry after changing the namespace</title>
<updated>2012-04-09T22:33:00Z</updated>
<author>
<name>Tom Goff</name>
<email>thomas.goff@boeing.com</email>
</author>
<published>2012-04-04T19:06:20Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=70fa4a62e913dde2d100e0be2711562742f58bee'/>
<id>urn:sha1:70fa4a62e913dde2d100e0be2711562742f58bee</id>
<content type='text'>
This is needed to allow renaming network devices that have been moved
to another network namespace.

Signed-off-by: Tom Goff &lt;thomas.goff@boeing.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>Revert "sysfs: Kill nlink counting."</title>
<updated>2012-03-08T21:03:10Z</updated>
<author>
<name>Greg Kroah-Hartman</name>
<email>gregkh@linuxfoundation.org</email>
</author>
<published>2012-03-08T21:03:10Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=54d20f006ceff1f2f1e69d0e54049b6c0765c039'/>
<id>urn:sha1:54d20f006ceff1f2f1e69d0e54049b6c0765c039</id>
<content type='text'>
This reverts commit 524b6c5b39b931311dfe5a2f5abae2f5c9731676.

It has shown to break userspace tools, which is not acceptable.

Reported-by: Jiri Slaby &lt;jslaby@suse.cz&gt;
Cc: Eric W. Biederman &lt;ebiederm@xmission.com&gt;
Cc: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>sysfs: Update the name hash when renaming sysfs entries</title>
<updated>2012-01-31T19:30:48Z</updated>
<author>
<name>Eric W. Biederman</name>
<email>ebiederm@xmission.com</email>
</author>
<published>2012-01-31T14:40:26Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=d5c38b137ac8a6e3dbed13bc494d60df5b69dfc4'/>
<id>urn:sha1:d5c38b137ac8a6e3dbed13bc494d60df5b69dfc4</id>
<content type='text'>
This fixes a bug introduced with sysfs name hashes where renaming a
network device appears to succeed but silently makes the sysfs files for
that network device inaccessible.

In at least one configuration this bug has stopped networking from
coming up during boot.

Signed-off-by: Eric W. Biederman &lt;ebiederm@xmission.com&gt;
Tested-by: Jiri Slaby &lt;jslaby@suse.cz&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@suse.de&gt;
</content>
</entry>
<entry>
<title>sysfs: Kill nlink counting.</title>
<updated>2012-01-24T20:41:46Z</updated>
<author>
<name>Eric W. Biederman</name>
<email>ebiederm@xmission.com</email>
</author>
<published>2011-12-19T04:09:31Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=524b6c5b39b931311dfe5a2f5abae2f5c9731676'/>
<id>urn:sha1:524b6c5b39b931311dfe5a2f5abae2f5c9731676</id>
<content type='text'>
Tracking the number of subdirectories requires an extra field that increases
the size of sysfs_dirent.  nlinks are not particularly interesting for sysfs
and the nlink counts are wrong when network namespaces are involved so stop
counting them, and always return nlink == 1.  Userspace already knows that
directories with nlink == 1 have an nlink count they can't use to count
subdirectories.

This reduces the size of sysfs_dirent by 8 bytes on 64bit platforms.

Signed-off-by: Eric W. Biederman &lt;ebiederm@xmission.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@suse.de&gt;
</content>
</entry>
<entry>
<title>sysfs: Store the sysfs inode in an unsigned int.</title>
<updated>2012-01-24T20:41:46Z</updated>
<author>
<name>Eric W. Biederman</name>
<email>ebiederm@xmission.com</email>
</author>
<published>2011-12-19T04:08:16Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=cafa6b5dd7ce4f0e0a30be301be4efed587a7808'/>
<id>urn:sha1:cafa6b5dd7ce4f0e0a30be301be4efed587a7808</id>
<content type='text'>
Store the sysfs inode number in an unsided int because
ida inode allocator can return at most a 31 bit number,
reducing the size of struct sysfs_dirent by 8 bytes
on 64bit platforms.

Signed-off-by: Eric W. Biederman &lt;ebiederm@xmission.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@suse.de&gt;
</content>
</entry>
</feed>
