linux-wpan.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: Networking <netdev@vger.kernel.org>, David Miller <davem@davemloft.net>
Cc: linux-arch <linux-arch@vger.kernel.org>,
	y2038 Mailman List <y2038@lists.linaro.org>,
	Eric Dumazet <edumazet@google.com>,
	Willem de Bruijn <willemb@google.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	linux-hams@vger.kernel.org,
	Bluez mailing list <linux-bluetooth@vger.kernel.org>,
	linux-can@vger.kernel.org, dccp@vger.kernel.org,
	linux-wpan@vger.kernel.org, linux-sctp@vger.kernel.org,
	linux-x25@vger.kernel.org
Subject: Re: [PATCH net-next 1/3] net: rework SIOCGSTAMP ioctl handling
Date: Thu, 13 Sep 2018 14:28:08 +0200	[thread overview]
Message-ID: <CAK8P3a038aDQQotzua_QtKGhq8O9n+rdiz2=WDCp82ys8eUT+A@mail.gmail.com> (raw)
In-Reply-To: <20180829130308.3504560-1-arnd@arndb.de>

On Wed, Aug 29, 2018 at 3:03 PM Arnd Bergmann <arnd@arndb.de> wrote:

> diff --git a/net/core/sock.c b/net/core/sock.c
> index 3730eb855095..df17bbfaca27 100644
> --- a/net/core/sock.c
> +++ b/net/core/sock.c
> @@ -2897,37 +2897,31 @@ bool lock_sock_fast(struct sock *sk)
>  }
>  EXPORT_SYMBOL(lock_sock_fast);
>
> -int sock_get_timestamp(struct sock *sk, struct timeval __user *userstamp)
> +int sock_gettstamp(struct socket *sock, void __user *userstamp,
> +                  bool timeval, bool time32)
>  {
> -       struct timeval tv;
> -
> -       sock_enable_timestamp(sk, SOCK_TIMESTAMP);
> -       tv = ktime_to_timeval(sk->sk_stamp);
> -       if (tv.tv_sec == -1)
> -               return -ENOENT;
> -       if (tv.tv_sec == 0) {
> -               sk->sk_stamp = ktime_get_real();
> -               tv = ktime_to_timeval(sk->sk_stamp);
> -       }
> -       return copy_to_user(userstamp, &tv, sizeof(tv)) ? -EFAULT : 0;
> -}
> -EXPORT_SYMBOL(sock_get_timestamp);

As  I just learned, sparc64 uses a 32-bit suseconds_t, so this
function always leaked 32 bits of kernel stack data by copying
the padding bytes of 'tv' into user space.

Linux-4.11 and higher could avoid that with
CONFIG_GCC_PLUGIN_STRUCTLEAK, but older kernels
have been affected since socket timestamps were first added.

The same thing is probably true of many other interfaces
that pass a timeval.

> -int sock_get_timestampns(struct sock *sk, struct timespec __user *userstamp)
> -{
> -       struct timespec ts;
> +       struct sock *sk = sock->sk;
> +       struct timespec64 ts;
>
>         sock_enable_timestamp(sk, SOCK_TIMESTAMP);
> -       ts = ktime_to_timespec(sk->sk_stamp);
> +       ts = ktime_to_timespec64(sk->sk_stamp);
>         if (ts.tv_sec == -1)
>                 return -ENOENT;
>         if (ts.tv_sec == 0) {
>                 sk->sk_stamp = ktime_get_real();
> -               ts = ktime_to_timespec(sk->sk_stamp);
> +               ts = ktime_to_timespec64(sk->sk_stamp);
>         }
> -       return copy_to_user(userstamp, &ts, sizeof(ts)) ? -EFAULT : 0;
> +
> +       if (timeval)
> +               ts.tv_nsec /= 1000;
> +#ifdef CONFIG_COMPAT_32BIT_TIME
> +       if (time32)
> +               return put_old_timespec32(&ts, userstamp);
> +#endif
> +
> +       return put_timespec64(&ts, userstamp);
>  }

My new implementation is worse here: it no longer leaks stack
data, but since we now write a big-endian 64-bit microseconds
value, the microseconds are in the wrong place and will
be interpreted as zero by user space...

I'll also have to revisit a few other similar patches I did for
y2038, to figure out what they should do on sparc64.

         Arnd

  parent reply	other threads:[~2018-09-13 17:37 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-29 12:59 [PATCH net-next 1/3] net: rework SIOCGSTAMP ioctl handling Arnd Bergmann
2018-08-30 20:09 ` Willem de Bruijn
2018-08-31 10:31   ` Arnd Bergmann
2018-08-31 13:37     ` Willem de Bruijn
2018-08-31 14:00       ` Arnd Bergmann
2018-08-31 15:08         ` Willem de Bruijn
2018-09-13 12:28 ` Arnd Bergmann [this message]
2018-09-21  9:14 ` Stefan Schmidt
2019-04-16 20:32 Arnd Bergmann
2019-04-17  9:35 ` Neil Horman
2019-04-17 17:21   ` David Miller
2019-04-17 20:15     ` Neil Horman
2019-04-17  9:59 ` Marc Kleine-Budde
2019-04-17 14:46 ` Willem de Bruijn
2019-04-17 16:19   ` Arnd Bergmann
2019-04-17 18:16     ` Willem de Bruijn

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='CAK8P3a038aDQQotzua_QtKGhq8O9n+rdiz2=WDCp82ys8eUT+A@mail.gmail.com' \
    --to=arnd@arndb.de \
    --cc=davem@davemloft.net \
    --cc=dccp@vger.kernel.org \
    --cc=edumazet@google.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-hams@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sctp@vger.kernel.org \
    --cc=linux-wpan@vger.kernel.org \
    --cc=linux-x25@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=willemb@google.com \
    --cc=y2038@lists.linaro.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).