public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Vasiliy Kulikov <segoon@openwall.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Valdis.Kletnieks@vt.edu,
	"Arkadiusz Miśkiewicz" <a.miskiewicz@gmail.com>,
	linux-kernel@vger.kernel.org,
	"Alexey Dobriyan" <adobriyan@gmail.com>
Subject: [PATCH] proc: reset mount options after the last procfs umount
Date: Sat, 31 Mar 2012 17:55:20 +0400	[thread overview]
Message-ID: <20120331135520.GB2845@albatros> (raw)
In-Reply-To: <20120326153738.aa728115.akpm@linux-foundation.org>

On Mon, Mar 26, 2012 at 15:37 -0700, Andrew Morton wrote:
> On Sun, 25 Mar 2012 18:23:16 -0400
> Valdis.Kletnieks@vt.edu wrote:
> 
> > Yes, it may be what the code actually *does*, but it certainly violates
> > the Principle of Least Surprise...
> 
> It surprises me ;)  I never noticed that before.
> 
> It does seem pretty insane.  I wonder how much downstream damage would
> result from fixing it.

Resetting options on each mount is implemented in the following patch.
However, I'm stuck with searching a race-free way to learn current
mounts count of this procfs sb.  sget() + atomic_read() is racy:

	(A)				(B)
	mount -t proc			mount -t proc

	sget()				|
	|				sget()
	atomic_read(&sb->s_active)	|
	|				atomic_read(&sb->s_active)

So, it has a theoretical race of reading sb->s_active with 2+ parallel
mounts and both reads will get 3 instead of 2.  Consequently, neither of
mounts will reset mount options.

I wonder whether anybody will try to do such parallel type of things
in reality (IOW, is it OK to leave this race?)

--------------
From: Vasiliy Kulikov <segoon@openwall.com>
Subject: [PATCH] proc: reset mount options after the last procfs umount

The following command sequence leads to wrong mount options setting:

  mount -t proc -o hidepid=1 none /proc
  umount /proc
  mount -t proc none /proc

The second "mount" mounts procfs with old options from the first "mount",
but should use no options.

Fix that by resetting mount options in pid_namespace each time procfs
is mounted in a pid namespace without other procfs mount points.

Note that if one creates second procfs mount point, it should use old
mount options (IOW, reuse first mount point's options).

Signed-off-by: Vasiliy Kulikov <segoon@openwall.com>

--
 fs/proc/root.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

---
diff --git a/fs/proc/root.c b/fs/proc/root.c
index eed44bf..7067a5c 100644
--- a/fs/proc/root.c
+++ b/fs/proc/root.c
@@ -47,6 +47,12 @@ static const match_table_t tokens = {
 	{Opt_err, NULL},
 };
 
+static void proc_reset_options(struct pid_namespace *pid)
+{
+	pid->pid_gid = 0;
+	pid->hide_pid = 0;
+}
+
 static int proc_parse_options(char *options, struct pid_namespace *pid)
 {
 	char *p;
@@ -115,6 +121,9 @@ static struct dentry *proc_mount(struct file_system_type *fs_type,
 	if (IS_ERR(sb))
 		return ERR_CAST(sb);
 
+	if (atomic_read(&sb->s_active) <= 2)
+		proc_reset_options(ns);
+
 	if (!proc_parse_options(options, ns)) {
 		deactivate_locked_super(sb);
 		return ERR_PTR(-EINVAL);
--

-- 
Vasiliy Kulikov
http://www.openwall.com - bringing security into open computing environments

  reply	other threads:[~2012-03-31 13:55 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-22  8:03 3.3 and hidepid feature problem - options not always applied at mount Arkadiusz Miśkiewicz
2012-03-23 17:10 ` [PATCH] proc: fix mount -t proc -o AAA Vasiliy Kulikov
2012-03-23 18:45   ` Arkadiusz Miśkiewicz
2012-03-23 19:18     ` Vasiliy Kulikov
2012-03-23 23:15   ` Andrew Morton
2012-03-25  7:24     ` Arkadiusz Miśkiewicz
2012-03-25 15:36       ` Vasiliy Kulikov
2012-03-25 17:40         ` Arkadiusz Miśkiewicz
2012-03-25 17:49           ` Vasiliy Kulikov
2012-03-25 22:23         ` Valdis.Kletnieks
2012-03-26 22:37           ` Andrew Morton
2012-03-31 13:55             ` Vasiliy Kulikov [this message]
2012-03-31 14:19               ` [PATCH] proc: reset mount options after the last procfs umount Arkadiusz Miśkiewicz
2012-03-31 15:20                 ` Vasiliy Kulikov
2012-03-31 15:31                   ` Arkadiusz Miśkiewicz
2012-03-31 15:46                     ` Vasiliy Kulikov
2012-03-26 22:35       ` [PATCH] proc: fix mount -t proc -o AAA Andrew Morton
2012-03-25 15:27     ` Vasiliy Kulikov
2012-03-31 13:51     ` Vasiliy Kulikov

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=20120331135520.GB2845@albatros \
    --to=segoon@openwall.com \
    --cc=Valdis.Kletnieks@vt.edu \
    --cc=a.miskiewicz@gmail.com \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox