linux/fs
Miklos Szeredi 1ce88cf466 [PATCH] namespace.c: fix race in mark_mounts_for_expiry()
This patch fixes a race found by Ram in mark_mounts_for_expiry() in
fs/namespace.c.

The bug can only be triggered with simultaneous exiting of a process having
a private namespace, and expiry of a mount from within that namespace.
It's practically impossible to trigger, and I haven't even tried.  But
still, a bug is a bug.

The race happens when put_namespace() is called by another task, while
mark_mounts_for_expiry() is between atomic_read() and get_namespace().  In
that case get_namespace() will be called on an already dead namespace with
unforeseeable results.

The solution was suggested by Al Viro, with his own words:

      Instead of screwing with atomic_read() in there, why don't we
      simply do the following:
      	a) atomic_dec_and_lock() in put_namespace()
      	b) __put_namespace() called without dropping lock
      	c) the first thing done by __put_namespace would be
      struct vfsmount *root = namespace->root;
      namespace->root = NULL;
      spin_unlock(...);
      ....
      umount_tree(root);
      ...
      	d) check in mark_... would be simply namespace && namespace->root.

      And we are all set; no screwing around with atomic_read(), no magic
      at all.  Dying namespace gets NULL ->root.
      All changes of ->root happen under spinlock.
      If under a spinlock we see non-NULL ->mnt_namespace, it won't be
      freed until we drop the lock (we will set ->mnt_namespace to NULL
      under that lock before we get to freeing namespace).
      If under a spinlock we see non-NULL ->mnt_namespace and
      ->mnt_namespace->root, we can grab a reference to namespace and be
      sure that it won't go away.

