]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
procfs: use an enum for possible hidepid values
authorLafcadio Wluiki <wluikil@gmail.com>
Fri, 24 Feb 2017 23:00:23 +0000 (15:00 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 25 Feb 2017 01:46:56 +0000 (17:46 -0800)
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>
fs/proc/base.c
fs/proc/inode.c
fs/proc/root.c
include/linux/pid_namespace.h

index 4ecb5edc3c612263524b409ed992f4c7e6fd418d..b8f06273353e9fe9b9e3e801fbd9ceff7212ed42 100644 (file)
@@ -697,11 +697,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
        task = get_proc_task(inode);
        if (!task)
                return -ESRCH;
-       has_perms = has_pid_permissions(pid, task, 1);
+       has_perms = has_pid_permissions(pid, task, HIDEPID_NO_ACCESS);
        put_task_struct(task);
 
        if (!has_perms) {
-               if (pid->hide_pid == 2) {
+               if (pid->hide_pid == HIDEPID_INVISIBLE) {
                        /*
                         * Let's make getdents(), stat(), and open()
                         * consistent with each other.  If a process
@@ -1737,7 +1737,7 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
        stat->gid = GLOBAL_ROOT_GID;
        task = pid_task(proc_pid(inode), PIDTYPE_PID);
        if (task) {
-               if (!has_pid_permissions(pid, task, 2)) {
+               if (!has_pid_permissions(pid, task, HIDEPID_INVISIBLE)) {
                        rcu_read_unlock();
                        /*
                         * This doesn't prevent learning whether PID exists,
@@ -3168,7 +3168,7 @@ int proc_pid_readdir(struct file *file, struct dir_context *ctx)
                int len;
 
                cond_resched();
-               if (!has_pid_permissions(ns, iter.task, 2))
+               if (!has_pid_permissions(ns, iter.task, HIDEPID_INVISIBLE))
                        continue;
 
                len = snprintf(name, sizeof(name), "%d", iter.tgid);
index 7ad9ed7958af47a355be9e27ed8501d98d4de0d1..2cc7a8030275c1bc98a0da9adb870b33d99f5433 100644 (file)
@@ -107,7 +107,7 @@ static int proc_show_options(struct seq_file *seq, struct dentry *root)
 
        if (!gid_eq(pid->pid_gid, GLOBAL_ROOT_GID))
                seq_printf(seq, ",gid=%u", from_kgid_munged(&init_user_ns, pid->pid_gid));
-       if (pid->hide_pid != 0)
+       if (pid->hide_pid != HIDEPID_OFF)
                seq_printf(seq, ",hidepid=%u", pid->hide_pid);
 
        return 0;
index 1988440b20496386303daec0190546261131a3b0..b90da888b81a3aed2a64d83b9167ab81036fc452 100644 (file)
@@ -58,7 +58,8 @@ int proc_parse_options(char *options, struct pid_namespace *pid)
                case Opt_hidepid:
                        if (match_int(&args[0], &option))
                                return 0;
-                       if (option < 0 || option > 2) {
+                       if (option < HIDEPID_OFF ||
+                           option > HIDEPID_INVISIBLE) {
                                pr_err("proc: hidepid value must be between 0 and 2.\n");
                                return 0;
                        }
index 34cce96741bc1dfb9966cb8b84da8eb6452464ed..c2a989dee876360d85f305965e34c1dddc0a9c12 100644 (file)
@@ -21,6 +21,12 @@ struct pidmap {
 
 struct fs_pin;
 
+enum { /* definitions for pid_namespace's hide_pid field */
+       HIDEPID_OFF       = 0,
+       HIDEPID_NO_ACCESS = 1,
+       HIDEPID_INVISIBLE = 2,
+};
+
 struct pid_namespace {
        struct kref kref;
        struct pidmap pidmap[PIDMAP_ENTRIES];