History

procfs: use an enum for possible hidepid values

Previously, the hidepid parameter was checked by comparing literal integers 0, 1, 2. Let's add a proper enum for this, to make the checking more expressive: 0 → HIDEPID_OFF 1 → HIDEPID_NO_ACCESS 2 → HIDEPID_INVISIBLE This changes the internal labelling only, the userspace-facing interface remains unmodified, and still works with literal integers 0, 1, 2. No functional changes.

Lafcadio Wluiki committed 9 years ago

Commit 796f5711 parent a0a07b84 files · +13 −6Browse files

Unified · Split

4 files
  1. fs/proc/base.c +4 −4
  2. fs/proc/inode.c +1 −1
  3. fs/proc/root.c +2 −1
  4. include/linux/pid_namespace.h +6 −0
fs/proc/base.c+4−4
@@ -697,11 +697,11 @@ static int proc_pid_permission(struct inode *inode, int mask) · 696 unmodified lines
697 task = get_proc_task(inode);697 task = get_proc_task(inode);
698 if (!task)698 if (!task)
699 return -ESRCH;699 return -ESRCH;
700 has_perms = has_pid_permissions(pid, task, 1);700 has_perms = has_pid_permissions(pid, task, HIDEPID_NO_ACCESS);
701 put_task_struct(task);701 put_task_struct(task);
702 702
703 if (!has_perms) {703 if (!has_perms) {
704 if (pid->hide_pid == 2) {704 if (pid->hide_pid == HIDEPID_INVISIBLE) {
705 /*705 /*
706 * Let's make getdents(), stat(), and open()706 * Let's make getdents(), stat(), and open()
707 * consistent with each other. If a process707 * consistent with each other. If a process
@@ -1737,7 +1737,7 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) · 1029 unmodified lines
1737 stat->gid = GLOBAL_ROOT_GID;1737 stat->gid = GLOBAL_ROOT_GID;
1738 task = pid_task(proc_pid(inode), PIDTYPE_PID);1738 task = pid_task(proc_pid(inode), PIDTYPE_PID);
1739 if (task) {1739 if (task) {
1740 if (!has_pid_permissions(pid, task, 2)) {1740 if (!has_pid_permissions(pid, task, HIDEPID_INVISIBLE)) {
1741 rcu_read_unlock();1741 rcu_read_unlock();
1742 /*1742 /*
1743 * This doesn't prevent learning whether PID exists,1743 * This doesn't prevent learning whether PID exists,
@@ -3168,7 +3168,7 @@ int proc_pid_readdir(struct file *file, struct dir_context *ctx) · 1424 unmodified lines
3168 int len;3168 int len;
3169 3169
3170 cond_resched();3170 cond_resched();
3171 if (!has_pid_permissions(ns, iter.task, 2))3171 if (!has_pid_permissions(ns, iter.task, HIDEPID_INVISIBLE))
3172 continue;3172 continue;
3173 3173
3174 len = snprintf(name, sizeof(name), "%d", iter.tgid);3174 len = snprintf(name, sizeof(name), "%d", iter.tgid);
fs/proc/inode.c+1−1
@@ -107,7 +107,7 @@ static int proc_show_options(struct seq_file *seq, struct dentry *root) · 106 unmodified lines
107 107
108 if (!gid_eq(pid->pid_gid, GLOBAL_ROOT_GID))108 if (!gid_eq(pid->pid_gid, GLOBAL_ROOT_GID))
109 seq_printf(seq, ",gid=%u", from_kgid_munged(&init_user_ns, pid->pid_gid));109 seq_printf(seq, ",gid=%u", from_kgid_munged(&init_user_ns, pid->pid_gid));
110 if (pid->hide_pid != 0)110 if (pid->hide_pid != HIDEPID_OFF)
111 seq_printf(seq, ",hidepid=%u", pid->hide_pid);111 seq_printf(seq, ",hidepid=%u", pid->hide_pid);
112 112
113 return 0;113 return 0;
fs/proc/root.c+2−1
@@ -58,7 +58,8 @@ int proc_parse_options(char *options, struct pid_namespace *pid) · 57 unmodified lines
58 case Opt_hidepid:58 case Opt_hidepid:
59 if (match_int(&args[0], &option))59 if (match_int(&args[0], &option))
60 return 0;60 return 0;
61 if (option < 0 || option > 2) {61 if (option < HIDEPID_OFF ||
62 option > HIDEPID_INVISIBLE) {
62 pr_err("proc: hidepid value must be between 0 and 2.\n");63 pr_err("proc: hidepid value must be between 0 and 2.\n");
63 return 0;64 return 0;
64 }65 }
include/linux/pid_namespace.h+6−0
@@ -21,6 +21,12 @@ struct pidmap { · 20 unmodified lines
21 21
22struct fs_pin;22struct fs_pin;
23 23
24enum { /* definitions for pid_namespace's hide_pid field */
25 HIDEPID_OFF = 0,
26 HIDEPID_NO_ACCESS = 1,
27 HIDEPID_INVISIBLE = 2,
28};
29
24struct pid_namespace {30struct pid_namespace {
25 struct kref kref;31 struct kref kref;
26 struct pidmap pidmap[PIDMAP_ENTRIES];32 struct pidmap pidmap[PIDMAP_ENTRIES];