Skip to content

Commit 4281580

Browse files
author
Christian Brauner
committed
timens: make vdso_join_timens() always succeed
As discussed on-list (cf. [1]), in order to make setns() support time namespaces when attaching to multiple namespaces at once properly we need to tweak vdso_join_timens() to always succeed. So switch vdso_join_timens() to using a read lock and replacing mmap_write_lock_killable() to mmap_read_lock() as we discussed. Last cycle setns() was changed to support attaching to multiple namespaces atomically. This requires all namespaces to have a point of no return where they can't fail anymore. Specifically, <namespace-type>_install() is allowed to perform permission checks and install the namespace into the new struct nsset that it has been given but it is not allowed to make visible changes to the affected task. Once <namespace-type>_install() returns anything that the given namespace type requires to be setup in addition needs to ideally be done in a function that can't fail or if it fails the failure is not fatal. For time namespaces the relevant functions that fall into this category are timens_set_vvar_page() and vdso_join_timens(). Currently the latter can fail but doesn't need to. With this we can go on to implement a timens_commit() helper in a follow up patch to be used by setns(). [1]: https://lore.kernel.org/lkml/20200611110221.pgd3r5qkjrjmfqa2@wittgenstein Signed-off-by: Christian Brauner <[email protected]> Reviewed-by: Andrei Vagin <[email protected]> Cc: Will Deacon <[email protected]> Cc: Vincenzo Frascino <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Dmitry Safonov <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected]
1 parent dcb7fd8 commit 4281580

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed

arch/x86/entry/vdso/vma.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ int vdso_join_timens(struct task_struct *task, struct time_namespace *ns)
144144
struct mm_struct *mm = task->mm;
145145
struct vm_area_struct *vma;
146146

147-
if (mmap_write_lock_killable(mm))
148-
return -EINTR;
147+
mmap_read_lock(mm);
149148

150149
for (vma = mm->mmap; vma; vma = vma->vm_next) {
151150
unsigned long size = vma->vm_end - vma->vm_start;
@@ -154,7 +153,7 @@ int vdso_join_timens(struct task_struct *task, struct time_namespace *ns)
154153
zap_page_range(vma, vma->vm_start, size);
155154
}
156155

157-
mmap_write_unlock(mm);
156+
mmap_read_unlock(mm);
158157
return 0;
159158
}
160159
#else

kernel/time/namespace.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@ static int timens_install(struct nsset *nsset, struct ns_common *new)
284284
{
285285
struct nsproxy *nsproxy = nsset->nsproxy;
286286
struct time_namespace *ns = to_time_ns(new);
287-
int err;
288287

289288
if (!current_is_single_threaded())
290289
return -EUSERS;
@@ -295,9 +294,7 @@ static int timens_install(struct nsset *nsset, struct ns_common *new)
295294

296295
timens_set_vvar_page(current, ns);
297296

298-
err = vdso_join_timens(current, ns);
299-
if (err)
300-
return err;
297+
vdso_join_timens(current, ns);
301298

302299
get_time_ns(ns);
303300
put_time_ns(nsproxy->time_ns);
@@ -313,17 +310,14 @@ int timens_on_fork(struct nsproxy *nsproxy, struct task_struct *tsk)
313310
{
314311
struct ns_common *nsc = &nsproxy->time_ns_for_children->ns;
315312
struct time_namespace *ns = to_time_ns(nsc);
316-
int err;
317313

318314
/* create_new_namespaces() already incremented the ref counter */
319315
if (nsproxy->time_ns == nsproxy->time_ns_for_children)
320316
return 0;
321317

322318
timens_set_vvar_page(tsk, ns);
323319

324-
err = vdso_join_timens(tsk, ns);
325-
if (err)
326-
return err;
320+
vdso_join_timens(tsk, ns);
327321

328322
get_time_ns(ns);
329323
put_time_ns(nsproxy->time_ns);

0 commit comments

Comments
 (0)