Message ID | 20190618093207.13436-1-ard.biesheuvel@linaro.org |
---|---|
Headers | show |
Series | net: fastopen: follow-up tweaks for SipHash switch | expand |
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.
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
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 ?
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.
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.
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.