LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Dave Hansen <haveblue@us.ibm.com>
To: linux-kernel@vger.kernel.org
Cc: hch@lst.de, miklos@szeredi.hu, akpm@osdl.org,
	Dave Hansen <haveblue@us.ibm.com>
Subject: [PATCH 27/30] r/o bind mounts: get callers of vfs_mknod/create()
Date: Fri, 15 Feb 2008 14:37:57 -0800	[thread overview]
Message-ID: <20080215223757.26182C0D@kernel> (raw)
In-Reply-To: <20080215223721.9E0A088A@kernel>


This takes care of all of the direct callers of vfs_mknod().
Since a few of these cases also handle normal file creation
as well, this also covers some calls to vfs_create().

So that we don't have to make three mnt_want/drop_write()
calls inside of the switch statement, we move some of its
logic outside of the switch and into a helper function
suggested by Christoph.

This also encapsulates a fix for mknod(S_IFREG) that Miklos
found.

Acked-by: Al Viro <viro@ZenIV.linux.org.uk>
Signed-off-by: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Dave Hansen <haveblue@us.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 linux-2.6.git-dave/fs/namei.c         |   43 +++++++++++++++++++++++++---------
 linux-2.6.git-dave/fs/nfsd/vfs.c      |    4 +++
 linux-2.6.git-dave/net/unix/af_unix.c |    4 +++
 3 files changed, 40 insertions(+), 11 deletions(-)

diff -puN fs/namei.c~r-o-bind-mounts-sys_mknodat-elevate-write-count-for-vfs_mknod-create fs/namei.c
--- linux-2.6.git/fs/namei.c~r-o-bind-mounts-sys_mknodat-elevate-write-count-for-vfs_mknod-create	2008-02-15 13:25:58.000000000 -0800
+++ linux-2.6.git-dave/fs/namei.c	2008-02-15 13:25:58.000000000 -0800
@@ -2038,6 +2038,23 @@ int vfs_mknod(struct inode *dir, struct 
 	return error;
 }
 
