From: Miklos Szeredi Date: Thu, 21 Jul 2016 20:30:58 +0000 (-0700) Subject: vfs: add vfs_select_inode() helper X-Git-Tag: v4.1.12-92~102^2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=5e9b8c2cf02bafdfe68ea971de0f5f37f7ced90a;p=users%2Fjedix%2Flinux-maple.git vfs: add vfs_select_inode() helper Signed-off-by: Miklos Szeredi Cc: # v4.2+ Orabug: 24363418 CVE:CVE-2016-6198,CVE-2016-6197 Based on mainline v4.6 commit 54d5ca871e72f2bb172ec9323497f01cd5091ec7 Conflicts: include/linux/dcache.h - code base Signed-off-by: Chuck Anderson --- diff --git a/fs/open.c b/fs/open.c index ff80b2542989..301c4a24c43f 100644 --- a/fs/open.c +++ b/fs/open.c @@ -832,16 +832,12 @@ EXPORT_SYMBOL(finish_no_open); int vfs_open(const struct path *path, struct file *file, const struct cred *cred) { - struct dentry *dentry = path->dentry; - struct inode *inode = dentry->d_inode; + struct inode *inode = vfs_select_inode(path->dentry, file->f_flags); - file->f_path = *path; - if (dentry->d_flags & DCACHE_OP_SELECT_INODE) { - inode = dentry->d_op->d_select_inode(dentry, file->f_flags); - if (IS_ERR(inode)) - return PTR_ERR(inode); - } + if (IS_ERR(inode)) + return PTR_ERR(inode); + file->f_path = *path; return do_dentry_open(file, inode, NULL, cred); } diff --git a/include/linux/dcache.h b/include/linux/dcache.h index ca9df4521734..2e4217570eb0 100644 --- a/include/linux/dcache.h +++ b/include/linux/dcache.h @@ -576,4 +576,16 @@ static inline struct dentry *d_backing_dentry(struct dentry *upper) return upper; } +static inline struct inode *vfs_select_inode(struct dentry *dentry, + unsigned open_flags) +{ + struct inode *inode = d_inode(dentry); + + if (inode && unlikely(dentry->d_flags & DCACHE_OP_SELECT_INODE)) + inode = dentry->d_op->d_select_inode(dentry, open_flags); + + return inode; +} + + #endif /* __LINUX_DCACHE_H */