* [PATCH -mm 7/9] unshare system call : allow unsharing of namespace
@ 2005-12-13 3:00 JANAK DESAI
2005-12-13 13:52 ` Al Viro
0 siblings, 1 reply; 5+ messages in thread
From: JANAK DESAI @ 2005-12-13 3:00 UTC (permalink / raw)
To: viro, chrisw, dwmw2, jamie, serue, mingo, linuxram, jmorris, sds, janak
Cc: akpm, linux-kernel
[PATCH -mm 7/9] unshare system call: allow unsharing of namespace
fs/namespace.c | 55
++++++++++++++++++++++++++++++----------------
include/linux/namespace.h | 1
kernel/fork.c | 16 +++++++++----
3 files changed, 48 insertions(+), 24 deletions(-)
diff -Naurp 2.6.15-rc5-mm2+patch/fs/namespace.c
2.6.15-rc5-mm2+patch7/fs/namespace.c
--- 2.6.15-rc5-mm2+patch/fs/namespace.c 2005-12-12 18:27:20.000000000
+0000
+++ 2.6.15-rc5-mm2+patch7/fs/namespace.c 2005-12-12 22:01:00.000000000
+0000
@@ -1314,7 +1314,11 @@ dput_out:
return retval;
}
-int copy_namespace(int flags, struct task_struct *tsk)
+/*
+ * Allocate a new namespace structure and populate it with contents
+ * copied from the namespace of the passed in task structure.
+ */
+struct namespace *dup_namespace(struct task_struct *tsk)
{
struct namespace *namespace = tsk->namespace;
struct namespace *new_ns;
@@ -1322,19 +1326,6 @@ int copy_namespace(int flags, struct tas
struct fs_struct *fs = tsk->fs;
struct vfsmount *p, *q;
- if (!namespace)
- return 0;
-
- get_namespace(namespace);
-
- if (!(flags & CLONE_NEWNS))
- return 0;
-
- if (!capable(CAP_SYS_ADMIN)) {
- put_namespace(namespace);
- return -EPERM;
- }
-
new_ns = kmalloc(sizeof(struct namespace), GFP_KERNEL);
if (!new_ns)
goto out;
@@ -1385,8 +1376,6 @@ int copy_namespace(int flags, struct tas
}
up_write(&namespace_sem);
- tsk->namespace = new_ns;
-
if (rootmnt)
mntput(rootmnt);
if (pwdmnt)
@@ -1394,12 +1383,40 @@ int copy_namespace(int flags, struct tas
if (altrootmnt)
mntput(altrootmnt);
- put_namespace(namespace);
- return 0;
+out:
+ return new_ns;
+}
+
+int copy_namespace(int flags, struct task_struct *tsk)
+{
+ struct namespace *namespace = tsk->namespace;
+ struct namespace *new_ns;
+ int err = 0;
+
+ if (!namespace)
+ return 0;
+
+ get_namespace(namespace);
+
+ if (!(flags & CLONE_NEWNS))
+ return 0;
+
+ if (!capable(CAP_SYS_ADMIN)) {
+ err = -EPERM;
+ goto out;
+ }
+
+ new_ns = dup_namespace(tsk);
+ if (!new_ns) {
+ err = -ENOMEM;
+ goto out;
+ }
+
+ tsk->namespace = new_ns;
out:
put_namespace(namespace);
- return -ENOMEM;
+ return err;
}
asmlinkage long sys_mount(char __user * dev_name, char __user *
dir_name,
diff -Naurp 2.6.15-rc5-mm2+patch/include/linux/namespace.h
2.6.15-rc5-mm2+patch7/include/linux/namespace.h
--- 2.6.15-rc5-mm2+patch/include/linux/namespace.h 2005-12-12
18:27:38.000000000 +0000
+++ 2.6.15-rc5-mm2+patch7/include/linux/namespace.h 2005-12-12
22:01:57.000000000 +0000
@@ -15,6 +15,7 @@ struct namespace {
extern int copy_namespace(int, struct task_struct *);
extern void __put_namespace(struct namespace *namespace);
+extern struct namespace *dup_namespace(struct task_struct *);
static inline void put_namespace(struct namespace *namespace)
{
diff -Naurp 2.6.15-rc5-mm2+patch/kernel/fork.c
2.6.15-rc5-mm2+patch7/kernel/fork.c
--- 2.6.15-rc5-mm2+patch/kernel/fork.c 2005-12-12 19:31:48.000000000
+0000
+++ 2.6.15-rc5-mm2+patch7/kernel/fork.c 2005-12-12 21:58:44.000000000
+0000
@@ -1392,16 +1392,22 @@ static int unshare_fs(unsigned long unsh
}
/*
- * Unsharing of namespace for tasks created without CLONE_NEWNS is not
- * supported yet
+ * Unshare the namespace structure if it is being shared
*/
static int unshare_namespace(unsigned long unshare_flags, struct
namespace **new_nsp)
{
- struct namespace *ns = current->namespace;
+ struct namespace *ns = current->namespace, *new_ns;
if ((unshare_flags & CLONE_NEWNS) &&
- (ns && atomic_read(&ns->count) > 1))
- return -EINVAL;
+ (ns && atomic_read(&ns->count) > 1)) {
+ if (!capable(CAP_SYS_ADMIN))
+ return -EPERM;
+
+ new_ns = dup_namespace(current);
+ if (!new_ns)
+ return -ENOMEM;
+ *new_nsp = new_ns;
+ }
return 0;
}
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH -mm 7/9] unshare system call : allow unsharing of namespace
2005-12-13 3:00 [PATCH -mm 7/9] unshare system call : allow unsharing of namespace JANAK DESAI
@ 2005-12-13 13:52 ` Al Viro
2005-12-13 14:11 ` JANAK DESAI
0 siblings, 1 reply; 5+ messages in thread
From: Al Viro @ 2005-12-13 13:52 UTC (permalink / raw)
To: JANAK DESAI
Cc: chrisw, dwmw2, jamie, serue, mingo, linuxram, jmorris, sds, akpm,
linux-kernel
On Mon, Dec 12, 2005 at 10:00:09PM -0500, JANAK DESAI wrote:
>
> [PATCH -mm 7/9] unshare system call: allow unsharing of namespace
You need a pointer to new fs_struct, since that's what will be modified.
As it is, you are modifying ->root, etc. of old fs_struct, which is OK
only when it's not shared.
What you need is to pass new_fs ? new_fs : current->fs as a separate
argument to your dup_namespace().
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH -mm 7/9] unshare system call : allow unsharing of namespace
2005-12-13 13:52 ` Al Viro
@ 2005-12-13 14:11 ` JANAK DESAI
0 siblings, 0 replies; 5+ messages in thread
From: JANAK DESAI @ 2005-12-13 14:11 UTC (permalink / raw)
To: Al Viro
Cc: chrisw, dwmw2, jamie, serue, mingo, linuxram, jmorris, sds, akpm,
linux-kernel
Al Viro wrote:
>On Mon, Dec 12, 2005 at 10:00:09PM -0500, JANAK DESAI wrote:
>
>
>>[PATCH -mm 7/9] unshare system call: allow unsharing of namespace
>>
>>
>
>You need a pointer to new fs_struct, since that's what will be modified.
>As it is, you are modifying ->root, etc. of old fs_struct, which is OK
>only when it's not shared.
>
> What you need is to pass new_fs ? new_fs : current->fs as a separate
>argument to your dup_namespace().
>-
>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/
>
>
>
>
Thanks. I will make all the changes as per your feedback, re-test and
resubmit the
series later today.
-Janak
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH -mm 7/9] unshare system call: allow unsharing of namespace
@ 2005-12-13 22:54 JANAK DESAI
0 siblings, 0 replies; 5+ messages in thread
From: JANAK DESAI @ 2005-12-13 22:54 UTC (permalink / raw)
To: viro, chrisw, dwmw2, jamie, serue, mingo, linuxram, jmorris, sds, janak
Cc: akpm, linux-kernel
[PATCH -mm 7/9] unshare system call: allow unsharing of namespace
If the namespace structure is being shared, allocate a new one and
copy information from the current, shared, structure.
Changes since the first submission of this patch on 12/12/05:
- Removed an unnecessary local variable. Fixed dup_namespace()
to update the correct filesystem structure (12/13/05)
Signed-off-by: Janak Desai <janak@us.ibm.com>
---
fs/namespace.c | 56 +++++++++++++++++++++++++++++-----------------
include/linux/namespace.h | 1
kernel/fork.c | 17 +++++++++----
3 files changed, 48 insertions(+), 26 deletions(-)
diff -Naurp 2.6.15-rc5-mm2+patch/fs/namespace.c 2.6.15-rc5-mm2+patch7/fs/namespace.c
--- 2.6.15-rc5-mm2+patch/fs/namespace.c 2005-12-12 18:27:20.000000000 +0000
+++ 2.6.15-rc5-mm2+patch7/fs/namespace.c 2005-12-13 19:15:17.000000000 +0000
@@ -1314,27 +1314,17 @@ dput_out:
return retval;
}
-int copy_namespace(int flags, struct task_struct *tsk)
+/*
+ * Allocate a new namespace structure and populate it with contents
+ * copied from the namespace of the passed in task structure.
+ */
+struct namespace *dup_namespace(struct task_struct *tsk, struct fs_struct *fs)
{
struct namespace *namespace = tsk->namespace;
struct namespace *new_ns;
struct vfsmount *rootmnt = NULL, *pwdmnt = NULL, *altrootmnt = NULL;
- struct fs_struct *fs = tsk->fs;
struct vfsmount *p, *q;
- if (!namespace)
- return 0;
-
- get_namespace(namespace);
-
- if (!(flags & CLONE_NEWNS))
- return 0;
-
- if (!capable(CAP_SYS_ADMIN)) {
- put_namespace(namespace);
- return -EPERM;
- }
-
new_ns = kmalloc(sizeof(struct namespace), GFP_KERNEL);
if (!new_ns)
goto out;
@@ -1385,8 +1375,6 @@ int copy_namespace(int flags, struct tas
}
up_write(&namespace_sem);
- tsk->namespace = new_ns;
-
if (rootmnt)
mntput(rootmnt);
if (pwdmnt)
@@ -1394,12 +1382,40 @@ int copy_namespace(int flags, struct tas
if (altrootmnt)
mntput(altrootmnt);
- put_namespace(namespace);
- return 0;
+out:
+ return new_ns;
+}
+
+int copy_namespace(int flags, struct task_struct *tsk)
+{
+ struct namespace *namespace = tsk->namespace;
+ struct namespace *new_ns;
+ int err = 0;
+
+ if (!namespace)
+ return 0;
+
+ get_namespace(namespace);
+
+ if (!(flags & CLONE_NEWNS))
+ return 0;
+
+ if (!capable(CAP_SYS_ADMIN)) {
+ err = -EPERM;
+ goto out;
+ }
+
+ new_ns = dup_namespace(tsk, tsk->fs);
+ if (!new_ns) {
+ err = -ENOMEM;
+ goto out;
+ }
+
+ tsk->namespace = new_ns;
out:
put_namespace(namespace);
- return -ENOMEM;
+ return err;
}
asmlinkage long sys_mount(char __user * dev_name, char __user * dir_name,
diff -Naurp 2.6.15-rc5-mm2+patch/include/linux/namespace.h 2.6.15-rc5-mm2+patch7/include/linux/namespace.h
--- 2.6.15-rc5-mm2+patch/include/linux/namespace.h 2005-12-12 18:27:38.000000000 +0000
+++ 2.6.15-rc5-mm2+patch7/include/linux/namespace.h 2005-12-13 19:13:34.000000000 +0000
@@ -15,6 +15,7 @@ struct namespace {
extern int copy_namespace(int, struct task_struct *);
extern void __put_namespace(struct namespace *namespace);
+extern struct namespace *dup_namespace(struct task_struct *, struct fs_struct *);
static inline void put_namespace(struct namespace *namespace)
{
diff -Naurp 2.6.15-rc5-mm2+patch/kernel/fork.c 2.6.15-rc5-mm2+patch7/kernel/fork.c
--- 2.6.15-rc5-mm2+patch/kernel/fork.c 2005-12-13 18:38:26.000000000 +0000
+++ 2.6.15-rc5-mm2+patch7/kernel/fork.c 2005-12-13 19:39:15.000000000 +0000
@@ -1392,16 +1392,21 @@ static int unshare_fs(unsigned long unsh
}
/*
- * Unsharing of namespace for tasks created without CLONE_NEWNS is not
- * supported yet
+ * Unshare the namespace structure if it is being shared
*/
-static int unshare_namespace(unsigned long unshare_flags, struct namespace **new_nsp)
+static int unshare_namespace(unsigned long unshare_flags, struct namespace **new_nsp, struct fs_struct *new_fs)
{
struct namespace *ns = current->namespace;
if ((unshare_flags & CLONE_NEWNS) &&
- (ns && atomic_read(&ns->count) > 1))
- return -EINVAL;
+ (ns && atomic_read(&ns->count) > 1)) {
+ if (!capable(CAP_SYS_ADMIN))
+ return -EPERM;
+
+ *new_nsp = dup_namespace(current, new_fs ? new_fs : current->fs);
+ if (!*new_nsp)
+ return -ENOMEM;
+ }
return 0;
}
@@ -1486,7 +1491,7 @@ asmlinkage long sys_unshare(unsigned lon
goto bad_unshare_out;
if ((err = unshare_fs(unshare_flags, &new_fs)))
goto bad_unshare_cleanup_thread;
- if ((err = unshare_namespace(unshare_flags, &new_ns)))
+ if ((err = unshare_namespace(unshare_flags, &new_ns, new_fs)))
goto bad_unshare_cleanup_fs;
if ((err = unshare_sighand(unshare_flags, &new_sigh)))
goto bad_unshare_cleanup_ns;
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH -mm 7/9] unshare system call : allow unsharing of namespace
@ 2005-12-13 13:43 JANAK DESAI
0 siblings, 0 replies; 5+ messages in thread
From: JANAK DESAI @ 2005-12-13 13:43 UTC (permalink / raw)
To: viro, chrisw, dwmw2, jamie, serue, mingo, linuxram, jmorris, sds, janak
Cc: akpm, linux-kernel
[PATCH -mm 7/9] unshare system call: allow unsharing of namespace
fs/namespace.c | 55 ++++++++++++++++++++++++++++++----------------
include/linux/namespace.h | 1
kernel/fork.c | 16 +++++++++----
3 files changed, 48 insertions(+), 24 deletions(-)
diff -Naurp 2.6.15-rc5-mm2+patch/fs/namespace.c 2.6.15-rc5-mm2+patch7/fs/namespace.c
--- 2.6.15-rc5-mm2+patch/fs/namespace.c 2005-12-12 18:27:20.000000000 +0000
+++ 2.6.15-rc5-mm2+patch7/fs/namespace.c 2005-12-12 22:01:00.000000000 +0000
@@ -1314,7 +1314,11 @@ dput_out:
return retval;
}
-int copy_namespace(int flags, struct task_struct *tsk)
+/*
+ * Allocate a new namespace structure and populate it with contents
+ * copied from the namespace of the passed in task structure.
+ */
+struct namespace *dup_namespace(struct task_struct *tsk)
{
struct namespace *namespace = tsk->namespace;
struct namespace *new_ns;
@@ -1322,19 +1326,6 @@ int copy_namespace(int flags, struct tas
struct fs_struct *fs = tsk->fs;
struct vfsmount *p, *q;
- if (!namespace)
- return 0;
-
- get_namespace(namespace);
-
- if (!(flags & CLONE_NEWNS))
- return 0;
-
- if (!capable(CAP_SYS_ADMIN)) {
- put_namespace(namespace);
- return -EPERM;
- }
-
new_ns = kmalloc(sizeof(struct namespace), GFP_KERNEL);
if (!new_ns)
goto out;
@@ -1385,8 +1376,6 @@ int copy_namespace(int flags, struct tas
}
up_write(&namespace_sem);
- tsk->namespace = new_ns;
-
if (rootmnt)
mntput(rootmnt);
if (pwdmnt)
@@ -1394,12 +1383,40 @@ int copy_namespace(int flags, struct tas
if (altrootmnt)
mntput(altrootmnt);
- put_namespace(namespace);
- return 0;
+out:
+ return new_ns;
+}
+
+int copy_namespace(int flags, struct task_struct *tsk)
+{
+ struct namespace *namespace = tsk->namespace;
+ struct namespace *new_ns;
+ int err = 0;
+
+ if (!namespace)
+ return 0;
+
+ get_namespace(namespace);
+
+ if (!(flags & CLONE_NEWNS))
+ return 0;
+
+ if (!capable(CAP_SYS_ADMIN)) {
+ err = -EPERM;
+ goto out;
+ }
+
+ new_ns = dup_namespace(tsk);
+ if (!new_ns) {
+ err = -ENOMEM;
+ goto out;
+ }
+
+ tsk->namespace = new_ns;
out:
put_namespace(namespace);
- return -ENOMEM;
+ return err;
}
asmlinkage long sys_mount(char __user * dev_name, char __user * dir_name,
diff -Naurp 2.6.15-rc5-mm2+patch/include/linux/namespace.h 2.6.15-rc5-mm2+patch7/include/linux/namespace.h
--- 2.6.15-rc5-mm2+patch/include/linux/namespace.h 2005-12-12 18:27:38.000000000 +0000
+++ 2.6.15-rc5-mm2+patch7/include/linux/namespace.h 2005-12-12 22:01:57.000000000 +0000
@@ -15,6 +15,7 @@ struct namespace {
extern int copy_namespace(int, struct task_struct *);
extern void __put_namespace(struct namespace *namespace);
+extern struct namespace *dup_namespace(struct task_struct *);
static inline void put_namespace(struct namespace *namespace)
{
diff -Naurp 2.6.15-rc5-mm2+patch/kernel/fork.c 2.6.15-rc5-mm2+patch7/kernel/fork.c
--- 2.6.15-rc5-mm2+patch/kernel/fork.c 2005-12-12 19:31:48.000000000 +0000
+++ 2.6.15-rc5-mm2+patch7/kernel/fork.c 2005-12-12 21:58:44.000000000 +0000
@@ -1392,16 +1392,22 @@ static int unshare_fs(unsigned long unsh
}
/*
- * Unsharing of namespace for tasks created without CLONE_NEWNS is not
- * supported yet
+ * Unshare the namespace structure if it is being shared
*/
static int unshare_namespace(unsigned long unshare_flags, struct namespace **new_nsp)
{
- struct namespace *ns = current->namespace;
+ struct namespace *ns = current->namespace, *new_ns;
if ((unshare_flags & CLONE_NEWNS) &&
- (ns && atomic_read(&ns->count) > 1))
- return -EINVAL;
+ (ns && atomic_read(&ns->count) > 1)) {
+ if (!capable(CAP_SYS_ADMIN))
+ return -EPERM;
+
+ new_ns = dup_namespace(current);
+ if (!new_ns)
+ return -ENOMEM;
+ *new_nsp = new_ns;
+ }
return 0;
}
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2005-12-13 22:57 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-13 3:00 [PATCH -mm 7/9] unshare system call : allow unsharing of namespace JANAK DESAI
2005-12-13 13:52 ` Al Viro
2005-12-13 14:11 ` JANAK DESAI
2005-12-13 13:43 JANAK DESAI
2005-12-13 22:54 [PATCH -mm 7/9] unshare system call: " JANAK DESAI
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.