[PATCH v1 1/3] net/af_packet: fix thread safety and frame calculations

Stephen Hemminger stephen at networkplumber.org
Tue Jan 27 19:39:11 CET 2026


On Tue, 27 Jan 2026 10:13:53 -0800
scott.k.mitch1 at gmail.com wrote:

> From: Scott Mitchell <scott.k.mitch1 at gmail.com>
> 
> The AF_PACKET driver had multiple correctness issues that could
> cause data races and memory corruption in multi-threaded environments.
> 
> Thread Safety Issues:
> 
> 1. Statistics counters (rx_pkts, tx_pkts, rx_bytes, tx_bytes, etc.)
>    were declared as 'volatile unsigned long' which provides no
>    atomicity guarantees and can cause torn reads/writes on 32-bit
>    platforms or when the compiler uses multiple instructions.


This is bad idea

Atomic is even more expensive and only one thread should be updating
at a time. If you want to handle 32 bit platforms then something
like the Linux kernel mechanism for stats is needed. It does:
  - on 32 bit platforms does a multiple read look (like seqlock)
  - on 64 bit platforms is just regular operations.



More information about the stable mailing list