On RX the netdev byte counter accounts the decrypted payload, but TX does not follow the same rule. For UDP, the tunnel helpers compute the packet length from the inner network header, which ovpn never sets: the value is inherited from the plaintext skb and may point anywhere, leading to random counts. For TCP, the whole encrypted packet, including the length prefix, is accounted. Mark the payload with the inner network header before encryption and account it on TX for both transports, as done on RX and by wireguard. Userspace messages sent over TCP are not encrypted and are still accounted entirely. Fixes: 08857b5ec5d9 ("ovpn: implement basic TX path (UDP)") Fixes: 11851cbd60ea ("ovpn: implement TCP transport") Cc: stable@vger.kernel.org Signed-off-by: Antonio Quartulli --- drivers/net/ovpn/io.c | 2 ++ drivers/net/ovpn/tcp.c | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/net/ovpn/io.c b/drivers/net/ovpn/io.c index 402a74a2a27b..a11ad979e9f3 100644 --- a/drivers/net/ovpn/io.c +++ b/drivers/net/ovpn/io.c @@ -328,6 +328,8 @@ static bool ovpn_encrypt_one(struct ovpn_peer *peer, struct sk_buff *skb) } memset(ovpn_skb_cb(skb), 0, sizeof(struct ovpn_cb)); + /* TX stats account the payload only, like RX */ + skb_reset_inner_network_header(skb); ovpn_encrypt_post(skb, ovpn_aead_encrypt(peer, ks, skb)); return true; } diff --git a/drivers/net/ovpn/tcp.c b/drivers/net/ovpn/tcp.c index 5340860c0b82..00cab8d2aa6a 100644 --- a/drivers/net/ovpn/tcp.c +++ b/drivers/net/ovpn/tcp.c @@ -294,7 +294,8 @@ static void ovpn_tcp_send_sock(struct ovpn_peer *peer, struct sock *sk) if (!peer->tcp.out_msg.len) { local_bh_disable(); - dev_dstats_tx_add(peer->ovpn->dev, skb->len); + dev_dstats_tx_add(peer->ovpn->dev, + skb->len - skb_inner_network_offset(skb)); local_bh_enable(); } @@ -446,6 +447,8 @@ static int ovpn_tcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) goto peer_free; } + /* userspace messages are not encrypted: account them entirely */ + skb_reset_inner_network_header(skb); ovpn_skb_cb(skb)->nosignal = msg->msg_flags & MSG_NOSIGNAL; ovpn_tcp_send_sock_skb(peer, sk, skb); ret = size;