tree: https://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux.git debugfs_namespaces head: 4e2b1b4274aaf7efdd1c24460febdf001421e695 commit: 738289244f9f67ce3281dfece66c6e2f728b6501 [1/4] debugfs: add ns entry config: x86_64-randconfig-s0-201940 (attached as .config) compiler: gcc-5 (Ubuntu 5.5.0-12ubuntu1) 5.5.0 20171010 reproduce: git checkout 738289244f9f67ce3281dfece66c6e2f728b6501 # save the attached .config to linux build tree make ARCH=x86_64 If you fix the issue, kindly add following tag Reported-by: kbuild test robot All errors (new ones prefixed by >>): fs/nsfs.c:19:30: error: conflicting type qualifiers for 'ns_file_operations' const struct file_operations ns_file_operations = { ^ In file included from fs/nsfs.c:12:0: include/linux/nsfs.h:6:31: note: previous declaration of 'ns_file_operations' was here extern struct file_operations ns_file_operations; ^ fs/nsfs.c: In function 'ns_ioctl': >> fs/nsfs.c:196:7: error: 'NS_GET_USERNS' undeclared (first use in this function) case NS_GET_USERNS: ^ fs/nsfs.c:196:7: note: each undeclared identifier is reported only once for each function it appears in >> fs/nsfs.c:198:7: error: 'NS_GET_PARENT' undeclared (first use in this function) case NS_GET_PARENT: ^ fs/nsfs.c:202:7: error: 'NS_GET_NSTYPE' undeclared (first use in this function) case NS_GET_NSTYPE: ^ >> fs/nsfs.c:204:7: error: 'NS_GET_OWNER_UID' undeclared (first use in this function) case NS_GET_OWNER_UID: ^ fs/nsfs.c: In function 'proc_ns_fget': fs/nsfs.c:244:15: error: implicit declaration of function 'debugfs_real_fops' [-Werror=implicit-function-declaration] real_fops = debugfs_real_fops(file); ^ fs/nsfs.c:244:13: warning: assignment makes pointer from integer without a cast [-Wint-conversion] real_fops = debugfs_real_fops(file); ^ cc1: some warnings being treated as errors vim +/NS_GET_USERNS +196 fs/nsfs.c 6786741dbf99e4 Andrey Vagin 2016-09-06 @12 #include d95fa3c76a66b6 Michael Kerrisk (man-pages 2017-01-25 13) #include e149ed2b805fef Al Viro 2014-11-01 14 e149ed2b805fef Al Viro 2014-11-01 15 static struct vfsmount *nsfs_mnt; e149ed2b805fef Al Viro 2014-11-01 16 6786741dbf99e4 Andrey Vagin 2016-09-06 17 static long ns_ioctl(struct file *filp, unsigned int ioctl, 6786741dbf99e4 Andrey Vagin 2016-09-06 18 unsigned long arg); 738289244f9f67 Christian Brauner 2019-10-11 @19 const struct file_operations ns_file_operations = { e149ed2b805fef Al Viro 2014-11-01 20 .llseek = no_llseek, 6786741dbf99e4 Andrey Vagin 2016-09-06 21 .unlocked_ioctl = ns_ioctl, e149ed2b805fef Al Viro 2014-11-01 22 }; e149ed2b805fef Al Viro 2014-11-01 23 e149ed2b805fef Al Viro 2014-11-01 24 static char *ns_dname(struct dentry *dentry, char *buffer, int buflen) e149ed2b805fef Al Viro 2014-11-01 25 { 75c3cfa855dced David Howells 2015-03-17 26 struct inode *inode = d_inode(dentry); e149ed2b805fef Al Viro 2014-11-01 27 const struct proc_ns_operations *ns_ops = dentry->d_fsdata; e149ed2b805fef Al Viro 2014-11-01 28 e149ed2b805fef Al Viro 2014-11-01 29 return dynamic_dname(dentry, buffer, buflen, "%s:[%lu]", e149ed2b805fef Al Viro 2014-11-01 30 ns_ops->name, inode->i_ino); e149ed2b805fef Al Viro 2014-11-01 31 } e149ed2b805fef Al Viro 2014-11-01 32 e149ed2b805fef Al Viro 2014-11-01 33 static void ns_prune_dentry(struct dentry *dentry) e149ed2b805fef Al Viro 2014-11-01 34 { 75c3cfa855dced David Howells 2015-03-17 35 struct inode *inode = d_inode(dentry); e149ed2b805fef Al Viro 2014-11-01 36 if (inode) { e149ed2b805fef Al Viro 2014-11-01 37 struct ns_common *ns = inode->i_private; e149ed2b805fef Al Viro 2014-11-01 38 atomic_long_set(&ns->stashed, 0); e149ed2b805fef Al Viro 2014-11-01 39 } e149ed2b805fef Al Viro 2014-11-01 40 } e149ed2b805fef Al Viro 2014-11-01 41 e149ed2b805fef Al Viro 2014-11-01 42 const struct dentry_operations ns_dentry_operations = e149ed2b805fef Al Viro 2014-11-01 43 { e149ed2b805fef Al Viro 2014-11-01 44 .d_prune = ns_prune_dentry, e149ed2b805fef Al Viro 2014-11-01 45 .d_delete = always_delete_dentry, e149ed2b805fef Al Viro 2014-11-01 46 .d_dname = ns_dname, e149ed2b805fef Al Viro 2014-11-01 47 }; e149ed2b805fef Al Viro 2014-11-01 48 e149ed2b805fef Al Viro 2014-11-01 49 static void nsfs_evict(struct inode *inode) e149ed2b805fef Al Viro 2014-11-01 50 { e149ed2b805fef Al Viro 2014-11-01 51 struct ns_common *ns = inode->i_private; e149ed2b805fef Al Viro 2014-11-01 52 clear_inode(inode); e149ed2b805fef Al Viro 2014-11-01 53 ns->ops->put(ns); e149ed2b805fef Al Viro 2014-11-01 54 } e149ed2b805fef Al Viro 2014-11-01 55 6786741dbf99e4 Andrey Vagin 2016-09-06 56 static void *__ns_get_path(struct path *path, struct ns_common *ns) e149ed2b805fef Al Viro 2014-11-01 57 { 213b067ce314f9 Eric W. Biederman 2016-09-22 58 struct vfsmount *mnt = nsfs_mnt; e149ed2b805fef Al Viro 2014-11-01 59 struct dentry *dentry; e149ed2b805fef Al Viro 2014-11-01 60 struct inode *inode; e149ed2b805fef Al Viro 2014-11-01 61 unsigned long d; e149ed2b805fef Al Viro 2014-11-01 62 e149ed2b805fef Al Viro 2014-11-01 63 rcu_read_lock(); e149ed2b805fef Al Viro 2014-11-01 64 d = atomic_long_read(&ns->stashed); e149ed2b805fef Al Viro 2014-11-01 65 if (!d) e149ed2b805fef Al Viro 2014-11-01 66 goto slow; e149ed2b805fef Al Viro 2014-11-01 67 dentry = (struct dentry *)d; e149ed2b805fef Al Viro 2014-11-01 68 if (!lockref_get_not_dead(&dentry->d_lockref)) e149ed2b805fef Al Viro 2014-11-01 69 goto slow; e149ed2b805fef Al Viro 2014-11-01 70 rcu_read_unlock(); 6786741dbf99e4 Andrey Vagin 2016-09-06 71 ns->ops->put(ns); e149ed2b805fef Al Viro 2014-11-01 72 got_it: 213b067ce314f9 Eric W. Biederman 2016-09-22 73 path->mnt = mntget(mnt); e149ed2b805fef Al Viro 2014-11-01 74 path->dentry = dentry; e149ed2b805fef Al Viro 2014-11-01 75 return NULL; e149ed2b805fef Al Viro 2014-11-01 76 slow: e149ed2b805fef Al Viro 2014-11-01 77 rcu_read_unlock(); e149ed2b805fef Al Viro 2014-11-01 78 inode = new_inode_pseudo(mnt->mnt_sb); e149ed2b805fef Al Viro 2014-11-01 79 if (!inode) { 6786741dbf99e4 Andrey Vagin 2016-09-06 80 ns->ops->put(ns); e149ed2b805fef Al Viro 2014-11-01 81 return ERR_PTR(-ENOMEM); e149ed2b805fef Al Viro 2014-11-01 82 } e149ed2b805fef Al Viro 2014-11-01 83 inode->i_ino = ns->inum; 078cd8279e6599 Deepa Dinamani 2016-09-14 84 inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode); e149ed2b805fef Al Viro 2014-11-01 85 inode->i_flags |= S_IMMUTABLE; e149ed2b805fef Al Viro 2014-11-01 86 inode->i_mode = S_IFREG | S_IRUGO; e149ed2b805fef Al Viro 2014-11-01 87 inode->i_fop = &ns_file_operations; e149ed2b805fef Al Viro 2014-11-01 88 inode->i_private = ns; e149ed2b805fef Al Viro 2014-11-01 89 5467a68cbf6884 Al Viro 2019-03-15 90 dentry = d_alloc_anon(mnt->mnt_sb); e149ed2b805fef Al Viro 2014-11-01 91 if (!dentry) { e149ed2b805fef Al Viro 2014-11-01 92 iput(inode); e149ed2b805fef Al Viro 2014-11-01 93 return ERR_PTR(-ENOMEM); e149ed2b805fef Al Viro 2014-11-01 94 } e149ed2b805fef Al Viro 2014-11-01 95 d_instantiate(dentry, inode); 6786741dbf99e4 Andrey Vagin 2016-09-06 96 dentry->d_fsdata = (void *)ns->ops; e149ed2b805fef Al Viro 2014-11-01 97 d = atomic_long_cmpxchg(&ns->stashed, 0, (unsigned long)dentry); e149ed2b805fef Al Viro 2014-11-01 98 if (d) { e149ed2b805fef Al Viro 2014-11-01 99 d_delete(dentry); /* make sure ->d_prune() does nothing */ e149ed2b805fef Al Viro 2014-11-01 100 dput(dentry); e149ed2b805fef Al Viro 2014-11-01 101 cpu_relax(); 6786741dbf99e4 Andrey Vagin 2016-09-06 102 return ERR_PTR(-EAGAIN); e149ed2b805fef Al Viro 2014-11-01 103 } e149ed2b805fef Al Viro 2014-11-01 104 goto got_it; e149ed2b805fef Al Viro 2014-11-01 105 } e149ed2b805fef Al Viro 2014-11-01 106 cdab6ba8668d68 Jakub Kicinski 2017-12-27 107 void *ns_get_path_cb(struct path *path, ns_get_path_helper_t *ns_get_cb, cdab6ba8668d68 Jakub Kicinski 2017-12-27 108 void *private_data) 6786741dbf99e4 Andrey Vagin 2016-09-06 109 { 6786741dbf99e4 Andrey Vagin 2016-09-06 110 void *ret; 6786741dbf99e4 Andrey Vagin 2016-09-06 111 357ab5b5d240a2 Al Viro 2019-03-22 112 do { 357ab5b5d240a2 Al Viro 2019-03-22 113 struct ns_common *ns = ns_get_cb(private_data); 6786741dbf99e4 Andrey Vagin 2016-09-06 114 if (!ns) 6786741dbf99e4 Andrey Vagin 2016-09-06 115 return ERR_PTR(-ENOENT); 6786741dbf99e4 Andrey Vagin 2016-09-06 116 6786741dbf99e4 Andrey Vagin 2016-09-06 117 ret = __ns_get_path(path, ns); 357ab5b5d240a2 Al Viro 2019-03-22 118 } while (ret == ERR_PTR(-EAGAIN)); 357ab5b5d240a2 Al Viro 2019-03-22 119 6786741dbf99e4 Andrey Vagin 2016-09-06 120 return ret; 6786741dbf99e4 Andrey Vagin 2016-09-06 121 } 6786741dbf99e4 Andrey Vagin 2016-09-06 122 cdab6ba8668d68 Jakub Kicinski 2017-12-27 123 struct ns_get_path_task_args { cdab6ba8668d68 Jakub Kicinski 2017-12-27 124 const struct proc_ns_operations *ns_ops; cdab6ba8668d68 Jakub Kicinski 2017-12-27 125 struct task_struct *task; cdab6ba8668d68 Jakub Kicinski 2017-12-27 126 }; cdab6ba8668d68 Jakub Kicinski 2017-12-27 127 cdab6ba8668d68 Jakub Kicinski 2017-12-27 128 static struct ns_common *ns_get_path_task(void *private_data) cdab6ba8668d68 Jakub Kicinski 2017-12-27 129 { cdab6ba8668d68 Jakub Kicinski 2017-12-27 130 struct ns_get_path_task_args *args = private_data; cdab6ba8668d68 Jakub Kicinski 2017-12-27 131 cdab6ba8668d68 Jakub Kicinski 2017-12-27 132 return args->ns_ops->get(args->task); cdab6ba8668d68 Jakub Kicinski 2017-12-27 133 } cdab6ba8668d68 Jakub Kicinski 2017-12-27 134 cdab6ba8668d68 Jakub Kicinski 2017-12-27 135 void *ns_get_path(struct path *path, struct task_struct *task, cdab6ba8668d68 Jakub Kicinski 2017-12-27 136 const struct proc_ns_operations *ns_ops) cdab6ba8668d68 Jakub Kicinski 2017-12-27 137 { cdab6ba8668d68 Jakub Kicinski 2017-12-27 138 struct ns_get_path_task_args args = { cdab6ba8668d68 Jakub Kicinski 2017-12-27 139 .ns_ops = ns_ops, cdab6ba8668d68 Jakub Kicinski 2017-12-27 140 .task = task, cdab6ba8668d68 Jakub Kicinski 2017-12-27 141 }; cdab6ba8668d68 Jakub Kicinski 2017-12-27 142 cdab6ba8668d68 Jakub Kicinski 2017-12-27 143 return ns_get_path_cb(path, ns_get_path_task, &args); cdab6ba8668d68 Jakub Kicinski 2017-12-27 144 } cdab6ba8668d68 Jakub Kicinski 2017-12-27 145 c62cce2caee558 Andrey Vagin 2016-10-24 146 int open_related_ns(struct ns_common *ns, 6786741dbf99e4 Andrey Vagin 2016-09-06 147 struct ns_common *(*get_ns)(struct ns_common *ns)) 6786741dbf99e4 Andrey Vagin 2016-09-06 148 { 6786741dbf99e4 Andrey Vagin 2016-09-06 149 struct path path = {}; 6786741dbf99e4 Andrey Vagin 2016-09-06 150 struct file *f; 6786741dbf99e4 Andrey Vagin 2016-09-06 151 void *err; 6786741dbf99e4 Andrey Vagin 2016-09-06 152 int fd; 6786741dbf99e4 Andrey Vagin 2016-09-06 153 6786741dbf99e4 Andrey Vagin 2016-09-06 154 fd = get_unused_fd_flags(O_CLOEXEC); 6786741dbf99e4 Andrey Vagin 2016-09-06 155 if (fd < 0) 6786741dbf99e4 Andrey Vagin 2016-09-06 156 return fd; 6786741dbf99e4 Andrey Vagin 2016-09-06 157 357ab5b5d240a2 Al Viro 2019-03-22 158 do { 6786741dbf99e4 Andrey Vagin 2016-09-06 159 struct ns_common *relative; 6786741dbf99e4 Andrey Vagin 2016-09-06 160 6786741dbf99e4 Andrey Vagin 2016-09-06 161 relative = get_ns(ns); 6786741dbf99e4 Andrey Vagin 2016-09-06 162 if (IS_ERR(relative)) { 6786741dbf99e4 Andrey Vagin 2016-09-06 163 put_unused_fd(fd); 6786741dbf99e4 Andrey Vagin 2016-09-06 164 return PTR_ERR(relative); 6786741dbf99e4 Andrey Vagin 2016-09-06 165 } 6786741dbf99e4 Andrey Vagin 2016-09-06 166 6786741dbf99e4 Andrey Vagin 2016-09-06 167 err = __ns_get_path(&path, relative); 357ab5b5d240a2 Al Viro 2019-03-22 168 } while (err == ERR_PTR(-EAGAIN)); 357ab5b5d240a2 Al Viro 2019-03-22 169 6786741dbf99e4 Andrey Vagin 2016-09-06 170 if (IS_ERR(err)) { 6786741dbf99e4 Andrey Vagin 2016-09-06 171 put_unused_fd(fd); 6786741dbf99e4 Andrey Vagin 2016-09-06 172 return PTR_ERR(err); 6786741dbf99e4 Andrey Vagin 2016-09-06 173 } 6786741dbf99e4 Andrey Vagin 2016-09-06 174 6786741dbf99e4 Andrey Vagin 2016-09-06 175 f = dentry_open(&path, O_RDONLY, current_cred()); 6786741dbf99e4 Andrey Vagin 2016-09-06 176 path_put(&path); 6786741dbf99e4 Andrey Vagin 2016-09-06 177 if (IS_ERR(f)) { 6786741dbf99e4 Andrey Vagin 2016-09-06 178 put_unused_fd(fd); 6786741dbf99e4 Andrey Vagin 2016-09-06 179 fd = PTR_ERR(f); 6786741dbf99e4 Andrey Vagin 2016-09-06 180 } else 6786741dbf99e4 Andrey Vagin 2016-09-06 181 fd_install(fd, f); 6786741dbf99e4 Andrey Vagin 2016-09-06 182 6786741dbf99e4 Andrey Vagin 2016-09-06 183 return fd; 6786741dbf99e4 Andrey Vagin 2016-09-06 184 } 24dce0800baaa5 Kirill Tkhai 2018-02-14 185 EXPORT_SYMBOL_GPL(open_related_ns); 6786741dbf99e4 Andrey Vagin 2016-09-06 186 6786741dbf99e4 Andrey Vagin 2016-09-06 187 static long ns_ioctl(struct file *filp, unsigned int ioctl, 6786741dbf99e4 Andrey Vagin 2016-09-06 188 unsigned long arg) 6786741dbf99e4 Andrey Vagin 2016-09-06 189 { d95fa3c76a66b6 Michael Kerrisk (man-pages 2017-01-25 190) struct user_namespace *user_ns; 6786741dbf99e4 Andrey Vagin 2016-09-06 191 struct ns_common *ns = get_proc_ns(file_inode(filp)); d95fa3c76a66b6 Michael Kerrisk (man-pages 2017-01-25 192) uid_t __user *argp; d95fa3c76a66b6 Michael Kerrisk (man-pages 2017-01-25 193) uid_t uid; 6786741dbf99e4 Andrey Vagin 2016-09-06 194 6786741dbf99e4 Andrey Vagin 2016-09-06 195 switch (ioctl) { 6786741dbf99e4 Andrey Vagin 2016-09-06 @196 case NS_GET_USERNS: 6786741dbf99e4 Andrey Vagin 2016-09-06 197 return open_related_ns(ns, ns_get_owner); a7306ed8d94af7 Andrey Vagin 2016-09-06 @198 case NS_GET_PARENT: a7306ed8d94af7 Andrey Vagin 2016-09-06 199 if (!ns->ops->get_parent) a7306ed8d94af7 Andrey Vagin 2016-09-06 200 return -EINVAL; a7306ed8d94af7 Andrey Vagin 2016-09-06 201 return open_related_ns(ns, ns->ops->get_parent); e5ff5ce6e20ee2 Michael Kerrisk (man-pages 2017-01-25 202) case NS_GET_NSTYPE: e5ff5ce6e20ee2 Michael Kerrisk (man-pages 2017-01-25 203) return ns->ops->type; d95fa3c76a66b6 Michael Kerrisk (man-pages 2017-01-25 @204) case NS_GET_OWNER_UID: d95fa3c76a66b6 Michael Kerrisk (man-pages 2017-01-25 205) if (ns->ops->type != CLONE_NEWUSER) d95fa3c76a66b6 Michael Kerrisk (man-pages 2017-01-25 206) return -EINVAL; d95fa3c76a66b6 Michael Kerrisk (man-pages 2017-01-25 207) user_ns = container_of(ns, struct user_namespace, ns); d95fa3c76a66b6 Michael Kerrisk (man-pages 2017-01-25 208) argp = (uid_t __user *) arg; d95fa3c76a66b6 Michael Kerrisk (man-pages 2017-01-25 209) uid = from_kuid_munged(current_user_ns(), user_ns->owner); d95fa3c76a66b6 Michael Kerrisk (man-pages 2017-01-25 210) return put_user(uid, argp); 6786741dbf99e4 Andrey Vagin 2016-09-06 211 default: 6786741dbf99e4 Andrey Vagin 2016-09-06 212 return -ENOTTY; 6786741dbf99e4 Andrey Vagin 2016-09-06 213 } 6786741dbf99e4 Andrey Vagin 2016-09-06 214 } 6786741dbf99e4 Andrey Vagin 2016-09-06 215 :::::: The code at line 196 was first introduced by commit :::::: 6786741dbf99e44fb0c0ed85a37582b8a26f1c3b nsfs: add ioctl to get an owning user namespace for ns file descriptor :::::: TO: Andrey Vagin :::::: CC: Eric W. Biederman --- 0-DAY kernel test infrastructure Open Source Technology Center https://lists.01.org/pipermail/kbuild-all Intel Corporation