All of lore.kernel.org
 help / color / mirror / Atom feed
From: Djalal Harouni <tixxdz@gmail.com>
To: linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Kees Cook <keescook@chromium.org>,
	Lafcadio Wluiki <wluikil@gmail.com>,
	Djalal Harouni <tixxdz@gmail.com>
Subject: [PATCH v4 1/2] procfs: use an enum for possible hidepid values
Date: Mon, 16 Jan 2017 14:23:03 +0100	[thread overview]
Message-ID: <1484572984-13388-2-git-send-email-djalal@gmail.com> (raw)
In-Reply-To: <1484572984-13388-1-git-send-email-djalal@gmail.com>

From: Lafcadio Wluiki <wluikil@gmail.com>

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.

Acked-by: Kees Cook <keescook@chromium.org>
Acked-by: Djalal Harouni <tixxdz@gmail.com>
Signed-off-by: Lafcadio Wluiki <wluikil@gmail.com>
---
 fs/proc/base.c                | 8 ++++----
 fs/proc/inode.c               | 2 +-
 fs/proc/root.c                | 3 ++-
 include/linux/pid_namespace.h | 6 ++++++
 4 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index 8e7e61b..cd8dd15 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -729,11 +729,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
@@ -1725,7 +1725,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,
@@ -3179,7 +3179,7 @@ int proc_pid_readdir(struct file *file, struct dir_context *ctx)
 	     iter.tgid += 1, iter = next_tgid(ns, iter)) {
 		char name[PROC_NUMBUF];
 		int len;
-		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);
diff --git a/fs/proc/inode.c b/fs/proc/inode.c
index 842a5ff..5d9bafb 100644
--- a/fs/proc/inode.c
+++ b/fs/proc/inode.c
@@ -106,7 +106,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;
diff --git a/fs/proc/root.c b/fs/proc/root.c
index 1988440..b90da88 100644
--- a/fs/proc/root.c
+++ b/fs/proc/root.c
@@ -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;
 			}
diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
index 34cce96..c2a989d 100644
--- a/include/linux/pid_namespace.h
+++ b/include/linux/pid_namespace.h
@@ -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];
-- 
2.5.5

WARNING: multiple messages have this Message-ID (diff)
From: Djalal Harouni <tixxdz@gmail.com>
To: linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Kees Cook <keescook@chromium.org>,
	Lafcadio Wluiki <wluikil@gmail.com>,
	Djalal Harouni <tixxdz@gmail.com>
Subject: [kernel-hardening] [PATCH v4 1/2] procfs: use an enum for possible hidepid values
Date: Mon, 16 Jan 2017 14:23:03 +0100	[thread overview]
Message-ID: <1484572984-13388-2-git-send-email-djalal@gmail.com> (raw)
In-Reply-To: <1484572984-13388-1-git-send-email-djalal@gmail.com>

From: Lafcadio Wluiki <wluikil@gmail.com>

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.

Acked-by: Kees Cook <keescook@chromium.org>
Acked-by: Djalal Harouni <tixxdz@gmail.com>
Signed-off-by: Lafcadio Wluiki <wluikil@gmail.com>
---
 fs/proc/base.c                | 8 ++++----
 fs/proc/inode.c               | 2 +-
 fs/proc/root.c                | 3 ++-
 include/linux/pid_namespace.h | 6 ++++++
 4 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index 8e7e61b..cd8dd15 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -729,11 +729,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
@@ -1725,7 +1725,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,
@@ -3179,7 +3179,7 @@ int proc_pid_readdir(struct file *file, struct dir_context *ctx)
 	     iter.tgid += 1, iter = next_tgid(ns, iter)) {
 		char name[PROC_NUMBUF];
 		int len;
-		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);
diff --git a/fs/proc/inode.c b/fs/proc/inode.c
index 842a5ff..5d9bafb 100644
--- a/fs/proc/inode.c
+++ b/fs/proc/inode.c
@@ -106,7 +106,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;
diff --git a/fs/proc/root.c b/fs/proc/root.c
index 1988440..b90da88 100644
--- a/fs/proc/root.c
+++ b/fs/proc/root.c
@@ -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;
 			}
diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
index 34cce96..c2a989d 100644
--- a/include/linux/pid_namespace.h
+++ b/include/linux/pid_namespace.h
@@ -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];
-- 
2.5.5

  reply	other threads:[~2017-01-16 13:23 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-16 13:23 [PATCH v4 0/2] procfs/tasks: introduce per-task procfs hidepid= field Djalal Harouni
2017-01-16 13:23 ` [kernel-hardening] " Djalal Harouni
2017-01-16 13:23 ` Djalal Harouni [this message]
2017-01-16 13:23   ` [kernel-hardening] [PATCH v4 1/2] procfs: use an enum for possible hidepid values Djalal Harouni
2017-02-13 22:16   ` Kees Cook
2017-02-13 22:16     ` [kernel-hardening] " Kees Cook
2017-02-15  0:34     ` Andrew Morton
2017-02-15  0:34       ` [kernel-hardening] " Andrew Morton
2017-02-15  8:56       ` Djalal Harouni
2017-02-15  8:56         ` [kernel-hardening] " Djalal Harouni
2017-01-16 13:23 ` [PATCH v4 2/2] procfs/tasks: add a simple per-task procfs hidepid= field Djalal Harouni
2017-01-16 13:23   ` [kernel-hardening] " Djalal Harouni
2017-01-16 17:12   ` Djalal Harouni
2017-01-16 17:12     ` [kernel-hardening] " Djalal Harouni
     [not found]   ` <1484572984-13388-3-git-send-email-djalal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-01-16 17:15     ` Djalal Harouni
     [not found]       ` <CAEiveUfDvSoW9Hy2Y_uxU2YQ+vR8OvXMqRhxAANTGG7QaQbJeg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-01-17 20:33         ` Andy Lutomirski
2017-01-18 22:50           ` Djalal Harouni
2017-01-18 22:50             ` [kernel-hardening] " Djalal Harouni
2017-01-18 23:35             ` Andy Lutomirski
2017-01-18 23:35               ` [kernel-hardening] " Andy Lutomirski
2017-01-18 23:35               ` Andy Lutomirski
2017-01-19 13:53               ` Djalal Harouni
2017-01-19 13:53                 ` [kernel-hardening] " Djalal Harouni
2017-01-19 13:53                 ` Djalal Harouni
2017-01-19 19:52                 ` Andy Lutomirski
2017-01-19 19:52                   ` [kernel-hardening] " Andy Lutomirski
2017-01-19 19:52                   ` Andy Lutomirski
2017-01-20 15:56                   ` Lafcadio Wluiki
2017-01-20 15:56                     ` [kernel-hardening] " Lafcadio Wluiki
2017-01-20 15:56                     ` Lafcadio Wluiki
2017-01-20 16:33                   ` Djalal Harouni
2017-01-20 16:33                     ` [kernel-hardening] " Djalal Harouni
2017-01-20 16:33                     ` Djalal Harouni
2017-01-21  0:53                     ` Andy Lutomirski
2017-01-21  0:53                       ` [kernel-hardening] " Andy Lutomirski
2017-01-21  0:53                       ` Andy Lutomirski
2017-01-23 11:46                       ` Djalal Harouni
2017-01-23 11:46                         ` [kernel-hardening] " Djalal Harouni
2017-01-23 11:46                         ` Djalal Harouni
2017-01-23 20:07                         ` Andy Lutomirski
2017-01-23 20:07                           ` [kernel-hardening] " Andy Lutomirski
2017-01-23 20:07                           ` Andy Lutomirski
2017-01-26 13:20                           ` Djalal Harouni
2017-01-26 13:20                             ` [kernel-hardening] " Djalal Harouni
2017-01-26 13:20                             ` Djalal Harouni
2017-02-10 14:40                       ` Lafcadio Wluiki
2017-02-10 14:40                         ` [kernel-hardening] " Lafcadio Wluiki
2017-02-10 14:40                         ` Lafcadio Wluiki
2017-02-10 16:18                         ` Andy Lutomirski
2017-02-10 16:18                           ` [kernel-hardening] " Andy Lutomirski
2017-02-10 16:18                           ` Andy Lutomirski
2017-01-20 15:44               ` Lafcadio Wluiki
2017-01-20 15:44                 ` [kernel-hardening] " Lafcadio Wluiki
2017-01-20 15:44                 ` Lafcadio Wluiki
2017-02-10 23:44               ` Kees Cook
2017-02-10 23:44                 ` [kernel-hardening] " Kees Cook
2017-02-10 23:44                 ` Kees Cook
2017-02-13 19:01                 ` Andy Lutomirski
2017-02-13 19:01                   ` [kernel-hardening] " Andy Lutomirski
2017-02-13 19:01                   ` Andy Lutomirski
2017-02-13 19:15                   ` Kees Cook
2017-02-13 19:15                     ` [kernel-hardening] " Kees Cook
2017-02-13 19:15                     ` Kees Cook
2017-02-14  4:11                     ` Christian Kujau
2017-02-14  4:11                       ` [kernel-hardening] " Christian Kujau
2017-02-14  4:11                       ` Christian Kujau
2017-01-16 18:24   ` [kernel-hardening] " Daniel Micay
2017-01-17  9:54     ` Lafcadio Wluiki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1484572984-13388-2-git-send-email-djalal@gmail.com \
    --to=tixxdz@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=keescook@chromium.org \
    --cc=kernel-hardening@lists.openwall.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=wluikil@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.