kernfs: protect lazy kernfs_iattrs allocation with mutex
authorTejun Heo <tj@kernel.org>
Wed, 2 Apr 2014 20:40:52 +0000 (16:40 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 27 Apr 2014 00:19:04 +0000 (17:19 -0700)
commit29b311867df2f1f7aee9ec42517becbbb4aeeeef
tree17533985d5559d114b9e3fb31163887c64caa6ff
parent52d6c48c9db5b020e6595067a7f1b00562d26434
kernfs: protect lazy kernfs_iattrs allocation with mutex

commit 4afddd60a770560d370d6f85c5aef57c16bf7502 upstream.

kernfs_iattrs is allocated lazily when operations which require it
take place; unfortunately, the lazy allocation and returning weren't
properly synchronized and when there are multiple concurrent
operations, it might end up returning kernfs_iattrs which hasn't
finished initialization yet or different copies to different callers.

Fix it by synchronizing with a mutex.  This can be smarter with memory
barriers but let's go there if it actually turns out to be necessary.

Signed-off-by: Tejun Heo <tj@kernel.org>
Link: http://lkml.kernel.org/g/533ABA32.9080602@oracle.com
Reported-by: Sasha Levin <sasha.levin@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/kernfs/inode.c