Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

New AT_... flag: AT_EMPTY_PATH

For name_to_handle_at(2) we'll want both ...at()-style syscall that
would be usable for non-directory descriptors (with empty relative
pathname). Introduce new flag (AT_EMPTY_PATH) to deal with that and
corresponding LOOKUP_EMPTY; teach user_path_at() and path_init() to
deal with the latter.

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

Al Viro f52e0c11 5fe0c237

+21 -10
+19 -10
fs/namei.c
··· 136 136 return retval; 137 137 } 138 138 139 - char * getname(const char __user * filename) 139 + static char *getname_flags(const char __user * filename, int flags) 140 140 { 141 141 char *tmp, *result; 142 142 ··· 147 147 148 148 result = tmp; 149 149 if (retval < 0) { 150 - __putname(tmp); 151 - result = ERR_PTR(retval); 150 + if (retval != -ENOENT || !(flags & LOOKUP_EMPTY)) { 151 + __putname(tmp); 152 + result = ERR_PTR(retval); 153 + } 152 154 } 153 155 } 154 156 audit_getname(result); 155 157 return result; 158 + } 159 + 160 + char *getname(const char __user * filename) 161 + { 162 + return getname_flags(filename, 0); 156 163 } 157 164 158 165 #ifdef CONFIG_AUDITSYSCALL ··· 1551 1544 1552 1545 dentry = file->f_path.dentry; 1553 1546 1554 - retval = -ENOTDIR; 1555 - if (!S_ISDIR(dentry->d_inode->i_mode)) 1556 - goto fput_fail; 1547 + if (*name) { 1548 + retval = -ENOTDIR; 1549 + if (!S_ISDIR(dentry->d_inode->i_mode)) 1550 + goto fput_fail; 1557 1551 1558 - retval = file_permission(file, MAY_EXEC); 1559 - if (retval) 1560 - goto fput_fail; 1552 + retval = file_permission(file, MAY_EXEC); 1553 + if (retval) 1554 + goto fput_fail; 1555 + } 1561 1556 1562 1557 nd->path = file->f_path; 1563 1558 if (flags & LOOKUP_RCU) { ··· 1768 1759 struct path *path) 1769 1760 { 1770 1761 struct nameidata nd; 1771 - char *tmp = getname(name); 1762 + char *tmp = getname_flags(name, flags); 1772 1763 int err = PTR_ERR(tmp); 1773 1764 if (!IS_ERR(tmp)) { 1774 1765
+1
include/linux/fcntl.h
··· 46 46 unlinking file. */ 47 47 #define AT_SYMLINK_FOLLOW 0x400 /* Follow symbolic links. */ 48 48 #define AT_NO_AUTOMOUNT 0x800 /* Suppress terminal automount traversal */ 49 + #define AT_EMPTY_PATH 0x1000 /* Allow empty relative pathname */ 49 50 50 51 #ifdef __KERNEL__ 51 52
+1
include/linux/namei.h
··· 64 64 65 65 #define LOOKUP_JUMPED 0x1000 66 66 #define LOOKUP_ROOT 0x2000 67 + #define LOOKUP_EMPTY 0x4000 67 68 68 69 extern int user_path_at(int, const char __user *, unsigned, struct path *); 69 70