mbox series

[0/2] net: fastopen: follow-up tweaks for SipHash switch

Message ID 20190618093207.13436-1-ard.biesheuvel@linaro.org
Headers show
Series net: fastopen: follow-up tweaks for SipHash switch | expand

Message

Ard Biesheuvel June 18, 2019, 9:32 a.m. UTC
A pair of tweaks for issues spotted by Eric Biggers. Patch #1 is
mostly cosmetic, since the error check it adds is unreachable in
practice, and the other changes are syntactic cleanups. Patch #2
adds endian swabbing of the SipHash output for big endian systems
so that the in-memory representation is the same as on little
endian systems.

cc: Eric Biggers <ebiggers@kernel.org>
cc: linux-crypto@vger.kernel.org
cc: herbert@gondor.apana.org.au
cc: edumazet@google.com
cc: davem@davemloft.net
cc: kuznet@ms2.inr.ac.ru
cc: yoshfuji@linux-ipv6.org
cc: jbaron@akamai.com
cc: cpaasch@apple.com
cc: David.Laight@aculab.com
cc: ycheng@google.com

Ard Biesheuvel (2):
  net: fastopen: make key handling more robust against future changes
  net: fastopen: use endianness agnostic representation of the cookie

 include/linux/tcp.h     |  2 +-
 include/net/tcp.h       |  5 +--
 net/ipv4/tcp_fastopen.c | 34 +++++++++++---------
 3 files changed, 23 insertions(+), 18 deletions(-)

-- 
2.17.1

Comments

Eric Dumazet June 18, 2019, 9:37 a.m. UTC | #1
On Tue, Jun 18, 2019 at 2:32 AM Ard Biesheuvel
<ard.biesheuvel@linaro.org> wrote:
>

> A pair of tweaks for issues spotted by Eric Biggers. Patch #1 is

> mostly cosmetic, since the error check it adds is unreachable in

> practice, and the other changes are syntactic cleanups. Patch #2

> adds endian swabbing of the SipHash output for big endian systems

> so that the in-memory representation is the same as on little

> endian systems.

>


Please always add net or net-next in your patches for netdev@

( Documentation/networking/netdev-FAQ.rst )

Thanks.
Ard Biesheuvel June 18, 2019, 9:38 a.m. UTC | #2
On Tue, 18 Jun 2019 at 11:37, Eric Dumazet <edumazet@google.com> wrote:
>

> On Tue, Jun 18, 2019 at 2:32 AM Ard Biesheuvel

> <ard.biesheuvel@linaro.org> wrote:

> >

> > A pair of tweaks for issues spotted by Eric Biggers. Patch #1 is

> > mostly cosmetic, since the error check it adds is unreachable in

> > practice, and the other changes are syntactic cleanups. Patch #2

> > adds endian swabbing of the SipHash output for big endian systems

> > so that the in-memory representation is the same as on little

> > endian systems.

> >

>

> Please always add net or net-next in your patches for netdev@

>

> ( Documentation/networking/netdev-FAQ.rst )

>


Apologies. These patches are intended for net-next
Eric Dumazet June 18, 2019, 9:39 a.m. UTC | #3
On Tue, Jun 18, 2019 at 2:32 AM Ard Biesheuvel
<ard.biesheuvel@linaro.org> wrote:
>

> Some changes to the TCP fastopen code to make it more robust

> against future changes in the choice of key/cookie size, etc.

>

> - Instead of keeping the SipHash key in an untyped u8[] buffer

>   and casting it to the right type upon use, use the correct

>   siphash_key_t type directly. This ensures that the key will

>   appear at the correct alignment if we ever change the way

>   these data structures are allocated. (Currently, they are

>   only allocated via kmalloc so they always appear at the

>   correct alignment)

>

> - Use DIV_ROUND_UP when sizing the u64[] array to hold the

>   cookie, so it is always of sufficient size, even when

>   TCP_FASTOPEN_COOKIE_MAX is no longer a multiple of 8.

>

> - Add a key length check to tcp_fastopen_reset_cipher(). No

>   callers exist currently that fail this check (they all pass

>   compile constant values that equal TCP_FASTOPEN_KEY_LENGTH),

>   but future changes might create problems, e.g., by leaving part

>   of the key uninitialized, or overflowing the key buffers.

>

> Note that none of these are functional changes wrt the current

> state of the code.

>

...

> -       memcpy(ctx->key[0], primary_key, len);

> +       if (unlikely(len != TCP_FASTOPEN_KEY_LENGTH)) {

> +               pr_err("TCP: TFO key length %u invalid\n", len);

> +               err = -EINVAL;

> +               goto out;

> +       }



Why a pr_err() is there ?

Can unpriv users flood the syslog ?
Ard Biesheuvel June 18, 2019, 9:41 a.m. UTC | #4
On Tue, 18 Jun 2019 at 11:39, Eric Dumazet <edumazet@google.com> wrote:
>

> On Tue, Jun 18, 2019 at 2:32 AM Ard Biesheuvel

> <ard.biesheuvel@linaro.org> wrote:

> >

> > Some changes to the TCP fastopen code to make it more robust

