All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael Weiß" <michael.weiss@aisec.fraunhofer.de>
To: Thomas Gleixner <tglx@linutronix.de>,
	Andrei Vagin <avagin@gmail.com>,
	Dmitry Safonov <0x7f454c46@gmail.com>,
	Christian Brauner <christian.brauner@ubuntu.com>
Cc: linux-kernel@vger.kernel.org,
	"Michael Weiß" <michael.weiss@aisec.fraunhofer.de>
Subject: [PATCH v2 2/4] time: make getboottime64 aware of time namespace
Date: Thu,  8 Oct 2020 07:39:42 +0200	[thread overview]
Message-ID: <20201008053944.32718-3-michael.weiss@aisec.fraunhofer.de> (raw)
In-Reply-To: <20201008053944.32718-1-michael.weiss@aisec.fraunhofer.de>

getboottime64() provides the time stamp of system boot. In case of
time namespaces, the offset to the boot time stamp was not applied
earlier. However, getboottime64 is used e.g., in /proc/stat to print
the system boot time to userspace. In container runtimes which utilize
time namespaces to virtualize boottime of a container, this leaks
information about the host system boot time.

Therefore, we make getboottime64() to respect the time namespace offset
for boottime by subtracting the boottime offset.

Signed-off-by: Michael Weiß <michael.weiss@aisec.fraunhofer.de>
---
 kernel/time/timekeeping.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 4c47f388a83f..67530cdb389e 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -17,6 +17,7 @@
 #include <linux/clocksource.h>
 #include <linux/jiffies.h>
 #include <linux/time.h>
+#include <linux/time_namespace.h>
 #include <linux/tick.h>
 #include <linux/stop_machine.h>
 #include <linux/pvclock_gtod.h>
@@ -2154,6 +2155,8 @@ void getboottime64(struct timespec64 *ts)
 {
 	struct timekeeper *tk = &tk_core.timekeeper;
 	ktime_t t = ktime_sub(tk->offs_real, tk->offs_boot);
+	/* shift boot time stamp according to the timens offset */
+	t = timens_ktime_to_host(CLOCK_BOOTTIME, t);
 
 	*ts = ktime_to_timespec64(t);
 }
-- 
2.20.1


  parent reply	other threads:[~2020-10-08  5:40 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-08  5:39 [PATCH v2 0/4] time namespace aware system boot time Michael Weiß
2020-10-08  5:39 ` [PATCH v2 1/4] timens: additional helper function to add boottime in nsec Michael Weiß
2020-10-08  5:39 ` Michael Weiß [this message]
2020-10-09 13:28   ` [PATCH v2 2/4] time: make getboottime64 aware of time namespace Christian Brauner
2020-10-09 13:55     ` J. Bruce Fields
2020-10-09 20:08       ` Thomas Gleixner
2020-10-12 21:13         ` J. Bruce Fields
2020-10-12 21:36           ` Thomas Gleixner
2020-10-14 22:05           ` J. Bruce Fields
2020-10-16 12:37             ` Thomas Gleixner
2020-10-10  7:19     ` Andrei Vagin
2020-10-10 11:50       ` Michael Weiß
2020-10-10 16:37         ` Thomas Gleixner
2020-10-13 20:05       ` Christian Brauner
2020-10-08  5:39 ` [PATCH v2 3/4] fs/proc: apply timens offset for start_boottime of processes Michael Weiß
2020-10-08  5:39 ` [PATCH v2 4/4] selftests/timens: added selftest for /proc/stat btime Michael Weiß
2020-10-09 13:21 ` [PATCH v2 0/4] time namespace aware system boot time Christian Brauner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201008053944.32718-3-michael.weiss@aisec.fraunhofer.de \
    --to=michael.weiss@aisec.fraunhofer.de \
    --cc=0x7f454c46@gmail.com \
    --cc=avagin@gmail.com \
    --cc=christian.brauner@ubuntu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.