ecryptfs_lookup_interpose(): lower_dentry->d_inode is not stable

lower_dentry can't go from positive to negative (we have it pinned),
but it *can* go from negative to positive. So fetching ->d_inode
into a local variable, doing a blocking allocation, checking that
now ->d_inode is non-NULL and feeding the value we'd fetched
earlier to a function that won't accept NULL is not a good idea.

Cc: stable@vger.kernel.org
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Al Viro e72b9dd6 bcf0d9d4

Changed files
+10 -2
fs
ecryptfs
+10 -2
fs/ecryptfs/inode.c
··· 319 319 static struct dentry *ecryptfs_lookup_interpose(struct dentry *dentry, 320 320 struct dentry *lower_dentry) 321 321 { 322 - struct inode *inode, *lower_inode = d_inode(lower_dentry); 322 + struct inode *inode, *lower_inode; 323 323 struct ecryptfs_dentry_info *dentry_info; 324 324 struct vfsmount *lower_mnt; 325 325 int rc = 0; ··· 339 339 dentry_info->lower_path.mnt = lower_mnt; 340 340 dentry_info->lower_path.dentry = lower_dentry; 341 341 342 - if (d_really_is_negative(lower_dentry)) { 342 + /* 343 + * negative dentry can go positive under us here - its parent is not 344 + * locked. That's OK and that could happen just as we return from 345 + * ecryptfs_lookup() anyway. Just need to be careful and fetch 346 + * ->d_inode only once - it's not stable here. 347 + */ 348 + lower_inode = READ_ONCE(lower_dentry->d_inode); 349 + 350 + if (!lower_inode) { 343 351 /* We want to add because we couldn't find in lower */ 344 352 d_add(dentry, NULL); 345 353 return NULL;