> > against future changes in the choice of key/cookie size, etc.

> >

> > - Instead of keeping the SipHash key in an untyped u8[] buffer

> >   and casting it to the right type upon use, use the correct

> >   siphash_key_t type directly. This ensures that the key will

> >   appear at the correct alignment if we ever change the way

> >   these data structures are allocated. (Currently, they are

> >   only allocated via kmalloc so they always appear at the

> >   correct alignment)

> >

> > - Use DIV_ROUND_UP when sizing the u64[] array to hold the

> >   cookie, so it is always of sufficient size, even when

> >   TCP_FASTOPEN_COOKIE_MAX is no longer a multiple of 8.

> >

> > - Add a key length check to tcp_fastopen_reset_cipher(). No

> >   callers exist currently that fail this check (they all pass

> >   compile constant values that equal TCP_FASTOPEN_KEY_LENGTH),

> >   but future changes might create problems, e.g., by leaving part

> >   of the key uninitialized, or overflowing the key buffers.

> >

> > Note that none of these are functional changes wrt the current

> > state of the code.

> >

> ...

>

> > -       memcpy(ctx->key[0], primary_key, len);

> > +       if (unlikely(len != TCP_FASTOPEN_KEY_LENGTH)) {

> > +               pr_err("TCP: TFO key length %u invalid\n", len);

> > +               err = -EINVAL;

> > +               goto out;

> > +       }

>

>

> Why a pr_err() is there ?

>

> Can unpriv users flood the syslog ?


They can if they could do so before: there was a call to
crypto_cipher_setkey() in the original pre-SipHash code which would
also result in a pr_err() on an invalid key length. That call got
removed along with the AES cipher handling, and this basically
reinstates it, as suggested by EricB.
Ard Biesheuvel June 18, 2019, 10:02 a.m. UTC | #5
On Tue, 18 Jun 2019 at 11:53, Eric Dumazet <edumazet@google.com> wrote:
>

> On Tue, Jun 18, 2019 at 2:41 AM Ard Biesheuvel

> <ard.biesheuvel@linaro.org> wrote:

> >

> > On Tue, 18 Jun 2019 at 11:39, Eric Dumazet <edumazet@google.com> wrote:

> > >

> > > On Tue, Jun 18, 2019 at 2:32 AM Ard Biesheuvel

> > > <ard.biesheuvel@linaro.org> wrote:

> > > >

> > > > Some changes to the TCP fastopen code to make it more robust

> > > > against future changes in the choice of key/cookie size, etc.

> > > >

> > > > - Instead of keeping the SipHash key in an untyped u8[] buffer

> > > >   and casting it to the right type upon use, use the correct

> > > >   siphash_key_t type directly. This ensures that the key will

> > > >   appear at the correct alignment if we ever change the way

> > > >   these data structures are allocated. (Currently, they are

> > > >   only allocated via kmalloc so they always appear at the

> > > >   correct alignment)

> > > >

> > > > - Use DIV_ROUND_UP when sizing the u64[] array to hold the

> > > >   cookie, so it is always of sufficient size, even when

> > > >   TCP_FASTOPEN_COOKIE_MAX is no longer a multiple of 8.

> > > >

> > > > - Add a key length check to tcp_fastopen_reset_cipher(). No

> > > >   callers exist currently that fail this check (they all pass

> > > >   compile constant values that equal TCP_FASTOPEN_KEY_LENGTH),

> > > >   but future changes might create problems, e.g., by leaving part

> > > >   of the key uninitialized, or overflowing the key buffers.

> > > >

> > > > Note that none of these are functional changes wrt the current

> > > > state of the code.

> > > >

> > > ...

> > >

> > > > -       memcpy(ctx->key[0], primary_key, len);

> > > > +       if (unlikely(len != TCP_FASTOPEN_KEY_LENGTH)) {

> > > > +               pr_err("TCP: TFO key length %u invalid\n", len);

> > > > +               err = -EINVAL;

> > > > +               goto out;

> > > > +       }

> > >

> > >

> > > Why a pr_err() is there ?

> > >

> > > Can unpriv users flood the syslog ?

> >

> > They can if they could do so before: there was a call to

> > crypto_cipher_setkey() in the original pre-SipHash code which would

> > also result in a pr_err() on an invalid key length. That call got

> > removed along with the AES cipher handling, and this basically

> > reinstates it, as suggested by EricB.

>

> This tcp_fastopen_reset_cipher() function is internal to TCP stack, all callers

> always pass the correct length.

>

> We could add checks all over the place, and end up having a TCP stack

> full of defensive

> checks and 10,000 additional lines of code :/

>

> I would prefer not reinstating this.


Fair enough.
Eric Dumazet June 18, 2019, 6:19 p.m. UTC | #6
On Tue, Jun 18, 2019 at 11:18 AM Eric Biggers <ebiggers@kernel.org> wrote:

> The length parameter makes no sense if it's not checked, though.  Either it

> should exist and be checked, or it should be removed and the length should be

> implicitly TCP_FASTOPEN_KEY_LENGTH.


Sure, please send a patch.