summaryrefslogtreecommitdiff
path: root/fs/proc/stat.c
diff options
context:
space:
mode:
authorMichael Weiß <michael.weiss@aisec.fraunhofer.de>2020-10-27 23:42:57 +0300
committerChristian Brauner <christian.brauner@ubuntu.com>2020-11-03 13:05:39 +0300
commit3ae700ecfae913316e3b4fe5f60c72b6131aaa1f (patch)
treeb6fc855cc317a4f2d4e3f56d4b124b6cfb55d304 /fs/proc/stat.c
parent31909e3330c8d65e9a928d40833ebd5feb4f64e6 (diff)
downloadlinux-3ae700ecfae913316e3b4fe5f60c72b6131aaa1f.tar.xz
fs/proc: apply the time namespace offset to /proc/stat btime
'/proc/stat' provides the field 'btime' which states the time stamp of system boot in seconds. In case of time namespaces, the offset to the boot time stamp was not applied earlier. This confuses tasks which are in another time universe, e.g., in a container of a container runtime which utilize time namespaces to virtualize boottime. Therefore, we make procfs to virtualize also the btime field by subtracting the offset of the timens boottime from 'btime' before printing the stats. Since start_boottime of processes are seconds since boottime and the boottime stamp is now shifted according to the timens offset, the offset of the time namespace also needs to be applied before the process stats are given to userspace. This avoids that processes shown, e.g., by 'ps' appear as time travelers in the corresponding time namespace. Signed-off-by: Michael Weiß <michael.weiss@aisec.fraunhofer.de> Reviewed-by: Andrei Vagin <avagin@gmail.com> Acked-by: Thomas Gleixner <tglx@linutronix.de> Acked-by: Christian Brauner <christian.brauner@ubuntu.com> Link: https://lore.kernel.org/r/20201027204258.7869-3-michael.weiss@aisec.fraunhofer.de
Diffstat (limited to 'fs/proc/stat.c')
-rw-r--r--fs/proc/stat.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/fs/proc/stat.c b/fs/proc/stat.c
index 46b3293015fe..9df128ea9417 100644
--- a/fs/proc/stat.c
+++ b/fs/proc/stat.c
@@ -10,6 +10,7 @@
#include <linux/seq_file.h>
#include <linux/slab.h>
#include <linux/time.h>
+#include <linux/time_namespace.h>
#include <linux/irqnr.h>
#include <linux/sched/cputime.h>
#include <linux/tick.h>
@@ -118,6 +119,8 @@ static int show_stat(struct seq_file *p, void *v)
irq = softirq = steal = 0;
guest = guest_nice = 0;
getboottime64(&boottime);
+ /* shift boot timestamp according to the timens offset */
+ timens_sub_boottime(&boottime);
for_each_possible_cpu(i) {
struct kernel_cpustat kcpustat;