+static int may_mknod(mode_t mode)
+{
+	switch (mode & S_IFMT) {
+	case S_IFREG:
+	case S_IFCHR:
+	case S_IFBLK:
+	case S_IFIFO:
+	case S_IFSOCK:
+	case 0: /* zero mode translates to S_IFREG */
+		return 0;
+	case S_IFDIR:
+		return -EPERM;
+	default:
+		return -EINVAL;
+	}
+}
+
 asmlinkage long sys_mknodat(int dfd, const char __user *filename, int mode,
 				unsigned dev)
 {
@@ -2056,12 +2073,19 @@ asmlinkage long sys_mknodat(int dfd, con
 	if (error)
 		goto out;
 	dentry = lookup_create(&nd, 0);
-	error = PTR_ERR(dentry);
-
+	if (IS_ERR(dentry)) {
+		error = PTR_ERR(dentry);
+		goto out_unlock;
+	}
 	if (!IS_POSIXACL(nd.path.dentry->d_inode))
 		mode &= ~current->fs->umask;
-	if (!IS_ERR(dentry)) {
-		switch (mode & S_IFMT) {
+	error = may_mknod(mode);
+	if (error)
+		goto out_dput;
+	error = mnt_want_write(nd.path.mnt);
+	if (error)
+		goto out_dput;
+	switch (mode & S_IFMT) {
 		case 0: case S_IFREG:
 			error = vfs_create(nd.path.dentry->d_inode,dentry,mode,&nd);
 			break;
@@ -2072,14 +2096,11 @@ asmlinkage long sys_mknodat(int dfd, con
 		case S_IFIFO: case S_IFSOCK:
 			error = vfs_mknod(nd.path.dentry->d_inode,dentry,mode,0);
 			break;
-		case S_IFDIR:
-			error = -EPERM;
-			break;
-		default:
-			error = -EINVAL;
-		}
-		dput(dentry);
 	}
+	mnt_drop_write(nd.path.mnt);
+out_dput:
+	dput(dentry);
+out_unlock:
 	mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
 	path_put(&nd.path);
 out:
diff -puN fs/nfsd/vfs.c~r-o-bind-mounts-sys_mknodat-elevate-write-count-for-vfs_mknod-create fs/nfsd/vfs.c
--- linux-2.6.git/fs/nfsd/vfs.c~r-o-bind-mounts-sys_mknodat-elevate-write-count-for-vfs_mknod-create	2008-02-15 13:25:58.000000000 -0800
+++ linux-2.6.git-dave/fs/nfsd/vfs.c	2008-02-15 13:25:58.000000000 -0800
@@ -1264,7 +1264,11 @@ nfsd_create(struct svc_rqst *rqstp, stru
 	case S_IFBLK:
 	case S_IFIFO:
 	case S_IFSOCK:
+		host_err = mnt_want_write(fhp->fh_export->ex_mnt);
+		if (host_err)
+			break;
 		host_err = vfs_mknod(dirp, dchild, iap->ia_mode, rdev);
+		mnt_drop_write(fhp->fh_export->ex_mnt);
 		break;
 	default:
 	        printk("nfsd: bad file type %o in nfsd_create\n", type);
diff -puN net/unix/af_unix.c~r-o-bind-mounts-sys_mknodat-elevate-write-count-for-vfs_mknod-create net/unix/af_unix.c
--- linux-2.6.git/net/unix/af_unix.c~r-o-bind-mounts-sys_mknodat-elevate-write-count-for-vfs_mknod-create	2008-02-15 13:25:58.000000000 -0800
+++ linux-2.6.git-dave/net/unix/af_unix.c	2008-02-15 13:25:58.000000000 -0800
@@ -819,7 +819,11 @@ static int unix_bind(struct socket *sock
 		 */
 		mode = S_IFSOCK |
 		       (SOCK_INODE(sock)->i_mode & ~current->fs->umask);
+		err = mnt_want_write(nd.path.mnt);
+		if (err)
+			goto out_mknod_dput;
 		err = vfs_mknod(nd.path.dentry->d_inode, dentry, mode, 0);
+		mnt_drop_write(nd.path.mnt);
 		if (err)
 			goto out_mknod_dput;
 		mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
_

  parent reply	other threads:[~2008-02-15 22:52 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-15 22:37 [PATCH 00/30] Read-only bind mounts (-mm resend) Dave Hansen
2008-02-15 22:37 ` [PATCH 01/30] reiserfs: eliminate private use of struct file in xattr Dave Hansen
2008-02-15 22:37 ` [PATCH 02/30] hppfs pass vfsmount to dentry_open() Dave Hansen
2008-02-15 22:37 ` [PATCH 03/30] check for null vfsmount in dentry_open() Dave Hansen
2008-02-15 22:37 ` [PATCH 04/30] fix up new filp allocators Dave Hansen
2008-02-15 22:37 ` [PATCH 05/30] do namei_flags calculation inside open_namei() Dave Hansen
2008-02-15 22:37 ` [PATCH 06/30] merge open_namei() and do_filp_open() Dave Hansen
2008-02-15 22:37 ` [PATCH 07/30] r/o bind mounts: stub functions Dave Hansen
2008-02-16  0:32   ` Theodore Tso
2008-02-16  0:49     ` Dave Hansen
2008-02-16  1:00       ` Theodore Tso
2008-02-16  1:11         ` Andrew Morton
2008-02-16  6:31           ` Christoph Hellwig
2008-02-16  6:46             ` Andrew Morton
2008-02-18  7:06               ` Dave Hansen
2008-02-20 22:25             ` Dave Hansen
2008-02-20 22:58               ` Christoph Hellwig
2008-02-15 22:37 ` [PATCH 08/30] r/o bind mounts: create helper to drop file write access Dave Hansen
2008-02-15 22:37 ` [PATCH 09/30] r/o bind mounts: drop write during emergency remount Dave Hansen
2008-02-18 16:29   ` Miklos Szeredi
2008-02-23 13:38     ` Al Viro
2008-02-15 22:37 ` [PATCH 10/30] r/o bind mounts: elevate write count for vfs_rmdir() Dave Hansen
2008-02-15 22:37 ` [PATCH 11/30] r/o bind mounts: elevate write count for callers of vfs_mkdir() Dave Hansen
2008-02-15 22:37 ` [PATCH 12/30] r/o bind mounts: elevate mnt_writers for unlink callers Dave Hansen
2008-02-15 22:37 ` [PATCH 13/30] r/o bind mounts: elevate write count for xattr_permission() callers Dave Hansen
2008-02-15 22:37 ` [PATCH 14/30] r/o bind mounts: elevate write count for ncp_ioctl() Dave Hansen
2008-02-15 22:37 ` [PATCH 15/30] r/o bind mounts: write counts for time functions Dave Hansen
2008-02-15 22:37 ` [PATCH 16/30] r/o bind mounts: elevate write count for do_utimes() Dave Hansen
2008-02-15 22:37 ` [PATCH 17/30] r/o bind mounts: write count for file_update_time() Dave Hansen
2008-02-15 22:37 ` [PATCH 18/30] r/o bind mounts: write counts for link/symlink Dave Hansen
2008-02-15 22:37 ` [PATCH 19/30] r/o bind mounts: elevate write count for ioctls() Dave Hansen
2008-02-15 22:37 ` [PATCH 20/30] r/o bind mounts: elevate write count for open()s Dave Hansen
2008-02-15 22:37 ` [PATCH 21/30] r/o bind mounts: get write access for vfs_rename() callers Dave Hansen
2008-02-15 22:37 ` [PATCH 22/30] r/o bind mounts: elevate write count for chmod/chown callers Dave Hansen
2008-02-15 22:37 ` [PATCH 23/30] r/o bind mounts: write counts for truncate() Dave Hansen
2008-02-15 22:37 ` [PATCH 24/30] r/o bind mounts: elevate count for xfs timestamp updates Dave Hansen
2008-02-15 22:37 ` [PATCH 25/30] r/o bind mounts: make access() use new r/o helper Dave Hansen
2008-02-15 22:37 ` [PATCH 26/30] r/o bind mounts: check mnt instead of superblock directly Dave Hansen
2008-02-15 22:37 ` Dave Hansen [this message]
2008-02-15 22:37 ` [PATCH 28/30] r/o bind mounts: track numbers of writers to mounts Dave Hansen
2008-02-18 16:10   ` Miklos Szeredi
2008-02-20 21:12     ` Dave Hansen
2008-02-15 22:38 ` [PATCH 29/30] r/o bind mounts: honor mount writer counts at remount Dave Hansen
2008-02-15 22:38 ` [PATCH 30/30] r/o bind mounts: debugging for missed calls Dave Hansen
2008-02-16  1:32 ` [PATCH] r/o bind mounts: stub functions Dave Hansen

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=20080215223757.26182C0D@kernel \
    --to=haveblue@us.ibm.com \
    --cc=akpm@osdl.org \
    --cc=hch@lst.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --subject='Re: [PATCH 27/30] r/o bind mounts: get callers of vfs_mknod/create()' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).