1 // SPDX-License-Identifier: GPL-2.0
5 #include <linux/init.h>
6 #include <linux/sysctl.h>
7 #include <linux/poll.h>
8 #include <linux/proc_fs.h>
9 #include <linux/printk.h>
10 #include <linux/security.h>
11 #include <linux/sched.h>
12 #include <linux/cred.h>
13 #include <linux/namei.h>
15 #include <linux/uio.h>
16 #include <linux/module.h>
17 #include <linux/bpf-cgroup.h>
18 #include <linux/mount.h>
19 #include <linux/kmemleak.h>
22 #define list_for_each_table_entry(entry, table) \
23 for ((entry) = (table); (entry)->procname; (entry)++)
25 static const struct dentry_operations proc_sys_dentry_operations;
26 static const struct file_operations proc_sys_file_operations;
27 static const struct inode_operations proc_sys_inode_operations;
28 static const struct file_operations proc_sys_dir_file_operations;
29 static const struct inode_operations proc_sys_dir_operations;
31 /* shared constants to be used in various sysctls */
32 const int sysctl_vals[] = { 0, 1, 2, 3, 4, 100, 200, 1000, 3000, INT_MAX, 65535, -1 };
33 EXPORT_SYMBOL(sysctl_vals);
35 const unsigned long sysctl_long_vals[] = { 0, 1, LONG_MAX };
36 EXPORT_SYMBOL_GPL(sysctl_long_vals);
38 /* Support for permanently empty directories */
40 struct ctl_table sysctl_mount_point[] = {
45 * register_sysctl_mount_point() - registers a sysctl mount point
46 * @path: path for the mount point
48 * Used to create a permanently empty directory to serve as mount point.
49 * There are some subtle but important permission checks this allows in the
50 * case of unprivileged mounts.
52 struct ctl_table_header *register_sysctl_mount_point(const char *path)
54 return register_sysctl(path, sysctl_mount_point);
56 EXPORT_SYMBOL(register_sysctl_mount_point);
58 static bool is_empty_dir(struct ctl_table_header *head)
60 return head->ctl_table[0].child == sysctl_mount_point;
63 static void set_empty_dir(struct ctl_dir *dir)
65 dir->header.ctl_table[0].child = sysctl_mount_point;
68 static void clear_empty_dir(struct ctl_dir *dir)
71 dir->header.ctl_table[0].child = NULL;
74 void proc_sys_poll_notify(struct ctl_table_poll *poll)
79 atomic_inc(&poll->event);
80 wake_up_interruptible(&poll->wait);
83 static struct ctl_table root_table[] = {
86 .mode = S_IFDIR|S_IRUGO|S_IXUGO,
90 static struct ctl_table_root sysctl_table_root = {
91 .default_set.dir.header = {
94 .ctl_table = root_table }},
95 .ctl_table_arg = root_table,
96 .root = &sysctl_table_root,
97 .set = &sysctl_table_root.default_set,
101 static DEFINE_SPINLOCK(sysctl_lock);
103 static void drop_sysctl_table(struct ctl_table_header *header);
104 static int sysctl_follow_link(struct ctl_table_header **phead,
105 struct ctl_table **pentry);
106 static int insert_links(struct ctl_table_header *head);
107 static void put_links(struct ctl_table_header *header);
109 static void sysctl_print_dir(struct ctl_dir *dir)
111 if (dir->header.parent)
112 sysctl_print_dir(dir->header.parent);
113 pr_cont("%s/", dir->header.ctl_table[0].procname);
116 static int namecmp(const char *name1, int len1, const char *name2, int len2)
120 cmp = memcmp(name1, name2, min(len1, len2));
126 /* Called under sysctl_lock */
127 static struct ctl_table *find_entry(struct ctl_table_header **phead,
128 struct ctl_dir *dir, const char *name, int namelen)
130 struct ctl_table_header *head;
131 struct ctl_table *entry;
132 struct rb_node *node = dir->root.rb_node;
136 struct ctl_node *ctl_node;
137 const char *procname;
140 ctl_node = rb_entry(node, struct ctl_node, node);
141 head = ctl_node->header;
142 entry = &head->ctl_table[ctl_node - head->node];
143 procname = entry->procname;
145 cmp = namecmp(name, namelen, procname, strlen(procname));
147 node = node->rb_left;
149 node = node->rb_right;
158 static int insert_entry(struct ctl_table_header *head, struct ctl_table *entry)
160 struct rb_node *node = &head->node[entry - head->ctl_table].node;
161 struct rb_node **p = &head->parent->root.rb_node;
162 struct rb_node *parent = NULL;
163 const char *name = entry->procname;
164 int namelen = strlen(name);
167 struct ctl_table_header *parent_head;
168 struct ctl_table *parent_entry;
169 struct ctl_node *parent_node;
170 const char *parent_name;
174 parent_node = rb_entry(parent, struct ctl_node, node);
175 parent_head = parent_node->header;
176 parent_entry = &parent_head->ctl_table[parent_node - parent_head->node];
177 parent_name = parent_entry->procname;
179 cmp = namecmp(name, namelen, parent_name, strlen(parent_name));
185 pr_err("sysctl duplicate entry: ");
186 sysctl_print_dir(head->parent);
187 pr_cont("%s\n", entry->procname);
192 rb_link_node(node, parent, p);
193 rb_insert_color(node, &head->parent->root);
197 static void erase_entry(struct ctl_table_header *head, struct ctl_table *entry)
199 struct rb_node *node = &head->node[entry - head->ctl_table].node;
201 rb_erase(node, &head->parent->root);
204 static void init_header(struct ctl_table_header *head,
205 struct ctl_table_root *root, struct ctl_table_set *set,
206 struct ctl_node *node, struct ctl_table *table)
208 head->ctl_table = table;
209 head->ctl_table_arg = table;
213 head->unregistering = NULL;
218 INIT_HLIST_HEAD(&head->inodes);
220 struct ctl_table *entry;
222 list_for_each_table_entry(entry, table) {
229 static void erase_header(struct ctl_table_header *head)
231 struct ctl_table *entry;
233 list_for_each_table_entry(entry, head->ctl_table)
234 erase_entry(head, entry);
237 static int insert_header(struct ctl_dir *dir, struct ctl_table_header *header)
239 struct ctl_table *entry;
242 /* Is this a permanently empty directory? */
243 if (is_empty_dir(&dir->header))
246 /* Am I creating a permanently empty directory? */
247 if (header->ctl_table == sysctl_mount_point) {
248 if (!RB_EMPTY_ROOT(&dir->root))
254 header->parent = dir;
255 err = insert_links(header);
258 list_for_each_table_entry(entry, header->ctl_table) {
259 err = insert_entry(header, entry);
265 erase_header(header);
268 if (header->ctl_table == sysctl_mount_point)
269 clear_empty_dir(dir);
270 header->parent = NULL;
271 drop_sysctl_table(&dir->header);
275 /* called under sysctl_lock */
276 static int use_table(struct ctl_table_header *p)
278 if (unlikely(p->unregistering))
284 /* called under sysctl_lock */
285 static void unuse_table(struct ctl_table_header *p)
288 if (unlikely(p->unregistering))
289 complete(p->unregistering);
292 static void proc_sys_invalidate_dcache(struct ctl_table_header *head)
294 proc_invalidate_siblings_dcache(&head->inodes, &sysctl_lock);
297 /* called under sysctl_lock, will reacquire if has to wait */
298 static void start_unregistering(struct ctl_table_header *p)
301 * if p->used is 0, nobody will ever touch that entry again;
302 * we'll eliminate all paths to it before dropping sysctl_lock
304 if (unlikely(p->used)) {
305 struct completion wait;
306 init_completion(&wait);
307 p->unregistering = &wait;
308 spin_unlock(&sysctl_lock);
309 wait_for_completion(&wait);
311 /* anything non-NULL; we'll never dereference it */
312 p->unregistering = ERR_PTR(-EINVAL);
313 spin_unlock(&sysctl_lock);
316 * Invalidate dentries for unregistered sysctls: namespaced sysctls
317 * can have duplicate names and contaminate dcache very badly.
319 proc_sys_invalidate_dcache(p);
321 * do not remove from the list until nobody holds it; walking the
322 * list in do_sysctl() relies on that.
324 spin_lock(&sysctl_lock);
328 static struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
331 spin_lock(&sysctl_lock);
332 if (!use_table(head))
333 head = ERR_PTR(-ENOENT);
334 spin_unlock(&sysctl_lock);
338 static void sysctl_head_finish(struct ctl_table_header *head)
342 spin_lock(&sysctl_lock);
344 spin_unlock(&sysctl_lock);
347 static struct ctl_table_set *
348 lookup_header_set(struct ctl_table_root *root)
350 struct ctl_table_set *set = &root->default_set;
352 set = root->lookup(root);
356 static struct ctl_table *lookup_entry(struct ctl_table_header **phead,
358 const char *name, int namelen)
360 struct ctl_table_header *head;
361 struct ctl_table *entry;
363 spin_lock(&sysctl_lock);
364 entry = find_entry(&head, dir, name, namelen);
365 if (entry && use_table(head))
369 spin_unlock(&sysctl_lock);
373 static struct ctl_node *first_usable_entry(struct rb_node *node)
375 struct ctl_node *ctl_node;
377 for (;node; node = rb_next(node)) {
378 ctl_node = rb_entry(node, struct ctl_node, node);
379 if (use_table(ctl_node->header))
385 static void first_entry(struct ctl_dir *dir,
386 struct ctl_table_header **phead, struct ctl_table **pentry)
388 struct ctl_table_header *head = NULL;
389 struct ctl_table *entry = NULL;
390 struct ctl_node *ctl_node;
392 spin_lock(&sysctl_lock);
393 ctl_node = first_usable_entry(rb_first(&dir->root));
394 spin_unlock(&sysctl_lock);
396 head = ctl_node->header;
397 entry = &head->ctl_table[ctl_node - head->node];
403 static void next_entry(struct ctl_table_header **phead, struct ctl_table **pentry)
405 struct ctl_table_header *head = *phead;
406 struct ctl_table *entry = *pentry;
407 struct ctl_node *ctl_node = &head->node[entry - head->ctl_table];
409 spin_lock(&sysctl_lock);
412 ctl_node = first_usable_entry(rb_next(&ctl_node->node));
413 spin_unlock(&sysctl_lock);
416 head = ctl_node->header;
417 entry = &head->ctl_table[ctl_node - head->node];
424 * sysctl_perm does NOT grant the superuser all rights automatically, because
425 * some sysctl variables are readonly even to root.
428 static int test_perm(int mode, int op)
430 if (uid_eq(current_euid(), GLOBAL_ROOT_UID))
432 else if (in_egroup_p(GLOBAL_ROOT_GID))
434 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
439 static int sysctl_perm(struct ctl_table_header *head, struct ctl_table *table, int op)
441 struct ctl_table_root *root = head->root;
444 if (root->permissions)
445 mode = root->permissions(head, table);
449 return test_perm(mode, op);
452 static struct inode *proc_sys_make_inode(struct super_block *sb,
453 struct ctl_table_header *head, struct ctl_table *table)
455 struct ctl_table_root *root = head->root;
457 struct proc_inode *ei;
459 inode = new_inode(sb);
461 return ERR_PTR(-ENOMEM);
463 inode->i_ino = get_next_ino();
467 spin_lock(&sysctl_lock);
468 if (unlikely(head->unregistering)) {
469 spin_unlock(&sysctl_lock);
471 return ERR_PTR(-ENOENT);
474 ei->sysctl_entry = table;
475 hlist_add_head_rcu(&ei->sibling_inodes, &head->inodes);
477 spin_unlock(&sysctl_lock);
479 inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
480 inode->i_mode = table->mode;
481 if (!S_ISDIR(table->mode)) {
482 inode->i_mode |= S_IFREG;
483 inode->i_op = &proc_sys_inode_operations;
484 inode->i_fop = &proc_sys_file_operations;
486 inode->i_mode |= S_IFDIR;
487 inode->i_op = &proc_sys_dir_operations;
488 inode->i_fop = &proc_sys_dir_file_operations;
489 if (is_empty_dir(head))
490 make_empty_dir_inode(inode);
493 if (root->set_ownership)
494 root->set_ownership(head, table, &inode->i_uid, &inode->i_gid);
496 inode->i_uid = GLOBAL_ROOT_UID;
497 inode->i_gid = GLOBAL_ROOT_GID;
503 void proc_sys_evict_inode(struct inode *inode, struct ctl_table_header *head)
505 spin_lock(&sysctl_lock);
506 hlist_del_init_rcu(&PROC_I(inode)->sibling_inodes);
508 kfree_rcu(head, rcu);
509 spin_unlock(&sysctl_lock);
512 static struct ctl_table_header *grab_header(struct inode *inode)
514 struct ctl_table_header *head = PROC_I(inode)->sysctl;
516 head = &sysctl_table_root.default_set.dir.header;
517 return sysctl_head_grab(head);
520 static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
523 struct ctl_table_header *head = grab_header(dir);
524 struct ctl_table_header *h = NULL;
525 const struct qstr *name = &dentry->d_name;
528 struct dentry *err = ERR_PTR(-ENOENT);
529 struct ctl_dir *ctl_dir;
533 return ERR_CAST(head);
535 ctl_dir = container_of(head, struct ctl_dir, header);
537 p = lookup_entry(&h, ctl_dir, name->name, name->len);
541 if (S_ISLNK(p->mode)) {
542 ret = sysctl_follow_link(&h, &p);
548 inode = proc_sys_make_inode(dir->i_sb, h ? h : head, p);
550 err = ERR_CAST(inode);
554 d_set_d_op(dentry, &proc_sys_dentry_operations);
555 err = d_splice_alias(inode, dentry);
559 sysctl_head_finish(h);
560 sysctl_head_finish(head);
564 static ssize_t proc_sys_call_handler(struct kiocb *iocb, struct iov_iter *iter,
567 struct inode *inode = file_inode(iocb->ki_filp);
568 struct ctl_table_header *head = grab_header(inode);
569 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
570 size_t count = iov_iter_count(iter);
575 return PTR_ERR(head);
578 * At this point we know that the sysctl was not unregistered
579 * and won't be until we finish.
582 if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
585 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
587 if (!table->proc_handler)
590 /* don't even try if the size is too large */
592 if (count >= KMALLOC_MAX_SIZE)
594 kbuf = kvzalloc(count + 1, GFP_KERNEL);
600 if (!copy_from_iter_full(kbuf, count, iter))
605 error = BPF_CGROUP_RUN_PROG_SYSCTL(head, table, write, &kbuf, &count,
610 /* careful: calling conventions are nasty here */
611 error = table->proc_handler(table, write, kbuf, &count, &iocb->ki_pos);
617 if (copy_to_iter(kbuf, count, iter) < count)
625 sysctl_head_finish(head);
630 static ssize_t proc_sys_read(struct kiocb *iocb, struct iov_iter *iter)
632 return proc_sys_call_handler(iocb, iter, 0);
635 static ssize_t proc_sys_write(struct kiocb *iocb, struct iov_iter *iter)
637 return proc_sys_call_handler(iocb, iter, 1);
640 static int proc_sys_open(struct inode *inode, struct file *filp)
642 struct ctl_table_header *head = grab_header(inode);
643 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
645 /* sysctl was unregistered */
647 return PTR_ERR(head);
650 filp->private_data = proc_sys_poll_event(table->poll);
652 sysctl_head_finish(head);
657 static __poll_t proc_sys_poll(struct file *filp, poll_table *wait)
659 struct inode *inode = file_inode(filp);
660 struct ctl_table_header *head = grab_header(inode);
661 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
662 __poll_t ret = DEFAULT_POLLMASK;
665 /* sysctl was unregistered */
667 return EPOLLERR | EPOLLHUP;
669 if (!table->proc_handler)
675 event = (unsigned long)filp->private_data;
676 poll_wait(filp, &table->poll->wait, wait);
678 if (event != atomic_read(&table->poll->event)) {
679 filp->private_data = proc_sys_poll_event(table->poll);
680 ret = EPOLLIN | EPOLLRDNORM | EPOLLERR | EPOLLPRI;
684 sysctl_head_finish(head);
689 static bool proc_sys_fill_cache(struct file *file,
690 struct dir_context *ctx,
691 struct ctl_table_header *head,
692 struct ctl_table *table)
694 struct dentry *child, *dir = file->f_path.dentry;
698 unsigned type = DT_UNKNOWN;
700 qname.name = table->procname;
701 qname.len = strlen(table->procname);
702 qname.hash = full_name_hash(dir, qname.name, qname.len);
704 child = d_lookup(dir, &qname);
706 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wq);
707 child = d_alloc_parallel(dir, &qname, &wq);
710 if (d_in_lookup(child)) {
712 inode = proc_sys_make_inode(dir->d_sb, head, table);
714 d_lookup_done(child);
718 d_set_d_op(child, &proc_sys_dentry_operations);
719 res = d_splice_alias(inode, child);
720 d_lookup_done(child);
731 inode = d_inode(child);
733 type = inode->i_mode >> 12;
735 return dir_emit(ctx, qname.name, qname.len, ino, type);
738 static bool proc_sys_link_fill_cache(struct file *file,
739 struct dir_context *ctx,
740 struct ctl_table_header *head,
741 struct ctl_table *table)
745 head = sysctl_head_grab(head);
749 /* It is not an error if we can not follow the link ignore it */
750 if (sysctl_follow_link(&head, &table))
753 ret = proc_sys_fill_cache(file, ctx, head, table);
755 sysctl_head_finish(head);
759 static int scan(struct ctl_table_header *head, struct ctl_table *table,
760 unsigned long *pos, struct file *file,
761 struct dir_context *ctx)
765 if ((*pos)++ < ctx->pos)
768 if (unlikely(S_ISLNK(table->mode)))
769 res = proc_sys_link_fill_cache(file, ctx, head, table);
771 res = proc_sys_fill_cache(file, ctx, head, table);
779 static int proc_sys_readdir(struct file *file, struct dir_context *ctx)
781 struct ctl_table_header *head = grab_header(file_inode(file));
782 struct ctl_table_header *h = NULL;
783 struct ctl_table *entry;
784 struct ctl_dir *ctl_dir;
788 return PTR_ERR(head);
790 ctl_dir = container_of(head, struct ctl_dir, header);
792 if (!dir_emit_dots(file, ctx))
797 for (first_entry(ctl_dir, &h, &entry); h; next_entry(&h, &entry)) {
798 if (!scan(h, entry, &pos, file, ctx)) {
799 sysctl_head_finish(h);
804 sysctl_head_finish(head);
808 static int proc_sys_permission(struct user_namespace *mnt_userns,
809 struct inode *inode, int mask)
812 * sysctl entries that are not writeable,
813 * are _NOT_ writeable, capabilities or not.
815 struct ctl_table_header *head;
816 struct ctl_table *table;
819 /* Executable files are not allowed under /proc/sys/ */
820 if ((mask & MAY_EXEC) && S_ISREG(inode->i_mode))
823 head = grab_header(inode);
825 return PTR_ERR(head);
827 table = PROC_I(inode)->sysctl_entry;
828 if (!table) /* global root - r-xr-xr-x */
829 error = mask & MAY_WRITE ? -EACCES : 0;
830 else /* Use the permissions on the sysctl table entry */
831 error = sysctl_perm(head, table, mask & ~MAY_NOT_BLOCK);
833 sysctl_head_finish(head);
837 static int proc_sys_setattr(struct user_namespace *mnt_userns,
838 struct dentry *dentry, struct iattr *attr)
840 struct inode *inode = d_inode(dentry);
843 if (attr->ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID))
846 error = setattr_prepare(&init_user_ns, dentry, attr);
850 setattr_copy(&init_user_ns, inode, attr);
851 mark_inode_dirty(inode);
855 static int proc_sys_getattr(struct user_namespace *mnt_userns,
856 const struct path *path, struct kstat *stat,
857 u32 request_mask, unsigned int query_flags)
859 struct inode *inode = d_inode(path->dentry);
860 struct ctl_table_header *head = grab_header(inode);
861 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
864 return PTR_ERR(head);
866 generic_fillattr(&init_user_ns, inode, stat);
868 stat->mode = (stat->mode & S_IFMT) | table->mode;
870 sysctl_head_finish(head);
874 static const struct file_operations proc_sys_file_operations = {
875 .open = proc_sys_open,
876 .poll = proc_sys_poll,
877 .read_iter = proc_sys_read,
878 .write_iter = proc_sys_write,
879 .splice_read = generic_file_splice_read,
880 .splice_write = iter_file_splice_write,
881 .llseek = default_llseek,
884 static const struct file_operations proc_sys_dir_file_operations = {
885 .read = generic_read_dir,
886 .iterate_shared = proc_sys_readdir,
887 .llseek = generic_file_llseek,
890 static const struct inode_operations proc_sys_inode_operations = {
891 .permission = proc_sys_permission,
892 .setattr = proc_sys_setattr,
893 .getattr = proc_sys_getattr,
896 static const struct inode_operations proc_sys_dir_operations = {
897 .lookup = proc_sys_lookup,
898 .permission = proc_sys_permission,
899 .setattr = proc_sys_setattr,
900 .getattr = proc_sys_getattr,
903 static int proc_sys_revalidate(struct dentry *dentry, unsigned int flags)
905 if (flags & LOOKUP_RCU)
907 return !PROC_I(d_inode(dentry))->sysctl->unregistering;
910 static int proc_sys_delete(const struct dentry *dentry)
912 return !!PROC_I(d_inode(dentry))->sysctl->unregistering;
915 static int sysctl_is_seen(struct ctl_table_header *p)
917 struct ctl_table_set *set = p->set;
919 spin_lock(&sysctl_lock);
920 if (p->unregistering)
922 else if (!set->is_seen)
925 res = set->is_seen(set);
926 spin_unlock(&sysctl_lock);
930 static int proc_sys_compare(const struct dentry *dentry,
931 unsigned int len, const char *str, const struct qstr *name)
933 struct ctl_table_header *head;
936 /* Although proc doesn't have negative dentries, rcu-walk means
937 * that inode here can be NULL */
938 /* AV: can it, indeed? */
939 inode = d_inode_rcu(dentry);
942 if (name->len != len)
944 if (memcmp(name->name, str, len))
946 head = rcu_dereference(PROC_I(inode)->sysctl);
947 return !head || !sysctl_is_seen(head);
950 static const struct dentry_operations proc_sys_dentry_operations = {
951 .d_revalidate = proc_sys_revalidate,
952 .d_delete = proc_sys_delete,
953 .d_compare = proc_sys_compare,
956 static struct ctl_dir *find_subdir(struct ctl_dir *dir,
957 const char *name, int namelen)
959 struct ctl_table_header *head;
960 struct ctl_table *entry;
962 entry = find_entry(&head, dir, name, namelen);
964 return ERR_PTR(-ENOENT);
965 if (!S_ISDIR(entry->mode))
966 return ERR_PTR(-ENOTDIR);
967 return container_of(head, struct ctl_dir, header);
970 static struct ctl_dir *new_dir(struct ctl_table_set *set,
971 const char *name, int namelen)
973 struct ctl_table *table;
975 struct ctl_node *node;
978 new = kzalloc(sizeof(*new) + sizeof(struct ctl_node) +
979 sizeof(struct ctl_table)*2 + namelen + 1,
984 node = (struct ctl_node *)(new + 1);
985 table = (struct ctl_table *)(node + 1);
986 new_name = (char *)(table + 2);
987 memcpy(new_name, name, namelen);
988 table[0].procname = new_name;
989 table[0].mode = S_IFDIR|S_IRUGO|S_IXUGO;
990 init_header(&new->header, set->dir.header.root, set, node, table);
996 * get_subdir - find or create a subdir with the specified name.
997 * @dir: Directory to create the subdirectory in
998 * @name: The name of the subdirectory to find or create
999 * @namelen: The length of name
1001 * Takes a directory with an elevated reference count so we know that
1002 * if we drop the lock the directory will not go away. Upon success
1003 * the reference is moved from @dir to the returned subdirectory.
1004 * Upon error an error code is returned and the reference on @dir is
1007 static struct ctl_dir *get_subdir(struct ctl_dir *dir,
1008 const char *name, int namelen)
1010 struct ctl_table_set *set = dir->header.set;
1011 struct ctl_dir *subdir, *new = NULL;
1014 spin_lock(&sysctl_lock);
1015 subdir = find_subdir(dir, name, namelen);
1016 if (!IS_ERR(subdir))
1018 if (PTR_ERR(subdir) != -ENOENT)
1021 spin_unlock(&sysctl_lock);
1022 new = new_dir(set, name, namelen);
1023 spin_lock(&sysctl_lock);
1024 subdir = ERR_PTR(-ENOMEM);
1028 /* Was the subdir added while we dropped the lock? */
1029 subdir = find_subdir(dir, name, namelen);
1030 if (!IS_ERR(subdir))
1032 if (PTR_ERR(subdir) != -ENOENT)
1035 /* Nope. Use the our freshly made directory entry. */
1036 err = insert_header(dir, &new->header);
1037 subdir = ERR_PTR(err);
1042 subdir->header.nreg++;
1044 if (IS_ERR(subdir)) {
1045 pr_err("sysctl could not get directory: ");
1046 sysctl_print_dir(dir);
1047 pr_cont("%*.*s %ld\n", namelen, namelen, name,
1050 drop_sysctl_table(&dir->header);
1052 drop_sysctl_table(&new->header);
1053 spin_unlock(&sysctl_lock);
1057 static struct ctl_dir *xlate_dir(struct ctl_table_set *set, struct ctl_dir *dir)
1059 struct ctl_dir *parent;
1060 const char *procname;
1061 if (!dir->header.parent)
1063 parent = xlate_dir(set, dir->header.parent);
1066 procname = dir->header.ctl_table[0].procname;
1067 return find_subdir(parent, procname, strlen(procname));
1070 static int sysctl_follow_link(struct ctl_table_header **phead,
1071 struct ctl_table **pentry)
1073 struct ctl_table_header *head;
1074 struct ctl_table_root *root;
1075 struct ctl_table_set *set;
1076 struct ctl_table *entry;
1077 struct ctl_dir *dir;
1080 spin_lock(&sysctl_lock);
1081 root = (*pentry)->data;
1082 set = lookup_header_set(root);
1083 dir = xlate_dir(set, (*phead)->parent);
1087 const char *procname = (*pentry)->procname;
1089 entry = find_entry(&head, dir, procname, strlen(procname));
1091 if (entry && use_table(head)) {
1092 unuse_table(*phead);
1099 spin_unlock(&sysctl_lock);
1103 static int sysctl_err(const char *path, struct ctl_table *table, char *fmt, ...)
1105 struct va_format vaf;
1108 va_start(args, fmt);
1112 pr_err("sysctl table check failed: %s/%s %pV\n",
1113 path, table->procname, &vaf);
1119 static int sysctl_check_table_array(const char *path, struct ctl_table *table)
1123 if ((table->proc_handler == proc_douintvec) ||
1124 (table->proc_handler == proc_douintvec_minmax)) {
1125 if (table->maxlen != sizeof(unsigned int))
1126 err |= sysctl_err(path, table, "array not allowed");
1129 if (table->proc_handler == proc_dou8vec_minmax) {
1130 if (table->maxlen != sizeof(u8))
1131 err |= sysctl_err(path, table, "array not allowed");
1137 static int sysctl_check_table(const char *path, struct ctl_table *table)
1139 struct ctl_table *entry;
1141 list_for_each_table_entry(entry, table) {
1143 err |= sysctl_err(path, entry, "Not a file");
1145 if ((entry->proc_handler == proc_dostring) ||
1146 (entry->proc_handler == proc_dointvec) ||
1147 (entry->proc_handler == proc_douintvec) ||
1148 (entry->proc_handler == proc_douintvec_minmax) ||
1149 (entry->proc_handler == proc_dointvec_minmax) ||
1150 (entry->proc_handler == proc_dou8vec_minmax) ||
1151 (entry->proc_handler == proc_dointvec_jiffies) ||
1152 (entry->proc_handler == proc_dointvec_userhz_jiffies) ||
1153 (entry->proc_handler == proc_dointvec_ms_jiffies) ||
1154 (entry->proc_handler == proc_doulongvec_minmax) ||
1155 (entry->proc_handler == proc_doulongvec_ms_jiffies_minmax)) {
1157 err |= sysctl_err(path, entry, "No data");
1159 err |= sysctl_err(path, entry, "No maxlen");
1161 err |= sysctl_check_table_array(path, entry);
1163 if (!entry->proc_handler)
1164 err |= sysctl_err(path, entry, "No proc_handler");
1166 if ((entry->mode & (S_IRUGO|S_IWUGO)) != entry->mode)
1167 err |= sysctl_err(path, entry, "bogus .mode 0%o",
1173 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
1174 struct ctl_table_root *link_root)
1176 struct ctl_table *link_table, *entry, *link;
1177 struct ctl_table_header *links;
1178 struct ctl_node *node;
1180 int nr_entries, name_bytes;
1184 list_for_each_table_entry(entry, table) {
1186 name_bytes += strlen(entry->procname) + 1;
1189 links = kzalloc(sizeof(struct ctl_table_header) +
1190 sizeof(struct ctl_node)*nr_entries +
1191 sizeof(struct ctl_table)*(nr_entries + 1) +
1198 node = (struct ctl_node *)(links + 1);
1199 link_table = (struct ctl_table *)(node + nr_entries);
1200 link_name = (char *)&link_table[nr_entries + 1];
1203 list_for_each_table_entry(entry, table) {
1204 int len = strlen(entry->procname) + 1;
1205 memcpy(link_name, entry->procname, len);
1206 link->procname = link_name;
1207 link->mode = S_IFLNK|S_IRWXUGO;
1208 link->data = link_root;
1212 init_header(links, dir->header.root, dir->header.set, node, link_table);
1213 links->nreg = nr_entries;
1218 static bool get_links(struct ctl_dir *dir,
1219 struct ctl_table *table, struct ctl_table_root *link_root)
1221 struct ctl_table_header *head;
1222 struct ctl_table *entry, *link;
1224 /* Are there links available for every entry in table? */
1225 list_for_each_table_entry(entry, table) {
1226 const char *procname = entry->procname;
1227 link = find_entry(&head, dir, procname, strlen(procname));
1230 if (S_ISDIR(link->mode) && S_ISDIR(entry->mode))
1232 if (S_ISLNK(link->mode) && (link->data == link_root))
1237 /* The checks passed. Increase the registration count on the links */
1238 list_for_each_table_entry(entry, table) {
1239 const char *procname = entry->procname;
1240 link = find_entry(&head, dir, procname, strlen(procname));
1246 static int insert_links(struct ctl_table_header *head)
1248 struct ctl_table_set *root_set = &sysctl_table_root.default_set;
1249 struct ctl_dir *core_parent = NULL;
1250 struct ctl_table_header *links;
1253 if (head->set == root_set)
1256 core_parent = xlate_dir(root_set, head->parent);
1257 if (IS_ERR(core_parent))
1260 if (get_links(core_parent, head->ctl_table, head->root))
1263 core_parent->header.nreg++;
1264 spin_unlock(&sysctl_lock);
1266 links = new_links(core_parent, head->ctl_table, head->root);
1268 spin_lock(&sysctl_lock);
1274 if (get_links(core_parent, head->ctl_table, head->root)) {
1279 err = insert_header(core_parent, links);
1283 drop_sysctl_table(&core_parent->header);
1288 * __register_sysctl_table - register a leaf sysctl table
1289 * @set: Sysctl tree to register on
1290 * @path: The path to the directory the sysctl table is in.
1291 * @table: the top-level table structure
1293 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1294 * array. A completely 0 filled entry terminates the table.
1296 * The members of the &struct ctl_table structure are used as follows:
1298 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1299 * enter a sysctl file
1301 * data - a pointer to data for use by proc_handler
1303 * maxlen - the maximum size in bytes of the data
1305 * mode - the file permissions for the /proc/sys file
1307 * child - must be %NULL.
1309 * proc_handler - the text handler routine (described below)
1311 * extra1, extra2 - extra pointers usable by the proc handler routines
1313 * Leaf nodes in the sysctl tree will be represented by a single file
1314 * under /proc; non-leaf nodes will be represented by directories.
1316 * There must be a proc_handler routine for any terminal nodes.
1317 * Several default handlers are available to cover common cases -
1319 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1320 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1321 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1323 * It is the handler's job to read the input buffer from user memory
1324 * and process it. The handler should return 0 on success.
1326 * This routine returns %NULL on a failure to register, and a pointer
1327 * to the table header on success.
1329 struct ctl_table_header *__register_sysctl_table(
1330 struct ctl_table_set *set,
1331 const char *path, struct ctl_table *table)
1333 struct ctl_table_root *root = set->dir.header.root;
1334 struct ctl_table_header *header;
1335 const char *name, *nextname;
1336 struct ctl_dir *dir;
1337 struct ctl_table *entry;
1338 struct ctl_node *node;
1341 list_for_each_table_entry(entry, table)
1344 header = kzalloc(sizeof(struct ctl_table_header) +
1345 sizeof(struct ctl_node)*nr_entries, GFP_KERNEL_ACCOUNT);
1349 node = (struct ctl_node *)(header + 1);
1350 init_header(header, root, set, node, table);
1351 if (sysctl_check_table(path, table))
1354 spin_lock(&sysctl_lock);
1356 /* Reference moved down the diretory tree get_subdir */
1358 spin_unlock(&sysctl_lock);
1360 /* Find the directory for the ctl_table */
1361 for (name = path; name; name = nextname) {
1363 nextname = strchr(name, '/');
1365 namelen = nextname - name;
1368 namelen = strlen(name);
1373 dir = get_subdir(dir, name, namelen);
1378 spin_lock(&sysctl_lock);
1379 if (insert_header(dir, header))
1380 goto fail_put_dir_locked;
1382 drop_sysctl_table(&dir->header);
1383 spin_unlock(&sysctl_lock);
1387 fail_put_dir_locked:
1388 drop_sysctl_table(&dir->header);
1389 spin_unlock(&sysctl_lock);
1397 * register_sysctl - register a sysctl table
1398 * @path: The path to the directory the sysctl table is in.
1399 * @table: the table structure
1401 * Register a sysctl table. @table should be a filled in ctl_table
1402 * array. A completely 0 filled entry terminates the table.
1404 * See __register_sysctl_table for more details.
1406 struct ctl_table_header *register_sysctl(const char *path, struct ctl_table *table)
1408 return __register_sysctl_table(&sysctl_table_root.default_set,
1411 EXPORT_SYMBOL(register_sysctl);
1414 * __register_sysctl_init() - register sysctl table to path
1415 * @path: path name for sysctl base
1416 * @table: This is the sysctl table that needs to be registered to the path
1417 * @table_name: The name of sysctl table, only used for log printing when
1418 * registration fails
1420 * The sysctl interface is used by userspace to query or modify at runtime
1421 * a predefined value set on a variable. These variables however have default
1422 * values pre-set. Code which depends on these variables will always work even
1423 * if register_sysctl() fails. If register_sysctl() fails you'd just loose the
1424 * ability to query or modify the sysctls dynamically at run time. Chances of
1425 * register_sysctl() failing on init are extremely low, and so for both reasons
1426 * this function does not return any error as it is used by initialization code.
1428 * Context: Can only be called after your respective sysctl base path has been
1429 * registered. So for instance, most base directories are registered early on
1430 * init before init levels are processed through proc_sys_init() and
1431 * sysctl_init_bases().
1433 void __init __register_sysctl_init(const char *path, struct ctl_table *table,
1434 const char *table_name)
1436 struct ctl_table_header *hdr = register_sysctl(path, table);
1438 if (unlikely(!hdr)) {
1439 pr_err("failed when register_sysctl %s to %s\n", table_name, path);
1442 kmemleak_not_leak(hdr);
1445 static char *append_path(const char *path, char *pos, const char *name)
1448 namelen = strlen(name);
1449 if (((pos - path) + namelen + 2) >= PATH_MAX)
1451 memcpy(pos, name, namelen);
1453 pos[namelen + 1] = '\0';
1458 static int count_subheaders(struct ctl_table *table)
1461 int nr_subheaders = 0;
1462 struct ctl_table *entry;
1464 /* special case: no directory and empty directory */
1465 if (!table || !table->procname)
1468 list_for_each_table_entry(entry, table) {
1470 nr_subheaders += count_subheaders(entry->child);
1474 return nr_subheaders + has_files;
1477 static int register_leaf_sysctl_tables(const char *path, char *pos,
1478 struct ctl_table_header ***subheader, struct ctl_table_set *set,
1479 struct ctl_table *table)
1481 struct ctl_table *ctl_table_arg = NULL;
1482 struct ctl_table *entry, *files;
1487 list_for_each_table_entry(entry, table) {
1495 /* If there are mixed files and directories we need a new table */
1496 if (nr_dirs && nr_files) {
1497 struct ctl_table *new;
1498 files = kcalloc(nr_files + 1, sizeof(struct ctl_table),
1503 ctl_table_arg = files;
1506 list_for_each_table_entry(entry, table) {
1514 /* Register everything except a directory full of subdirectories */
1515 if (nr_files || !nr_dirs) {
1516 struct ctl_table_header *header;
1517 header = __register_sysctl_table(set, path, files);
1519 kfree(ctl_table_arg);
1523 /* Remember if we need to free the file table */
1524 header->ctl_table_arg = ctl_table_arg;
1525 **subheader = header;
1529 /* Recurse into the subdirectories. */
1530 list_for_each_table_entry(entry, table) {
1536 err = -ENAMETOOLONG;
1537 child_pos = append_path(path, pos, entry->procname);
1541 err = register_leaf_sysctl_tables(path, child_pos, subheader,
1549 /* On failure our caller will unregister all registered subheaders */
1554 * __register_sysctl_paths - register a sysctl table hierarchy
1555 * @set: Sysctl tree to register on
1556 * @path: The path to the directory the sysctl table is in.
1557 * @table: the top-level table structure
1559 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1560 * array. A completely 0 filled entry terminates the table.
1562 * See __register_sysctl_table for more details.
1564 struct ctl_table_header *__register_sysctl_paths(
1565 struct ctl_table_set *set,
1566 const struct ctl_path *path, struct ctl_table *table)
1568 struct ctl_table *ctl_table_arg = table;
1569 int nr_subheaders = count_subheaders(table);
1570 struct ctl_table_header *header = NULL, **subheaders, **subheader;
1571 const struct ctl_path *component;
1572 char *new_path, *pos;
1574 pos = new_path = kmalloc(PATH_MAX, GFP_KERNEL);
1579 for (component = path; component->procname; component++) {
1580 pos = append_path(new_path, pos, component->procname);
1584 while (table->procname && table->child && !table[1].procname) {
1585 pos = append_path(new_path, pos, table->procname);
1588 table = table->child;
1590 if (nr_subheaders == 1) {
1591 header = __register_sysctl_table(set, new_path, table);
1593 header->ctl_table_arg = ctl_table_arg;
1595 header = kzalloc(sizeof(*header) +
1596 sizeof(*subheaders)*nr_subheaders, GFP_KERNEL);
1600 subheaders = (struct ctl_table_header **) (header + 1);
1601 subheader = subheaders;
1602 header->ctl_table_arg = ctl_table_arg;
1604 if (register_leaf_sysctl_tables(new_path, pos, &subheader,
1606 goto err_register_leaves;
1613 err_register_leaves:
1614 while (subheader > subheaders) {
1615 struct ctl_table_header *subh = *(--subheader);
1616 struct ctl_table *table = subh->ctl_table_arg;
1617 unregister_sysctl_table(subh);
1626 * register_sysctl_paths - register a sysctl table hierarchy
1627 * @path: The path to the directory the sysctl table is in.
1628 * @table: the top-level table structure
1630 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1631 * array. A completely 0 filled entry terminates the table.
1633 * See __register_sysctl_paths for more details.
1635 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1636 struct ctl_table *table)
1638 return __register_sysctl_paths(&sysctl_table_root.default_set,
1641 EXPORT_SYMBOL(register_sysctl_paths);
1644 * register_sysctl_table - register a sysctl table hierarchy
1645 * @table: the top-level table structure
1647 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1648 * array. A completely 0 filled entry terminates the table.
1650 * See register_sysctl_paths for more details.
1652 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1654 static const struct ctl_path null_path[] = { {} };
1656 return register_sysctl_paths(null_path, table);
1658 EXPORT_SYMBOL(register_sysctl_table);
1660 int __register_sysctl_base(struct ctl_table *base_table)
1662 struct ctl_table_header *hdr;
1664 hdr = register_sysctl_table(base_table);
1665 kmemleak_not_leak(hdr);
1669 static void put_links(struct ctl_table_header *header)
1671 struct ctl_table_set *root_set = &sysctl_table_root.default_set;
1672 struct ctl_table_root *root = header->root;
1673 struct ctl_dir *parent = header->parent;
1674 struct ctl_dir *core_parent;
1675 struct ctl_table *entry;
1677 if (header->set == root_set)
1680 core_parent = xlate_dir(root_set, parent);
1681 if (IS_ERR(core_parent))
1684 list_for_each_table_entry(entry, header->ctl_table) {
1685 struct ctl_table_header *link_head;
1686 struct ctl_table *link;
1687 const char *name = entry->procname;
1689 link = find_entry(&link_head, core_parent, name, strlen(name));
1691 ((S_ISDIR(link->mode) && S_ISDIR(entry->mode)) ||
1692 (S_ISLNK(link->mode) && (link->data == root)))) {
1693 drop_sysctl_table(link_head);
1696 pr_err("sysctl link missing during unregister: ");
1697 sysctl_print_dir(parent);
1698 pr_cont("%s\n", name);
1703 static void drop_sysctl_table(struct ctl_table_header *header)
1705 struct ctl_dir *parent = header->parent;
1712 start_unregistering(header);
1715 if (!--header->count)
1716 kfree_rcu(header, rcu);
1719 drop_sysctl_table(&parent->header);
1723 * unregister_sysctl_table - unregister a sysctl table hierarchy
1724 * @header: the header returned from register_sysctl_table
1726 * Unregisters the sysctl table and all children. proc entries may not
1727 * actually be removed until they are no longer used by anyone.
1729 void unregister_sysctl_table(struct ctl_table_header * header)
1737 nr_subheaders = count_subheaders(header->ctl_table_arg);
1738 if (unlikely(nr_subheaders > 1)) {
1739 struct ctl_table_header **subheaders;
1742 subheaders = (struct ctl_table_header **)(header + 1);
1743 for (i = nr_subheaders -1; i >= 0; i--) {
1744 struct ctl_table_header *subh = subheaders[i];
1745 struct ctl_table *table = subh->ctl_table_arg;
1746 unregister_sysctl_table(subh);
1753 spin_lock(&sysctl_lock);
1754 drop_sysctl_table(header);
1755 spin_unlock(&sysctl_lock);
1757 EXPORT_SYMBOL(unregister_sysctl_table);
1759 void setup_sysctl_set(struct ctl_table_set *set,
1760 struct ctl_table_root *root,
1761 int (*is_seen)(struct ctl_table_set *))
1763 memset(set, 0, sizeof(*set));
1764 set->is_seen = is_seen;
1765 init_header(&set->dir.header, root, set, NULL, root_table);
1768 void retire_sysctl_set(struct ctl_table_set *set)
1770 WARN_ON(!RB_EMPTY_ROOT(&set->dir.root));
1773 int __init proc_sys_init(void)
1775 struct proc_dir_entry *proc_sys_root;
1777 proc_sys_root = proc_mkdir("sys", NULL);
1778 proc_sys_root->proc_iops = &proc_sys_dir_operations;
1779 proc_sys_root->proc_dir_ops = &proc_sys_dir_file_operations;
1780 proc_sys_root->nlink = 0;
1782 return sysctl_init_bases();
1785 struct sysctl_alias {
1786 const char *kernel_param;
1787 const char *sysctl_param;
1791 * Historically some settings had both sysctl and a command line parameter.
1792 * With the generic sysctl. parameter support, we can handle them at a single
1793 * place and only keep the historical name for compatibility. This is not meant
1794 * to add brand new aliases. When adding existing aliases, consider whether
1795 * the possibly different moment of changing the value (e.g. from early_param
1796 * to the moment do_sysctl_args() is called) is an issue for the specific
1799 static const struct sysctl_alias sysctl_aliases[] = {
1800 {"hardlockup_all_cpu_backtrace", "kernel.hardlockup_all_cpu_backtrace" },
1801 {"hung_task_panic", "kernel.hung_task_panic" },
1802 {"numa_zonelist_order", "vm.numa_zonelist_order" },
1803 {"softlockup_all_cpu_backtrace", "kernel.softlockup_all_cpu_backtrace" },
1804 {"softlockup_panic", "kernel.softlockup_panic" },
1808 static const char *sysctl_find_alias(char *param)
1810 const struct sysctl_alias *alias;
1812 for (alias = &sysctl_aliases[0]; alias->kernel_param != NULL; alias++) {
1813 if (strcmp(alias->kernel_param, param) == 0)
1814 return alias->sysctl_param;
1820 /* Set sysctl value passed on kernel command line. */
1821 static int process_sysctl_arg(char *param, char *val,
1822 const char *unused, void *arg)
1825 struct vfsmount **proc_mnt = arg;
1826 struct file_system_type *proc_fs_type;
1833 if (strncmp(param, "sysctl", sizeof("sysctl") - 1) == 0) {
1834 param += sizeof("sysctl") - 1;
1836 if (param[0] != '/' && param[0] != '.')
1841 param = (char *) sysctl_find_alias(param);
1853 * To set sysctl options, we use a temporary mount of proc, look up the
1854 * respective sys/ file and write to it. To avoid mounting it when no
1855 * options were given, we mount it only when the first sysctl option is
1856 * found. Why not a persistent mount? There are problems with a
1857 * persistent mount of proc in that it forces userspace not to use any
1858 * proc mount options.
1861 proc_fs_type = get_fs_type("proc");
1862 if (!proc_fs_type) {
1863 pr_err("Failed to find procfs to set sysctl from command line\n");
1866 *proc_mnt = kern_mount(proc_fs_type);
1867 put_filesystem(proc_fs_type);
1868 if (IS_ERR(*proc_mnt)) {
1869 pr_err("Failed to mount procfs to set sysctl from command line\n");
1874 path = kasprintf(GFP_KERNEL, "sys/%s", param);
1876 panic("%s: Failed to allocate path for %s\n", __func__, param);
1877 strreplace(path, '.', '/');
1879 file = file_open_root_mnt(*proc_mnt, path, O_WRONLY, 0);
1881 err = PTR_ERR(file);
1883 pr_err("Failed to set sysctl parameter '%s=%s': parameter not found\n",
1885 else if (err == -EACCES)
1886 pr_err("Failed to set sysctl parameter '%s=%s': permission denied (read-only?)\n",
1889 pr_err("Error %pe opening proc file to set sysctl parameter '%s=%s'\n",
1893 wret = kernel_write(file, val, len, &pos);
1897 pr_err("Failed to set sysctl parameter '%s=%s': invalid value\n",
1900 pr_err("Error %pe writing to proc file to set sysctl parameter '%s=%s'\n",
1901 ERR_PTR(err), param, val);
1902 } else if (wret != len) {
1903 pr_err("Wrote only %zd bytes of %d writing to proc file %s to set sysctl parameter '%s=%s\n",
1904 wret, len, path, param, val);
1907 err = filp_close(file, NULL);
1909 pr_err("Error %pe closing proc file to set sysctl parameter '%s=%s\n",
1910 ERR_PTR(err), param, val);
1916 void do_sysctl_args(void)
1919 struct vfsmount *proc_mnt = NULL;
1921 command_line = kstrdup(saved_command_line, GFP_KERNEL);
1923 panic("%s: Failed to allocate copy of command line\n", __func__);
1925 parse_args("Setting sysctl args", command_line,
1926 NULL, 0, -1, -1, &proc_mnt, process_sysctl_arg);
1929 kern_unmount(proc_mnt);
1931 kfree(command_line);