diff options
author | Eric Dumazet <edumazet@google.com> | 2023-03-16 01:10:07 +0000 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2023-03-17 08:52:05 +0000 |
commit | ee5675ecdf7a4e713ed21d98a70c2871d6ebed01 (patch) | |
tree | be50e68015ab84229d2f3cd223e352be1df2bb2f /net/packet/internal.h | |
parent | b9d83ab8a708f23a4001d60e9d8d0b3be3d9f607 (diff) | |
download | linux-ee5675ecdf7a4e713ed21d98a70c2871d6ebed01.tar.gz linux-ee5675ecdf7a4e713ed21d98a70c2871d6ebed01.tar.bz2 linux-ee5675ecdf7a4e713ed21d98a70c2871d6ebed01.zip |
net/packet: convert po->origdev to an atomic flag
syzbot/KCAN reported that po->origdev can be read
while another thread is changing its value.
We can avoid this splat by converting this field
to an actual bit.
Following patches will convert remaining 1bit fields.
Fixes: 80feaacb8a64 ("[AF_PACKET]: Add option to return orig_dev to userspace.")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: syzbot <syzkaller@googlegroups.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/packet/internal.h')
-rw-r--r-- | net/packet/internal.h | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/net/packet/internal.h b/net/packet/internal.h index 48af35b1aed2..178cd1852238 100644 --- a/net/packet/internal.h +++ b/net/packet/internal.h @@ -116,9 +116,9 @@ struct packet_sock { int copy_thresh; spinlock_t bind_lock; struct mutex pg_vec_lock; + unsigned long flags; unsigned int running; /* bind_lock must be held */ unsigned int auxdata:1, /* writer must hold sock lock */ - origdev:1, has_vnet_hdr:1, tp_loss:1, tp_tx_has_off:1; @@ -144,4 +144,24 @@ static inline struct packet_sock *pkt_sk(struct sock *sk) return (struct packet_sock *)sk; } +enum packet_sock_flags { + PACKET_SOCK_ORIGDEV, +}; + +static inline void packet_sock_flag_set(struct packet_sock *po, + enum packet_sock_flags flag, + bool val) +{ + if (val) + set_bit(flag, &po->flags); + else + clear_bit(flag, &po->flags); +} + +static inline bool packet_sock_flag(const struct packet_sock *po, + enum packet_sock_flags flag) +{ + return test_bit(flag, &po->flags); +} + #endif |