lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CALAqxLUd4nEiayhEMCRCmDm4NrU+4T_VkmafRxJepbGQUg-iEQ@mail.gmail.com>
Date:   Thu, 24 Aug 2017 11:50:40 -0700
From:   John Stultz <john.stultz@...aro.org>
To:     Prarit Bhargava <prarit@...hat.com>
Cc:     lkml <linux-kernel@...r.kernel.org>,
        Mark Salyzyn <salyzyn@...roid.com>,
        Jonathan Corbet <corbet@....net>,
        Petr Mladek <pmladek@...e.com>,
        Sergey Senozhatsky <sergey.senozhatsky@...il.com>,
        Steven Rostedt <rostedt@...dmis.org>,
        Thomas Gleixner <tglx@...utronix.de>,
        Stephen Boyd <sboyd@...eaurora.org>,
        Andrew Morton <akpm@...ux-foundation.org>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        "Paul E. McKenney" <paulmck@...ux.vnet.ibm.com>,
        Christoffer Dall <cdall@...aro.org>,
        Deepa Dinamani <deepa.kernel@...il.com>,
        Ingo Molnar <mingo@...nel.org>,
        Joel Fernandes <joelaf@...gle.com>,
        Kees Cook <keescook@...omium.org>,
        Peter Zijlstra <peterz@...radead.org>,
        Geert Uytterhoeven <geert+renesas@...der.be>,
        "Luis R. Rodriguez" <mcgrof@...nel.org>,
        Nicholas Piggin <npiggin@...il.com>,
        "Jason A. Donenfeld" <Jason@...c4.com>,
        Olof Johansson <olof@...om.net>,
        Josh Poimboeuf <jpoimboe@...hat.com>, linux-doc@...r.kernel.org
Subject: Re: [PATCH 2/2 v8] printk: Add monotonic, boottime, and realtime timestamps

On Thu, Aug 24, 2017 at 6:42 AM, Prarit Bhargava <prarit@...hat.com> wrote:
> --- a/include/linux/timekeeping.h
> +++ b/include/linux/timekeeping.h
> @@ -239,6 +239,7 @@ static inline u64 ktime_get_raw_ns(void)
>  extern u64 ktime_get_mono_fast_ns(void);
>  extern u64 ktime_get_raw_fast_ns(void);
>  extern u64 ktime_get_boot_fast_ns(void);
> +extern u64 ktime_get_real_offset(void);
>
>  /*
>   * Timespec interfaces utilizing the ktime based ones
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index fc47863f629c..dd972bc5c88b 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
...
> + * printk_get_real_ns: - Return a realtime timestamp for printk messages
> + * On 32-bit systems selecting the real clock printk timestamp may lead to
> + * unlikely situations where a timestamp is wrong because the real time offset
> + * is read without the protection of a sequence lock.
> + */
> +static u64 printk_get_real_ns(void)
> +{
> +       return ktime_get_mono_fast_ns() + ktime_get_real_offset();
> +}
> +
...
> diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
> index d111039e0245..de07bb5ffef5 100644
> --- a/kernel/time/timekeeping.c
> +++ b/kernel/time/timekeeping.c
> @@ -508,6 +508,11 @@ u64 notrace ktime_get_boot_fast_ns(void)
>  }
>  EXPORT_SYMBOL_GPL(ktime_get_boot_fast_ns);
>
> +u64 ktime_get_real_offset(void)
> +{
> +       return ktime_to_ns(tk_core.timekeeper.offs_real);
> +}
> +

Apologies! One last nit here.  So if we're going to export
ktime_get_real_offset(), folks are going to use it, and there is no
documentation about its very sketchy behavioral limits as an
interface, except elsewhere in the printk code.

Instead of doing that, could you export a
__ktime_get_real_fast_ns_unsafe() function, which has its limits
(calculating the realtime w/o locks, thus may return completely bad
values occasionally) clearly documented in the timekeeping code?

You can then use that directly in your printk code, and others who
find it and think "Hey this would be great for my
life-safety-critical-system driver" will be clearly warned.

thanks
-john

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