Signed-off-by: Miklos Szeredi <miklos@szeredi.hu>
Acked-by: Al Viro <viro@parcelfarce.linux.theplanet.co.uk>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-07-07 18:23:51 -07:00
..
adfs
affs
afs [PATCH] Cleanup patch for process freezing 2005-06-25 17:10:13 -07:00
autofs
autofs4 [PATCH] autofs4: mistake in debug print 2005-07-07 18:23:46 -07:00
befs
bfs
cifs
coda
cramfs
debugfs [PATCH] remove duplicate get_dentry functions in various places 2005-06-23 09:45:20 -07:00
devfs
devpts
efs
exportfs
ext2 [PATCH] xip: reduce code duplication 2005-06-24 00:06:41 -07:00
ext3 [PATCH] ext3 xattr: Don't write to the in-inode xattr space of reserved inodes 2005-07-07 18:23:46 -07:00
fat [PATCH] fatfs sectioning fix 2005-06-30 22:29:48 -07:00
freevxfs [PATCH] freevxfs: minor cleanups 2005-06-30 08:45:12 -07:00
hfs
hfsplus
hostfs
hpfs
hppfs [PATCH] uml: restore hppfs support 2005-07-07 18:23:44 -07:00
hugetlbfs
isofs
jbd [PATCH] Cleanup patch for process freezing 2005-06-25 17:10:13 -07:00
jffs [PATCH] fs/jffs/: cleanups 2005-06-25 16:25:04 -07:00
jffs2 [PATCH] jffs2 build fix 2005-06-26 08:43:19 -07:00
jfs [PATCH] Cleanup patch for process freezing 2005-06-25 17:10:13 -07:00
lockd [PATCH] Cleanup patch for process freezing 2005-06-25 17:10:13 -07:00
minix
msdos
ncpfs [PATCH] fs/ncpfs/: remove unused #ifdef USE_OLD_SLOW_DIRECTORY_LISTING code 2005-06-25 16:25:04 -07:00
nfs [PATCH] really remove xattr_acl.h 2005-06-28 21:20:31 -07:00
nfs_common [PATCH] NFSD: Add server support for NFSv3 ACLs. 2005-06-22 16:07:23 -04:00
nfsd [PATCH] really remove xattr_acl.h 2005-06-28 21:20:31 -07:00
nls
ntfs
openpromfs
partitions [PATCH] small partitions/msdos cleanups 2005-06-25 16:24:59 -07:00
proc [PATCH] kdump: Parse elf32 headers and export through /proc/vmcore 2005-06-25 16:24:53 -07:00
qnx4 [PATCH] fs/qnx4/*: fix sparse warnings 2005-06-24 14:14:24 -07:00
ramfs
reiserfs [PATCH] reiserfs: handle_attrs() fix 2005-06-30 08:45:13 -07:00
romfs
smbfs
sysfs [PATCH] DocBook: update comments 2005-06-24 00:06:40 -07:00
sysv
udf [PATCH] udf_find_entry() cleanup 2005-06-30 08:45:11 -07:00
ufs
umsdos
vfat
xfs [PATCH] Cleanup patch for process freezing 2005-06-25 17:10:13 -07:00
Kconfig [PATCH] acl kconfig cleanup 2005-07-07 18:23:45 -07:00
Kconfig.binfmt
Makefile [PATCH] Update cfq io scheduler to time sliced design 2005-06-27 14:33:29 -07:00
aio.c [PATCH] aio-retry-fix: fix aio retry work queueing 2005-06-28 21:20:32 -07:00
attr.c
bad_inode.c
binfmt_aout.c
binfmt_elf.c
binfmt_elf_fdpic.c
binfmt_em86.c
binfmt_flat.c
binfmt_misc.c
binfmt_script.c
binfmt_som.c
bio.c [PATCH] mostly_read data section 2005-07-07 18:23:46 -07:00
block_dev.c [PATCH] block: add unlocked_ioctl support for block devices 2005-06-23 09:45:32 -07:00
buffer.c [PATCH] page_uptodate locking scalability 2005-07-07 18:23:45 -07:00
char_dev.c [PATCH] fix semaphore handling in __unregister_chrdev_region 2005-06-28 21:20:29 -07:00
compat.c
compat_ioctl.c
dcache.c
dcookies.c
direct-io.c [PATCH] pass iocb to dio_iodone_t 2005-06-24 00:05:19 -07:00
dnotify.c
dquot.c [PATCH] list_for_each_entry: fs-dquot.c 2005-06-25 16:25:11 -07:00
eventpoll.c [PATCH] Remove eventpoll macro obfuscation 2005-06-23 09:45:30 -07:00
exec.c [PATCH] setuid core dump 2005-06-23 09:45:26 -07:00
fcntl.c
fifo.c
file.c
file_table.c [PATCH] Fix of bogus file max limit messages 2005-06-23 09:45:26 -07:00
filesystems.c
fs-writeback.c [PATCH] O(1) sb list traversing on syncs 2005-06-23 09:45:27 -07:00
inode.c [PATCH] export generic_drop_inode() to modules 2005-07-07 18:23:35 -07:00
ioctl.c
ioprio.c [PATCH] move ioprio syscalls into syscalls.h 2005-07-07 18:23:37 -07:00
libfs.c [PATCH] fix fsync(dir) return value for ram-based filesystems 2005-06-25 16:24:38 -07:00
locks.c [PATCH] coverity: fs/locks.c flp null check 2005-07-07 18:23:47 -07:00
mbcache.c
mpage.c
namei.c [PATCH] add some comments to lookup_create() 2005-06-23 09:45:26 -07:00
namespace.c [PATCH] namespace.c: fix race in mark_mounts_for_expiry() 2005-07-07 18:23:51 -07:00
nfsctl.c
open.c [PATCH] xip: fs/mm: execute in place 2005-06-24 00:06:41 -07:00
pipe.c
posix_acl.c
quota.c [PATCH] O(1) sb list traversing on syncs 2005-06-23 09:45:27 -07:00
quota_v1.c
quota_v2.c
read_write.c [PATCH] aio: fix do_sync_(read|write) to properly handle aio retries 2005-06-23 09:45:34 -07:00
readdir.c
select.c
seq_file.c
stat.c
super.c [PATCH] O(1) sb list traversing on syncs 2005-06-23 09:45:27 -07:00
xattr.c
xattr_acl.c