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
697697 task = get_proc_task(inode);
698698 if (!task)
699699 return -ESRCH;
700− has_perms = has_pid_permissions(pid, task, 1);
700+ has_perms = has_pid_permissions(pid, task, HIDEPID_NO_ACCESS);
701701 put_task_struct(task);
702702
703703 if (!has_perms) {
704− if (pid->hide_pid == 2) {
704+ if (pid->hide_pid == HIDEPID_INVISIBLE) {
705705 /*
706706 * Let's make getdents(), stat(), and open()
707707 * 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
17371737 stat->gid = GLOBAL_ROOT_GID;
17381738 task = pid_task(proc_pid(inode), PIDTYPE_PID);
17391739 if (task) {
1740− if (!has_pid_permissions(pid, task, 2)) {
1740+ if (!has_pid_permissions(pid, task, HIDEPID_INVISIBLE)) {
17411741 rcu_read_unlock();
17421742 /*
17431743 * 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
31683168 int len;
31693169
31703170 cond_resched();
3171− if (!has_pid_permissions(ns, iter.task, 2))
3171+ if (!has_pid_permissions(ns, iter.task, HIDEPID_INVISIBLE))
31723172 continue;
31733173
31743174 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
107107
108108 if (!gid_eq(pid->pid_gid, GLOBAL_ROOT_GID))
109109 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)
111111 seq_printf(seq, ",hidepid=%u", pid->hide_pid);
112112
113113 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
5858 case Opt_hidepid:
5959 if (match_int(&args[0], &option))
6060 return 0;
61− if (option < 0 || option > 2) {
61+ if (option < HIDEPID_OFF ||
62+ option > HIDEPID_INVISIBLE) {
6263 pr_err("proc: hidepid value must be between 0 and 2.\n");
6364 return 0;
6465 }
include/linux/pid_namespace.h+6−0
@@ -21,6 +21,12 @@ struct pidmap { · 20 unmodified lines
2121
2222 struct fs_pin;
2323
24+enum { /* definitions for pid_namespace's hide_pid field */
25+ HIDEPID_OFF = 0,
26+ HIDEPID_NO_ACCESS = 1,
27+ HIDEPID_INVISIBLE = 2,
28+};
29+
2430 struct pid_namespace {
2531 struct kref kref;
2632 struct pidmap pidmap[PIDMAP_ENTRIES];