Skip to content

Commit fc64869

Browse files
aryabinindavem330
authored andcommitted
net: sock: move ->sk_shutdown out of bitfields.
->sk_shutdown bits share one bitfield with some other bits in sock struct, such as ->sk_no_check_[r,t]x, ->sk_userlocks ... sock_setsockopt() may write to these bits, while holding the socket lock. In case of AF_UNIX sockets, we change ->sk_shutdown bits while holding only unix_state_lock(). So concurrent setsockopt() and shutdown() may lead to corrupting these bits. Fix this by moving ->sk_shutdown bits out of bitfield into a separate byte. This will not change the 'struct sock' size since ->sk_shutdown moved into previously unused 16-bit hole. Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com> Suggested-by: Hannes Frederic Sowa <hannes@stressinduktion.org> Acked-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 911f6b1 commit fc64869

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

include/net/sock.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,15 +382,21 @@ struct sock {
382382
atomic_t sk_omem_alloc;
383383
int sk_sndbuf;
384384
struct sk_buff_head sk_write_queue;
385+
386+
/*
387+
* Because of non atomicity rules, all
388+
* changes are protected by socket lock.
389+
*/
385390
kmemcheck_bitfield_begin(flags);
386-
unsigned int sk_shutdown : 2,
391+
unsigned int sk_padding : 2,
387392
sk_no_check_tx : 1,
388393
sk_no_check_rx : 1,
389394
sk_userlocks : 4,
390395
sk_protocol : 8,
391396
sk_type : 16;
392397
#define SK_PROTOCOL_MAX U8_MAX
393398
kmemcheck_bitfield_end(flags);
399+
394400
int sk_wmem_queued;
395401
gfp_t sk_allocation;
396402
u32 sk_pacing_rate; /* bytes per second */
@@ -418,6 +424,7 @@ struct sock {
418424
struct timer_list sk_timer;
419425
ktime_t sk_stamp;
420426
u16 sk_tsflags;
427+
u8 sk_shutdown;
421428
u32 sk_tskey;
422429
struct socket *sk_socket;
423430
void *sk_user_data;

0 commit comments

Comments
 (0)