Lines Matching +full:ns +full:-
1 // SPDX-License-Identifier: GPL-2.0
30 offset = timespec64_to_ktime(ns_offsets->monotonic); in do_timens_ktime_to_host()
34 offset = timespec64_to_ktime(ns_offsets->boottime); in do_timens_ktime_to_host()
46 * User can specify @tim *absolute* value - if it's lesser than in do_timens_ktime_to_host()
47 * the time namespace's offset - it's already expired. in do_timens_ktime_to_host()
59 static struct ucounts *inc_time_namespaces(struct user_namespace *ns) in inc_time_namespaces() argument
61 return inc_ucount(ns, current_euid(), UCOUNT_TIME_NAMESPACES); in inc_time_namespaces()
70 * clone_time_ns - Clone a time namespace
81 struct time_namespace *ns; in clone_time_ns() local
85 err = -ENOSPC; in clone_time_ns()
90 err = -ENOMEM; in clone_time_ns()
91 ns = kmalloc(sizeof(*ns), GFP_KERNEL_ACCOUNT); in clone_time_ns()
92 if (!ns) in clone_time_ns()
95 refcount_set(&ns->ns.count, 1); in clone_time_ns()
97 ns->vvar_page = alloc_page(GFP_KERNEL_ACCOUNT | __GFP_ZERO); in clone_time_ns()
98 if (!ns->vvar_page) in clone_time_ns()
101 err = ns_alloc_inum(&ns->ns); in clone_time_ns()
105 ns->ucounts = ucounts; in clone_time_ns()
106 ns->ns.ops = &timens_operations; in clone_time_ns()
107 ns->user_ns = get_user_ns(user_ns); in clone_time_ns()
108 ns->offsets = old_ns->offsets; in clone_time_ns()
109 ns->frozen_offsets = false; in clone_time_ns()
110 return ns; in clone_time_ns()
113 __free_page(ns->vvar_page); in clone_time_ns()
115 kfree(ns); in clone_time_ns()
123 * copy_time_ns - Create timens_for_children from @old_ns
160 * TIMENS <- Not really required
168 * The check for vdso_clock->clock_mode is in the unlikely path of
169 * the seq begin magic. So for the non-timens case most of the time
173 * for vdso_clock->clock_mode is a non-issue. The task is spin waiting for the
176 * Timens page has vdso_clock->clock_mode set to VDSO_CLOCKMODE_TIMENS which
180 struct time_namespace *ns) in timens_setup_vdso_clock_data() argument
182 struct timens_offset *offset = vc->offset; in timens_setup_vdso_clock_data()
183 struct timens_offset monotonic = offset_from_ts(ns->offsets.monotonic); in timens_setup_vdso_clock_data()
184 struct timens_offset boottime = offset_from_ts(ns->offsets.boottime); in timens_setup_vdso_clock_data()
186 vc->seq = 1; in timens_setup_vdso_clock_data()
187 vc->clock_mode = VDSO_CLOCKMODE_TIMENS; in timens_setup_vdso_clock_data()
197 if (likely(vma->vm_mm == current->mm)) in find_timens_vvar_page()
198 return current->nsproxy->time_ns->vvar_page; in find_timens_vvar_page()
220 struct time_namespace *ns) in timens_set_vvar_page() argument
226 if (ns == &init_time_ns) in timens_set_vvar_page()
229 /* Fast-path, taken by every task in namespace except the first. */ in timens_set_vvar_page()
230 if (likely(ns->frozen_offsets)) in timens_set_vvar_page()
234 /* Nothing to-do: vvar_page has been already initialized. */ in timens_set_vvar_page()
235 if (ns->frozen_offsets) in timens_set_vvar_page()
238 ns->frozen_offsets = true; in timens_set_vvar_page()
239 vdata = page_address(ns->vvar_page); in timens_set_vvar_page()
240 vc = vdata->clock_data; in timens_set_vvar_page()
243 timens_setup_vdso_clock_data(&vc[i], ns); in timens_set_vvar_page()
246 for (i = 0; i < ARRAY_SIZE(vdata->aux_clock_data); i++) in timens_set_vvar_page()
247 timens_setup_vdso_clock_data(&vdata->aux_clock_data[i], ns); in timens_set_vvar_page()
254 void free_time_ns(struct time_namespace *ns) in free_time_ns() argument
256 dec_time_namespaces(ns->ucounts); in free_time_ns()
257 put_user_ns(ns->user_ns); in free_time_ns()
258 ns_free_inum(&ns->ns); in free_time_ns()
259 __free_page(ns->vvar_page); in free_time_ns()
260 kfree(ns); in free_time_ns()
263 static struct time_namespace *to_time_ns(struct ns_common *ns) in to_time_ns() argument
265 return container_of(ns, struct time_namespace, ns); in to_time_ns()
270 struct time_namespace *ns = NULL; in timens_get() local
274 nsproxy = task->nsproxy; in timens_get()
276 ns = nsproxy->time_ns; in timens_get()
277 get_time_ns(ns); in timens_get()
281 return ns ? &ns->ns : NULL; in timens_get()
286 struct time_namespace *ns = NULL; in timens_for_children_get() local
290 nsproxy = task->nsproxy; in timens_for_children_get()
292 ns = nsproxy->time_ns_for_children; in timens_for_children_get()
293 get_time_ns(ns); in timens_for_children_get()
297 return ns ? &ns->ns : NULL; in timens_for_children_get()
300 static void timens_put(struct ns_common *ns) in timens_put() argument
302 put_time_ns(to_time_ns(ns)); in timens_put()
305 void timens_commit(struct task_struct *tsk, struct time_namespace *ns) in timens_commit() argument
307 timens_set_vvar_page(tsk, ns); in timens_commit()
308 vdso_join_timens(tsk, ns); in timens_commit()
313 struct nsproxy *nsproxy = nsset->nsproxy; in timens_install()
314 struct time_namespace *ns = to_time_ns(new); in timens_install() local
317 return -EUSERS; in timens_install()
319 if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN) || in timens_install()
320 !ns_capable(nsset->cred->user_ns, CAP_SYS_ADMIN)) in timens_install()
321 return -EPERM; in timens_install()
323 get_time_ns(ns); in timens_install()
324 put_time_ns(nsproxy->time_ns); in timens_install()
325 nsproxy->time_ns = ns; in timens_install()
327 get_time_ns(ns); in timens_install()
328 put_time_ns(nsproxy->time_ns_for_children); in timens_install()
329 nsproxy->time_ns_for_children = ns; in timens_install()
335 struct ns_common *nsc = &nsproxy->time_ns_for_children->ns; in timens_on_fork()
336 struct time_namespace *ns = to_time_ns(nsc); in timens_on_fork() local
339 if (nsproxy->time_ns == nsproxy->time_ns_for_children) in timens_on_fork()
342 get_time_ns(ns); in timens_on_fork()
343 put_time_ns(nsproxy->time_ns); in timens_on_fork()
344 nsproxy->time_ns = ns; in timens_on_fork()
346 timens_commit(tsk, ns); in timens_on_fork()
349 static struct user_namespace *timens_owner(struct ns_common *ns) in timens_owner() argument
351 return to_time_ns(ns)->user_ns; in timens_owner()
369 seq_printf(m, "%-10s %10lld %9ld\n", clock, ts->tv_sec, ts->tv_nsec); in show_offset()
374 struct ns_common *ns; in proc_timens_show_offsets() local
377 ns = timens_for_children_get(p); in proc_timens_show_offsets()
378 if (!ns) in proc_timens_show_offsets()
380 time_ns = to_time_ns(ns); in proc_timens_show_offsets()
382 show_offset(m, CLOCK_MONOTONIC, &time_ns->offsets.monotonic); in proc_timens_show_offsets()
383 show_offset(m, CLOCK_BOOTTIME, &time_ns->offsets.boottime); in proc_timens_show_offsets()
390 struct ns_common *ns; in proc_timens_set_offset() local
395 ns = timens_for_children_get(p); in proc_timens_set_offset()
396 if (!ns) in proc_timens_set_offset()
397 return -ESRCH; in proc_timens_set_offset()
398 time_ns = to_time_ns(ns); in proc_timens_set_offset()
400 if (!file_ns_capable(file, time_ns->user_ns, CAP_SYS_TIME)) { in proc_timens_set_offset()
402 return -EPERM; in proc_timens_set_offset()
408 switch (off->clockid) { in proc_timens_set_offset()
416 err = -EINVAL; in proc_timens_set_offset()
420 err = -ERANGE; in proc_timens_set_offset()
422 if (off->val.tv_sec > KTIME_SEC_MAX || in proc_timens_set_offset()
423 off->val.tv_sec < -KTIME_SEC_MAX) in proc_timens_set_offset()
426 tp = timespec64_add(tp, off->val); in proc_timens_set_offset()
436 if (time_ns->frozen_offsets) { in proc_timens_set_offset()
437 err = -EACCES; in proc_timens_set_offset()
447 switch (off->clockid) { in proc_timens_set_offset()
449 offset = &time_ns->offsets.monotonic; in proc_timens_set_offset()
452 offset = &time_ns->offsets.boottime; in proc_timens_set_offset()
456 *offset = off->val; in proc_timens_set_offset()
487 .ns.count = REFCOUNT_INIT(3),
489 .ns.inum = PROC_TIME_INIT_INO,
490 .ns.ops = &timens_operations,