Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.

Link: http://lkml.kernel.org/r/1484572984-13388-2-git-send-email-djalal@gmail.com
Signed-off-by: Lafcadio Wluiki <wluikil@gmail.com>
Signed-off-by: Djalal Harouni <tixxdz@gmail.com>
Acked-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Lafcadio Wluiki and committed by
Linus Torvalds
796f571b a0a07b87

+13 -6
+4 -4
fs/proc/base.c
··· 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 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 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);
+1 -1
fs/proc/inode.c
··· 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;
+2 -1
fs/proc/root.c
··· 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 }
+6
include/linux/pid_namespace.h
··· 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];