Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp2288507pxu; Fri, 9 Oct 2020 12:43:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfv+P1R/HcWPlTjvrjYlghKJZnOz5css8ESX8KYSZbQpqeFtpVUYS8AcLprwO12QLnR9iJ X-Received: by 2002:a05:6402:1847:: with SMTP id v7mr858476edy.307.1602272619680; Fri, 09 Oct 2020 12:43:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602272619; cv=none; d=google.com; s=arc-20160816; b=QGorz7zXcVpUiDXzqhEgdxTzWxoF3ZgGpaIObbeHAsuLzMcO2YMfeaImZGqhrdMEIA cwrNRnUXpSrqr9QXSU6zakGcrfWMD5ewrBt9Uc2x+3NbVqwVHf5b6/iTLi7Yk8LySIm4 GXbQi09vyJLjq5M+LI8gRrkHgbmm0WBwVM5GuAutun/jPBSDnJawJr8tQ0nxCx5RfLlt 4InT5vGi5AD46mYJRNiFiyyCFDdyWFfGakrcX+FRPBg0Z8GI+QvoB/vXdBAcMLCcxRQj KG1xHTf8VmIAO5fUXlj3Jus+ZNVBYQJutyrkIXPsFQmr4jV/k2yYSCW+vgylB8TWyB8z udOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=SIPH9D01z+/KjAU74Pf75DJ6GeoTkS+zxp1jLiBNYoE=; b=Gi4jlizZIkZY0uL3NWc64FOBlOPbuiiQXJsRUeQTb06DDU8oLQ7hjudJlpxumWi1xQ zgvEZV/hkwN/0yx9g/b3CSzeCeA6Pc3UesK3XMQIH9mExoJ1wZVk2xOoPaZ0e2u78lk5 x6Ij4QzoUTSNYELFjaY76nXMUg/giwToooTQXaRNjxVPipYjR6/x/GbcxrQrb8ap+bWQ jxtCkizQTDdvcEpIDaqF7JAZN63I7sWIUkvjdOfF/BYEe6pOq0lqgyYjIiAMdjZY7Wec DmrJqpiArYs12hsp/R5F3Rd3mVy4f0HOED74GnJsT4bcd/4saHzGv6pT6SgUsqgzQ9c5 72ZQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gf16si6735470ejb.694.2020.10.09.12.43.16; Fri, 09 Oct 2020 12:43:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733191AbgJIN2T (ORCPT + 99 others); Fri, 9 Oct 2020 09:28:19 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:60042 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729272AbgJIN2T (ORCPT ); Fri, 9 Oct 2020 09:28:19 -0400 Received: from ip5f5af0a0.dynamic.kabel-deutschland.de ([95.90.240.160] helo=wittgenstein) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kQsRU-0006Q9-7Q; Fri, 09 Oct 2020 13:28:16 +0000 Date: Fri, 9 Oct 2020 15:28:15 +0200 From: Christian Brauner To: Michael =?utf-8?B?V2Vpw58=?= Cc: Thomas Gleixner , Andrei Vagin , Dmitry Safonov <0x7f454c46@gmail.com>, linux-kernel@vger.kernel.org, "J. Bruce Fields" , Chuck Lever , Trond Myklebust , Anna Schumaker Subject: Re: [PATCH v2 2/4] time: make getboottime64 aware of time namespace Message-ID: <20201009132815.5afulu5poh5ti57m@wittgenstein> References: <20201008053944.32718-1-michael.weiss@aisec.fraunhofer.de> <20201008053944.32718-3-michael.weiss@aisec.fraunhofer.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20201008053944.32718-3-michael.weiss@aisec.fraunhofer.de> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 08, 2020 at 07:39:42AM +0200, Michael Weiß wrote: > 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ß > --- > 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 > #include > #include > +#include > #include > #include > #include > @@ -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); Note that getbootime64() is mostly used in net/sunrpc and I don't know if this change has any security implications for them. Hey, Trond, Anna, Bruce, and Chuck this virtualizes boottime according to the time namespace of the caller, i.e. a container can e.g. reset it's boottime when started. This is already possible. The series here fixes a bug where /proc/stat's btime field is not virtualized but since this changes getboottime64() this would also apply to sunrpc's timekeeping. Is that ok or does sunrpc rely on the hosts's boot time, i.e. the time in the initial time namespace? Christian