Skip to content

Commit f7f870e

Browse files
author
Sabrina Dubroca
committed
tls: add counters for rekey
JIRA: https://issues.redhat.com/browse/RHEL-86020 commit 510128b Author: Sabrina Dubroca <sd@queasysnail.net> Date: Thu Dec 12 16:36:06 2024 +0100 tls: add counters for rekey This introduces 5 counters to keep track of key updates: Tls{Rx,Tx}Rekey{Ok,Error} and TlsRxRekeyReceived. Suggested-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sabrina Dubroca <sd@queasysnail.net> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
1 parent 4bd3b42 commit f7f870e

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

include/uapi/linux/snmp.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,11 @@ enum
358358
LINUX_MIB_TLSRXDEVICERESYNC, /* TlsRxDeviceResync */
359359
LINUX_MIB_TLSDECRYPTRETRY, /* TlsDecryptRetry */
360360
LINUX_MIB_TLSRXNOPADVIOL, /* TlsRxNoPadViolation */
361+
LINUX_MIB_TLSRXREKEYOK, /* TlsRxRekeyOk */
362+
LINUX_MIB_TLSRXREKEYERROR, /* TlsRxRekeyError */
363+
LINUX_MIB_TLSTXREKEYOK, /* TlsTxRekeyOk */
364+
LINUX_MIB_TLSTXREKEYERROR, /* TlsTxRekeyError */
365+
LINUX_MIB_TLSRXREKEYRECEIVED, /* TlsRxRekeyReceived */
361366
__LINUX_MIB_TLSMAX
362367
};
363368

net/tls/tls_main.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,11 @@ static int do_tls_setsockopt_conf(struct sock *sk, sockptr_t optval,
640640
/* Currently we only support setting crypto info more
641641
* than one time for TLS 1.3
642642
*/
643-
if (crypto_info->version != TLS_1_3_VERSION)
643+
if (crypto_info->version != TLS_1_3_VERSION) {
644+
TLS_INC_STATS(sock_net(sk), tx ? LINUX_MIB_TLSTXREKEYERROR
645+
: LINUX_MIB_TLSRXREKEYERROR);
644646
return -EBUSY;
647+
}
645648

646649
update = true;
647650
old_crypto_info = crypto_info;
@@ -696,8 +699,13 @@ static int do_tls_setsockopt_conf(struct sock *sk, sockptr_t optval,
696699
update ? crypto_info : NULL);
697700
if (rc)
698701
goto err_crypto_info;
699-
TLS_INC_STATS(sock_net(sk), LINUX_MIB_TLSTXSW);
700-
TLS_INC_STATS(sock_net(sk), LINUX_MIB_TLSCURRTXSW);
702+
703+
if (update) {
704+
TLS_INC_STATS(sock_net(sk), LINUX_MIB_TLSTXREKEYOK);
705+
} else {
706+
TLS_INC_STATS(sock_net(sk), LINUX_MIB_TLSTXSW);
707+
TLS_INC_STATS(sock_net(sk), LINUX_MIB_TLSCURRTXSW);
708+
}
701709
conf = TLS_SW;
702710
}
703711
} else {
@@ -711,8 +719,13 @@ static int do_tls_setsockopt_conf(struct sock *sk, sockptr_t optval,
711719
update ? crypto_info : NULL);
712720
if (rc)
713721
goto err_crypto_info;
714-
TLS_INC_STATS(sock_net(sk), LINUX_MIB_TLSRXSW);
715-
TLS_INC_STATS(sock_net(sk), LINUX_MIB_TLSCURRRXSW);
722+
723+
if (update) {
724+
TLS_INC_STATS(sock_net(sk), LINUX_MIB_TLSRXREKEYOK);
725+
} else {
726+
TLS_INC_STATS(sock_net(sk), LINUX_MIB_TLSRXSW);
727+
TLS_INC_STATS(sock_net(sk), LINUX_MIB_TLSCURRRXSW);
728+
}
716729
conf = TLS_SW;
717730
}
718731
if (!update)
@@ -735,6 +748,10 @@ static int do_tls_setsockopt_conf(struct sock *sk, sockptr_t optval,
735748
return 0;
736749

737750
err_crypto_info:
751+
if (update) {
752+
TLS_INC_STATS(sock_net(sk), tx ? LINUX_MIB_TLSTXREKEYERROR
753+
: LINUX_MIB_TLSRXREKEYERROR);
754+
}
738755
memzero_explicit(crypto_ctx, sizeof(*crypto_ctx));
739756
return rc;
740757
}

net/tls/tls_proc.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ static const struct snmp_mib tls_mib_list[] = {
2222
SNMP_MIB_ITEM("TlsRxDeviceResync", LINUX_MIB_TLSRXDEVICERESYNC),
2323
SNMP_MIB_ITEM("TlsDecryptRetry", LINUX_MIB_TLSDECRYPTRETRY),
2424
SNMP_MIB_ITEM("TlsRxNoPadViolation", LINUX_MIB_TLSRXNOPADVIOL),
25+
SNMP_MIB_ITEM("TlsRxRekeyOk", LINUX_MIB_TLSRXREKEYOK),
26+
SNMP_MIB_ITEM("TlsRxRekeyError", LINUX_MIB_TLSRXREKEYERROR),
27+
SNMP_MIB_ITEM("TlsTxRekeyOk", LINUX_MIB_TLSTXREKEYOK),
28+
SNMP_MIB_ITEM("TlsTxRekeyError", LINUX_MIB_TLSTXREKEYERROR),
29+
SNMP_MIB_ITEM("TlsRxRekeyReceived", LINUX_MIB_TLSRXREKEYRECEIVED),
2530
SNMP_MIB_SENTINEL
2631
};
2732

net/tls/tls_sw.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,7 +1724,8 @@ tls_decrypt_device(struct sock *sk, struct msghdr *msg,
17241724
return 1;
17251725
}
17261726

1727-
static int tls_check_pending_rekey(struct tls_context *ctx, struct sk_buff *skb)
1727+
static int tls_check_pending_rekey(struct sock *sk, struct tls_context *ctx,
1728+
struct sk_buff *skb)
17281729
{
17291730
const struct strp_msg *rxm = strp_msg(skb);
17301731
const struct tls_msg *tlm = tls_msg(skb);
@@ -1747,6 +1748,7 @@ static int tls_check_pending_rekey(struct tls_context *ctx, struct sk_buff *skb)
17471748
struct tls_sw_context_rx *rx_ctx = ctx->priv_ctx_rx;
17481749

17491750
WRITE_ONCE(rx_ctx->key_update_pending, true);
1751+
TLS_INC_STATS(sock_net(sk), LINUX_MIB_TLSRXREKEYRECEIVED);
17501752
}
17511753

17521754
return 0;
@@ -1771,7 +1773,7 @@ static int tls_rx_one_record(struct sock *sk, struct msghdr *msg,
17711773
rxm->full_len -= prot->overhead_size;
17721774
tls_advance_record_sn(sk, prot, &tls_ctx->rx);
17731775

1774-
return tls_check_pending_rekey(tls_ctx, darg->skb);
1776+
return tls_check_pending_rekey(sk, tls_ctx, darg->skb);
17751777
}
17761778

17771779
int decrypt_skb(struct sock *sk, struct scatterlist *sgout)

0 commit comments

Comments
 (0)