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.
Unified · Split
| @@ -697,11 +697,11 @@ static int proc_pid_permission(struct inode *inode, int mask) · 696 unmodified lines | ||
| 697 | 697 | task = get_proc_task(inode); |
| 698 | 698 | if (!task) |
| 699 | 699 | return -ESRCH; |
| 700 | − has_perms = has_pid_permissions(pid, task, 1); | |
| 700 | + has_perms = has_pid_permissions(pid, task, HIDEPID_NO_ACCESS); | |
| 701 | 701 | put_task_struct(task); |
| 702 | 702 | |
| 703 | 703 | if (!has_perms) { |
| 704 | − if (pid->hide_pid == 2) { | |
| 704 | + if (pid->hide_pid == HIDEPID_INVISIBLE) { | |
| 705 | 705 | /* |
| 706 | 706 | * Let's make getdents(), stat(), and open() |
| 707 | 707 | * 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 | 1737 | stat->gid = GLOBAL_ROOT_GID; |
| 1738 | 1738 | task = pid_task(proc_pid(inode), PIDTYPE_PID); |
| 1739 | 1739 | if (task) { |
| 1740 | − if (!has_pid_permissions(pid, task, 2)) { | |
| 1740 | + if (!has_pid_permissions(pid, task, HIDEPID_INVISIBLE)) { | |
| 1741 | 1741 | rcu_read_unlock(); |
| 1742 | 1742 | /* |
| 1743 | 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 | 3168 | int len; |
| 3169 | 3169 | |
| 3170 | 3170 | cond_resched(); |
| 3171 | − if (!has_pid_permissions(ns, iter.task, 2)) | |
| 3171 | + if (!has_pid_permissions(ns, iter.task, HIDEPID_INVISIBLE)) | |
| 3172 | 3172 | continue; |
| 3173 | 3173 | |
| 3174 | 3174 | len = snprintf(name, sizeof(name), "%d", iter.tgid); |
| @@ -107,7 +107,7 @@ static int proc_show_options(struct seq_file *seq, struct dentry *root) · 106 unmodified lines | ||
| 107 | 107 | |
| 108 | 108 | if (!gid_eq(pid->pid_gid, GLOBAL_ROOT_GID)) |
| 109 | 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 | 111 | seq_printf(seq, ",hidepid=%u", pid->hide_pid); |
| 112 | 112 | |
| 113 | 113 | return 0; |
| @@ -58,7 +58,8 @@ int proc_parse_options(char *options, struct pid_namespace *pid) · 57 unmodified lines | ||
| 58 | 58 | case Opt_hidepid: |
| 59 | 59 | if (match_int(&args[0], &option)) |
| 60 | 60 | return 0; |
| 61 | − if (option < 0 || option > 2) { | |
| 61 | + if (option < HIDEPID_OFF || | |
| 62 | + option > HIDEPID_INVISIBLE) { | |
| 62 | 63 | pr_err("proc: hidepid value must be between 0 and 2.\n"); |
| 63 | 64 | return 0; |
| 64 | 65 | } |
| @@ -21,6 +21,12 @@ struct pidmap { · 20 unmodified lines | ||
| 21 | 21 | |
| 22 | 22 | struct fs_pin; |
| 23 | 23 | |
| 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 | + | |
| 24 | 30 | struct pid_namespace { |
| 25 | 31 | struct kref kref; |
| 26 | 32 | struct pidmap pidmap[PIDMAP_ENTRIES]; |