public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fs: load FS modules before pinning the mountpoint
@ 2014-11-13 14:14 David Herrmann
  2014-11-13 14:43 ` Al Viro
  0 siblings, 1 reply; 2+ messages in thread
From: David Herrmann @ 2014-11-13 14:14 UTC (permalink / raw)
  To: linux-fsdevel, Alexander Viro, torvalds; +Cc: linux-kernel, David Herrmann

Several pseudo file-systems create default mountpoints in /sys/fs/ or
/sys/kernel/, including:
    /sys/kernel/debug
    /sys/fs/mqueue
    /sys/fs/cgroup
    /sys/fs/pstore

If the given pseudo file-system is available as a module, user-space can
rely on mount(2) to load the module on-demand (assuming MODULE_ALIAS_FS).
However, in case the default mount-point is created by the file-system
itself, mount(2) will fail as it cannot pin the mountpoint.

This patch makes mount(2) load any requested file-systems before pinning
the target mount-point. This way, a file-system module can create default
mount-points in the module instead of creating them statically in the
core kernel.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
---
 fs/namespace.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/fs/namespace.c b/fs/namespace.c
index 5b66b2b..b1dc9f8 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -2565,6 +2565,7 @@ char *copy_mount_string(const void __user *data)
 long do_mount(const char *dev_name, const char __user *dir_name,
 		const char *type_page, unsigned long flags, void *data_page)
 {
+	struct file_system_type *fstype = NULL;
 	struct path path;
 	int retval = 0;
 	int mnt_flags = 0;
@@ -2577,10 +2578,15 @@ long do_mount(const char *dev_name, const char __user *dir_name,
 	if (data_page)
 		((char *)data_page)[PAGE_SIZE - 1] = 0;
 
+	/* load fs-modules before pinning the mountpoint */
+	if (type_page && !(flags & (MS_REMOUNT|MS_BIND|MS_MOVE|MS_SHARED|
+				    MS_PRIVATE|MS_SLAVE|MS_UNBINDABLE)))
+		fstype = get_fs_type(type_page);
+
 	/* ... and get the mountpoint */
 	retval = user_path(dir_name, &path);
 	if (retval)
-		return retval;
+		goto putfs_out;
 
 	retval = security_sb_mount(dev_name, &path,
 				   type_page, flags, data_page);
@@ -2635,6 +2641,9 @@ long do_mount(const char *dev_name, const char __user *dir_name,
 				      dev_name, data_page);
 dput_out:
 	path_put(&path);
+putfs_out:
+	if (fstype)
+		put_filesystem(fstype);
 	return retval;
 }
 
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] fs: load FS modules before pinning the mountpoint
  2014-11-13 14:14 [PATCH] fs: load FS modules before pinning the mountpoint David Herrmann
@ 2014-11-13 14:43 ` Al Viro
  0 siblings, 0 replies; 2+ messages in thread
From: Al Viro @ 2014-11-13 14:43 UTC (permalink / raw)
  To: David Herrmann; +Cc: linux-fsdevel, torvalds, linux-kernel

On Thu, Nov 13, 2014 at 03:14:33PM +0100, David Herrmann wrote:
> Several pseudo file-systems create default mountpoints in /sys/fs/ or
> /sys/kernel/, including:
>     /sys/kernel/debug
>     /sys/fs/mqueue
>     /sys/fs/cgroup
>     /sys/fs/pstore
> 
> If the given pseudo file-system is available as a module, user-space can
> rely on mount(2) to load the module on-demand (assuming MODULE_ALIAS_FS).
> However, in case the default mount-point is created by the file-system
> itself, mount(2) will fail as it cannot pin the mountpoint.
> 
> This patch makes mount(2) load any requested file-systems before pinning
> the target mount-point. This way, a file-system module can create default
> mount-points in the module instead of creating them statically in the
> core kernel.

I'm not taking that until I see a module that would attempt to do such
mountpoint creation *and* managed to get it race-free.

Besides, I really don't like the way you do this lookup only to never use
the result other than for pinning the damn module.  But that's secondary -
the main issue is with the amount of fun races in the whole "let module
create that default mountpoint" approach.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-11-13 14:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-13 14:14 [PATCH] fs: load FS modules before pinning the mountpoint David Herrmann
2014-11-13 14:43 ` Al Viro

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox