mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tejun Heo <htejun@gmail.com>
To: zwane@linuxpower.ca, viro@zeniv.linux.org.uk
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH linux-2.6 03/04] brsem: fix ro-remount <-> open race condition
Date: Sun, 25 Sep 2005 15:43:22 +0900 (KST)	[thread overview]
Message-ID: <20050925064218.367B8B6E@htj.dyndns.org> (raw)
In-Reply-To: <20050925064218.E7558977@htj.dyndns.org>

03_brsem_fix-remount-open-race.patch

	A file can be opened rw while ro-remounting is in progress
	resulting in open rw file on ro mounted filesystem.  This
	patch kills the race by making permission check and the rest
	of open atomic w.r.t. remounting.  Other file operations also
	have this race condition and should be fixed in similar
	manner.

Signed-off-by: Tejun Heo <htejun@gmail.com>

 namei.c |   11 ++++++++++-
 open.c  |   12 ++++++++++--
 2 files changed, 20 insertions(+), 3 deletions(-)

Index: linux-work/fs/namei.c
===================================================================
--- linux-work.orig/fs/namei.c	2005-09-25 15:26:32.000000000 +0900
+++ linux-work/fs/namei.c	2005-09-25 15:42:04.000000000 +0900
@@ -1412,6 +1412,12 @@ int may_open(struct nameidata *nd, int a
  *			  11 - read/write permissions needed
  * which is a lot more logical, and also allows the "no perm" needed
  * for symlinks (where the permissions are checked later).
+ *
+ * nd->mnt->mnt_sb->s_umount brsem is read-locked on successful return
+ * from this function.  This is to make permission checking and the
+ * actual open operation atomic w.r.t. remounting.  The caller must
+ * release s_umount after open is complete.
+ *
  * SMP-safe
  */
 int open_namei(const char * pathname, int flag, int mode, struct nameidata *nd)
@@ -1512,9 +1518,12 @@ do_last:
 	if (path.dentry->d_inode && S_ISDIR(path.dentry->d_inode->i_mode))
 		goto exit;
 ok:
+	brsem_down_read(nd->mnt->mnt_sb->s_umount);
 	error = may_open(nd, acc_mode, flag);
-	if (error)
+	if (error) {
+		brsem_up_read(nd->mnt->mnt_sb->s_umount);
 		goto exit;
+	}
 	return 0;
 
 exit_dput:
Index: linux-work/fs/open.c
===================================================================
--- linux-work.orig/fs/open.c	2005-09-25 15:26:32.000000000 +0900
+++ linux-work/fs/open.c	2005-09-25 15:42:04.000000000 +0900
@@ -828,8 +828,16 @@ struct file *filp_open(const char * file
 		return ERR_PTR(error);
 
 	error = open_namei(filename, namei_flags, mode, &nd);
-	if (!error)
-		return __dentry_open(nd.dentry, nd.mnt, flags, f);
+	if (!error) {
+		f = __dentry_open(nd.dentry, nd.mnt, flags, f);
+		/*
+		 * On successful return from open_namei(), s_umount is
+		 * read-locked, see comment above open_namei() for
+		 * more information.
+		 */
+		brsem_up_read(nd.mnt->mnt_sb->s_umount);
+		return f;
+	}
 
 	put_filp(f);
 	return ERR_PTR(error);


  parent reply	other threads:[~2005-09-25  6:43 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-25  6:43 [PATCH linux-2.6 00/04] brsem: [RFC] big reader semaphore Tejun Heo
2005-09-25  6:43 ` [PATCH linux-2.6 01/04] brsem: implement " Tejun Heo
2005-09-25  7:19   ` Nick Piggin
2005-09-25  8:03     ` Nick Piggin
2005-09-25  8:11     ` Tejun Heo
2005-09-25  8:27       ` Nick Piggin
2005-09-25  8:53         ` Tejun Heo
2005-09-25  9:24           ` Nick Piggin
2005-09-25 10:05             ` Tejun Heo
2005-09-25 11:22               ` Nick Piggin
2005-09-25  6:43 ` [PATCH linux-2.6 02/04] brsem: convert super_block->s_umount to brsem Tejun Heo
2005-09-25  6:43 ` Tejun Heo [this message]
2005-09-25  6:43 ` [PATCH linux-2.6 04/04] brsem: convert cpucontrol " Tejun Heo
2005-09-25  7:39   ` Nick Piggin
2005-09-25  8:03     ` Tejun Heo
2005-09-25 23:46     ` Nathan Lynch
2005-09-26  1:11       ` Nick Piggin
2005-09-26  4:05         ` Tejun Heo

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=20050925064218.367B8B6E@htj.dyndns.org \
    --to=htejun@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=zwane@linuxpower.ca \
    /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

all inboxes | Powered by JetHome®