tls: rx: follow-ups to NoPad
Subsystems (5)
Jakub Kicinski
maintainercover tls: rx: follow-ups to NoPad
A few fixes for issues spotted by Maxim.
Jakub Kicinski (4):
tls: fix spelling of MIB
tls: rx: add counter for NoPad violations
tls: rx: fix the NoPad getsockopt
selftests: tls: add test for NoPad getsockopt
Documentation/networking/tls.rst | 4 +++ include/uapi/linux/snmp.h | 3 +- net/tls/tls_main.c | 9 +++--- net/tls/tls_proc.c | 3 +- net/tls/tls_sw.c | 4 ++- tools/testing/selftests/net/tls.c | 51 +++++++++++++++++++++++++++++++ 6 files changed, 66 insertions(+), 8 deletions(-)
Signature · 1 line
2.36.1
Jakub Kicinski
maintainerPATCH 1/4 tls: fix spelling of MIB
MIN -> MIB
--- include/uapi/linux/snmp.h | 2 +- net/tls/tls_proc.c | 2 +- net/tls/tls_sw.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
include/uapi/linux/snmp.h +1 -1
@@ -344,7 +344,7 @@ enumLINUX_MIB_TLSRXDEVICE ,/* TlsRxDevice */ LINUX_MIB_TLSDECRYPTERROR ,/* TlsDecryptError */ LINUX_MIB_TLSRXDEVICERESYNC ,/* TlsRxDeviceResync */ -LINUX_MIN_TLSDECRYPTRETRY ,/* TlsDecryptRetry */ +LINUX_MIB_TLSDECRYPTRETRY ,/* TlsDecryptRetry */ __LINUX_MIB_TLSMAX };
net/tls/tls_proc.c +1 -1
@@ -20,7 +20,7 @@ static const struct snmp_mib tls_mib_list[] = {SNMP_MIB_ITEM ("TlsRxDevice" ,LINUX_MIB_TLSRXDEVICE ),SNMP_MIB_ITEM ("TlsDecryptError" ,LINUX_MIB_TLSDECRYPTERROR ),SNMP_MIB_ITEM ("TlsRxDeviceResync" ,LINUX_MIB_TLSRXDEVICERESYNC ), -SNMP_MIB_ITEM ("TlsDecryptRetry" ,LINUX_MIN_TLSDECRYPTRETRY ), +SNMP_MIB_ITEM ("TlsDecryptRetry" ,LINUX_MIB_TLSDECRYPTRETRY ), SNMP_MIB_SENTINEL };
net/tls/tls_sw.c +1 -1
@@ -1596,7 +1596,7 @@ static int decrypt_skb_update(struct sock *sk, struct sk_buff *skb,if (unlikely (darg->zc && prot->version ==TLS_1_3_VERSION && darg->tail !=TLS_RECORD_TYPE_DATA )) { darg->zc = false; -TLS_INC_STATS (sock_net (sk),LINUX_MIN_TLSDECRYPTRETRY ); +TLS_INC_STATS (sock_net (sk),LINUX_MIB_TLSDECRYPTRETRY );return decrypt_skb_update (sk, skb, dest, darg); }
Signature · 1 line
2.36.1
Jakub Kicinski
maintainerPATCH 2/4 tls: rx: add counter for NoPad violations
In reply to Jakub KicinskiAs discussed with Maxim add a counter for true NoPad violations. This should help deployments catch unexpected padded records vs just control records which always need re-encryption.
https://lore.kernel.org/all/[email protected]/
--- Documentation/networking/tls.rst | 4 ++++ include/uapi/linux/snmp.h | 1 + net/tls/tls_proc.c | 1 + net/tls/tls_sw.c | 2 ++ 4 files changed, 8 insertions(+)
Documentation/networking/tls.rst +4 -0
@@ -282,3 +282,7 @@ TLS implementation exposes the following per-namespace statistics number of RX records which had to be re-decrypted due to ``TLS_RX_EXPECT_NO_PAD`` mis-prediction. Note that this counter will also increment for non-data records. + +- ``TlsRxNoPadViolation`` - + number of data RX records which had to be re-decrypted due to + ``TLS_RX_EXPECT_NO_PAD`` mis-prediction.
include/uapi/linux/snmp.h +1 -0
@@ -345,6 +345,7 @@ enumLINUX_MIB_TLSDECRYPTERROR ,/* TlsDecryptError */ LINUX_MIB_TLSRXDEVICERESYNC ,/* TlsRxDeviceResync */ LINUX_MIB_TLSDECRYPTRETRY ,/* TlsDecryptRetry */ +LINUX_MIB_TLSRXNOPADVIOL ,/* TlsRxNoPadViolation */ __LINUX_MIB_TLSMAX };
net/tls/tls_proc.c +1 -0
@@ -21,6 +21,7 @@ static const struct snmp_mib tls_mib_list[] = {SNMP_MIB_ITEM ("TlsDecryptError" ,LINUX_MIB_TLSDECRYPTERROR ),SNMP_MIB_ITEM ("TlsRxDeviceResync" ,LINUX_MIB_TLSRXDEVICERESYNC ),SNMP_MIB_ITEM ("TlsDecryptRetry" ,LINUX_MIB_TLSDECRYPTRETRY ), +SNMP_MIB_ITEM ("TlsRxNoPadViolation" ,LINUX_MIB_TLSRXNOPADVIOL ), SNMP_MIB_SENTINEL };
net/tls/tls_sw.c +2 -0
@@ -1596,6 +1596,8 @@ static int decrypt_skb_update(struct sock *sk, struct sk_buff *skb,if (unlikely (darg->zc && prot->version ==TLS_1_3_VERSION && darg->tail !=TLS_RECORD_TYPE_DATA )) { darg->zc = false; +if (!darg->tail) +TLS_INC_STATS (sock_net (sk),LINUX_MIB_TLSRXNOPADVIOL );TLS_INC_STATS (sock_net (sk),LINUX_MIB_TLSDECRYPTRETRY );return decrypt_skb_update (sk, skb, dest, darg); }
Signature · 1 line
2.36.1
Jakub Kicinski
maintainerPATCH 3/4 tls: rx: fix the NoPad getsockopt
In reply to Jakub KicinskiMaxim reports do_tls_getsockopt_no_pad() will always return an error. Indeed looks like refactoring gone wrong - remove err and use value.
--- net/tls/tls_main.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
net/tls/tls_main.c +4 -5
@@ -539,8 +539,7 @@ static int do_tls_getsockopt_no_pad(struct sock *sk, char __user *optval, int __user *optlen) {struct tls_context *ctx =tls_get_ctx (sk); -unsigned int value; -int err, len; +int value, len;if (ctx->prot_info.version !=TLS_1_3_VERSION )return -EINVAL ;
@@ -551,12 +550,12 @@ static int do_tls_getsockopt_no_pad(struct sock *sk, char __user *optval,return -EINVAL ;lock_sock (sk); - err = -EINVAL ; + value = -EINVAL ;if (ctx->rx_conf ==TLS_SW || ctx->rx_conf ==TLS_HW ) value = ctx->rx_no_pad;release_sock (sk); -if (err) -return err; +if (value <0 ) +return value;if (put_user (sizeof (value), optlen))return -EFAULT ;
Signature · 1 line
2.36.1
Jakub Kicinski
maintainerPATCH 4/4 selftests: tls: add test for NoPad getsockopt
In reply to Jakub KicinskiMake sure setsockopt / getsockopt behave as expected.
--- tools/testing/selftests/net/tls.c | 51 +++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)
tools/testing/selftests/net/tls.c +51 -0
@@ -1674,6 +1674,57 @@ TEST(keysizes) {close (cfd); } +TEST (no_pad) { +struct tls12_crypto_info_aes_gcm_256 tls12; +int ret, fd, cfd, val; +socklen_t len; +bool notls; + +memset (&tls12,0 ,sizeof (tls12)); + tls12.info.version =TLS_1_3_VERSION ; + tls12.info.cipher_type =TLS_CIPHER_AES_GCM_256 ; + +ulp_sock_pair (_metadata, &fd, &cfd, ¬ls); + +if (notls) +exit (KSFT_SKIP ); + + ret =setsockopt (fd,SOL_TLS ,TLS_TX , &tls12,sizeof (tls12)); +EXPECT_EQ (ret,0 ); + + ret =setsockopt (cfd,SOL_TLS ,TLS_RX , &tls12,sizeof (tls12)); +EXPECT_EQ (ret,0 ); + + val =1 ; + ret =setsockopt (cfd,SOL_TLS ,TLS_RX_EXPECT_NO_PAD , + (void *)&val,sizeof (val)); +EXPECT_EQ (ret,0 ); + + len =sizeof (val); + val =2 ; + ret =getsockopt (cfd,SOL_TLS ,TLS_RX_EXPECT_NO_PAD , + (void *)&val, &len); +EXPECT_EQ (ret,0 ); +EXPECT_EQ (val,1 ); +EXPECT_EQ (len,4 ); + + val =0 ; + ret =setsockopt (cfd,SOL_TLS ,TLS_RX_EXPECT_NO_PAD , + (void *)&val,sizeof (val)); +EXPECT_EQ (ret,0 ); + + len =sizeof (val); + val =2 ; + ret =getsockopt (cfd,SOL_TLS ,TLS_RX_EXPECT_NO_PAD , + (void *)&val, &len); +EXPECT_EQ (ret,0 ); +EXPECT_EQ (val,0 ); +EXPECT_EQ (len,4 ); + +close (fd); +close (cfd); +} +TEST (tls_v6ops) {struct tls_crypto_info_keys tls12;struct sockaddr_in6 addr, addr2;
Signature · 1 line
2.36.1
This series was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Fri, 8 Jul 2022 19:52:51 -0700 you wrote:
A few fixes for issues spotted by Maxim.
Jakub Kicinski (4):
tls: fix spelling of MIB
tls: rx: add counter for NoPad violations
tls: rx: fix the NoPad getsockopt
selftests: tls: add test for NoPad getsockopt[...]
Here is the summary with links:
- [net-next,1/4] tls: fix spelling of MIB
https://git.kernel.org/netdev/net-next/c/1090c1ea2208 - [net-next,2/4] tls: rx: add counter for NoPad violations https://git.kernel.org/netdev/net-next/c/bb56cea9abd8 - [net-next,3/4] tls: rx: fix the NoPad getsockopt https://git.kernel.org/netdev/net-next/c/57128e98c33d - [net-next,4/4] selftests: tls: add test for NoPad getsockopt https://git.kernel.org/netdev/net-next/c/1d55f2031385
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html