lkml.org 
[lkml]   [2005]   [May]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
SubjectRe: [PATCH] namespace.c: fix bind mount from foreign namespace
From
Date
> Ok. less restriction without compromising security is a good idea.
>
> Under the premise that bind mounts across namespace should be allowed;
> any insight why the "founding fathers" :) allowed only bind
> and not recursive bind? What issue would that create? One can
> easily workaround that restriction by manually binding recursively.
> So does the recursive bind restriction serve any purpose?
>
> I remember Miklos saying its not a security issue but a
> implementation/locking issue. That can be fixed aswell.

Yes, as pointed out by Jamie, both namespaces need to be locked for
this to work. Something like the attached should do it.

Miklos


Index: linux/fs/namespace.c
===================================================================
--- linux.orig/fs/namespace.c 2005-05-16 22:02:36.000000000 +0200
+++ linux/fs/namespace.c 2005-05-16 22:13:30.000000000 +0200
@@ -622,6 +622,8 @@ out_unlock:
static int do_loopback(struct nameidata *nd, char *old_name, int recurse)
{
struct nameidata old_nd;
+ struct namespace *ns1 = current->namespace;
+ struct namespace *ns2 = NULL;
struct vfsmount *mnt = NULL;
int err = mount_is_safe(nd);
if (err)
@@ -632,15 +634,30 @@ static int do_loopback(struct nameidata
if (err)
return err;

- down_write(&current->namespace->sem);
err = -EINVAL;
- if (check_mnt(nd->mnt) && (!recurse || check_mnt(old_nd.mnt))) {
- err = -ENOMEM;
- if (recurse)
- mnt = copy_tree(old_nd.mnt, old_nd.dentry);
- else
- mnt = clone_mnt(old_nd.mnt, old_nd.dentry);
- }
+ if (!check_mnt(nd->mnt))
+ goto out_path_release;
+
+ if (recurse && old_nd.mnt->mnt_namespace != ns1) {
+ ns2 = old_nd.mnt->mnt_namespace;
+ if (ns1 < ns2) {
+ down_write(&ns1->sem);
+ down_write(&ns2->sem);
+ } else {
+ down_write(&ns2->sem);
+ down_write(&ns1->sem);
+ }
+ } else
+ down_write(&ns1->sem);
+
+ err = -ENOMEM;
+ if (recurse)
+ mnt = copy_tree(old_nd.mnt, old_nd.dentry);
+ else
+ mnt = clone_mnt(old_nd.mnt, old_nd.dentry);
+
+ if (ns2)
+ up_write(&ns2->sem);

if (mnt) {
/* stop bind mounts from expiring */
@@ -657,7 +674,8 @@ static int do_loopback(struct nameidata
mntput(mnt);
}

- up_write(&current->namespace->sem);
+ up_write(&ns1->sem);
+out_path_release:
path_release(&old_nd);
return err;
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
\
 
 \ /
  Last update: 2005-05-16 22:32    [from the cache]
©2003-2014 Jasper Spaans. Advertise on this site