@@ -1487,11 +1487,13 @@ static int path_init(int dfd, const char *name, unsigned int flags,
14871487 nd -> depth = 0 ;
14881488 if (flags & LOOKUP_ROOT ) {
14891489 struct inode * inode = nd -> root .dentry -> d_inode ;
1490- if (!inode -> i_op -> lookup )
1491- return - ENOTDIR ;
1492- retval = inode_permission (inode , MAY_EXEC );
1493- if (retval )
1494- return retval ;
1490+ if (* name ) {
1491+ if (!inode -> i_op -> lookup )
1492+ return - ENOTDIR ;
1493+ retval = inode_permission (inode , MAY_EXEC );
1494+ if (retval )
1495+ return retval ;
1496+ }
14951497 nd -> path = nd -> root ;
14961498 nd -> inode = inode ;
14971499 if (flags & LOOKUP_RCU ) {
@@ -1937,7 +1939,7 @@ int vfs_create(struct inode *dir, struct dentry *dentry, int mode,
19371939 return error ;
19381940}
19391941
1940- int may_open (struct path * path , int acc_mode , int flag )
1942+ static int may_open (struct path * path , int acc_mode , int flag )
19411943{
19421944 struct dentry * dentry = path -> dentry ;
19431945 struct inode * inode = dentry -> d_inode ;
@@ -2250,11 +2252,10 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
22502252}
22512253
22522254static struct file * path_openat (int dfd , const char * pathname ,
2253- const struct open_flags * op , int flags )
2255+ struct nameidata * nd , const struct open_flags * op , int flags )
22542256{
22552257 struct file * base = NULL ;
22562258 struct file * filp ;
2257- struct nameidata nd ;
22582259 struct path path ;
22592260 int count = 0 ;
22602261 int error ;
@@ -2264,27 +2265,27 @@ static struct file *path_openat(int dfd, const char *pathname,
22642265 return ERR_PTR (- ENFILE );
22652266
22662267 filp -> f_flags = op -> open_flag ;
2267- nd . intent .open .file = filp ;
2268- nd . intent .open .flags = open_to_namei_flags (op -> open_flag );
2269- nd . intent .open .create_mode = op -> mode ;
2268+ nd -> intent .open .file = filp ;
2269+ nd -> intent .open .flags = open_to_namei_flags (op -> open_flag );
2270+ nd -> intent .open .create_mode = op -> mode ;
22702271
2271- error = path_init (dfd , pathname , flags | LOOKUP_PARENT , & nd , & base );
2272+ error = path_init (dfd , pathname , flags | LOOKUP_PARENT , nd , & base );
22722273 if (unlikely (error ))
22732274 goto out_filp ;
22742275
22752276 current -> total_link_count = 0 ;
2276- error = link_path_walk (pathname , & nd );
2277+ error = link_path_walk (pathname , nd );
22772278 if (unlikely (error ))
22782279 goto out_filp ;
22792280
2280- filp = do_last (& nd , & path , op , pathname );
2281+ filp = do_last (nd , & path , op , pathname );
22812282 while (unlikely (!filp )) { /* trailing symlink */
22822283 struct path link = path ;
22832284 struct inode * linki = link .dentry -> d_inode ;
22842285 void * cookie ;
2285- if (!(nd . flags & LOOKUP_FOLLOW ) || count ++ == 32 ) {
2286- path_put_conditional (& path , & nd );
2287- path_put (& nd . path );
2286+ if (!(nd -> flags & LOOKUP_FOLLOW ) || count ++ == 32 ) {
2287+ path_put_conditional (& path , nd );
2288+ path_put (& nd -> path );
22882289 filp = ERR_PTR (- ELOOP );
22892290 break ;
22902291 }
@@ -2299,23 +2300,23 @@ static struct file *path_openat(int dfd, const char *pathname,
22992300 * have to putname() it when we are done. Procfs-like symlinks
23002301 * just set LAST_BIND.
23012302 */
2302- nd . flags |= LOOKUP_PARENT ;
2303- nd . flags &= ~(LOOKUP_OPEN |LOOKUP_CREATE |LOOKUP_EXCL );
2304- error = __do_follow_link (& link , & nd , & cookie );
2303+ nd -> flags |= LOOKUP_PARENT ;
2304+ nd -> flags &= ~(LOOKUP_OPEN |LOOKUP_CREATE |LOOKUP_EXCL );
2305+ error = __do_follow_link (& link , nd , & cookie );
23052306 if (unlikely (error ))
23062307 filp = ERR_PTR (error );
23072308 else
2308- filp = do_last (& nd , & path , op , pathname );
2309+ filp = do_last (nd , & path , op , pathname );
23092310 if (!IS_ERR (cookie ) && linki -> i_op -> put_link )
2310- linki -> i_op -> put_link (link .dentry , & nd , cookie );
2311+ linki -> i_op -> put_link (link .dentry , nd , cookie );
23112312 path_put (& link );
23122313 }
23132314out :
2314- if (nd . root .mnt && !(nd . flags & LOOKUP_ROOT ))
2315- path_put (& nd . root );
2315+ if (nd -> root .mnt && !(nd -> flags & LOOKUP_ROOT ))
2316+ path_put (& nd -> root );
23162317 if (base )
23172318 fput (base );
2318- release_open_intent (& nd );
2319+ release_open_intent (nd );
23192320 return filp ;
23202321
23212322out_filp :
@@ -2326,16 +2327,39 @@ static struct file *path_openat(int dfd, const char *pathname,
23262327struct file * do_filp_open (int dfd , const char * pathname ,
23272328 const struct open_flags * op , int flags )
23282329{
2330+ struct nameidata nd ;
23292331 struct file * filp ;
23302332
2331- filp = path_openat (dfd , pathname , op , flags | LOOKUP_RCU );
2333+ filp = path_openat (dfd , pathname , & nd , op , flags | LOOKUP_RCU );
23322334 if (unlikely (filp == ERR_PTR (- ECHILD )))
2333- filp = path_openat (dfd , pathname , op , flags );
2335+ filp = path_openat (dfd , pathname , & nd , op , flags );
23342336 if (unlikely (filp == ERR_PTR (- ESTALE )))
2335- filp = path_openat (dfd , pathname , op , flags | LOOKUP_REVAL );
2337+ filp = path_openat (dfd , pathname , & nd , op , flags | LOOKUP_REVAL );
23362338 return filp ;
23372339}
23382340
2341+ struct file * do_file_open_root (struct dentry * dentry , struct vfsmount * mnt ,
2342+ const char * name , const struct open_flags * op , int flags )
2343+ {
2344+ struct nameidata nd ;
2345+ struct file * file ;
2346+
2347+ nd .root .mnt = mnt ;
2348+ nd .root .dentry = dentry ;
2349+
2350+ flags |= LOOKUP_ROOT ;
2351+
2352+ if (dentry -> d_inode -> i_op -> follow_link )
2353+ return ERR_PTR (- ELOOP );
2354+
2355+ file = path_openat (-1 , name , & nd , op , flags | LOOKUP_RCU );
2356+ if (unlikely (file == ERR_PTR (- ECHILD )))
2357+ file = path_openat (-1 , name , & nd , op , flags );
2358+ if (unlikely (file == ERR_PTR (- ESTALE )))
2359+ file = path_openat (-1 , name , & nd , op , flags | LOOKUP_REVAL );
2360+ return file ;
2361+ }
2362+
23392363/**
23402364 * lookup_create - lookup a dentry, creating it if it doesn't exist
23412365 * @nd: nameidata info
0 commit comments