Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1402906

[PATCH v2] net: sock: move ->sk_shutdown out of bitfields.

From Andrey Ryabinin <aryabinin@virtuozzo.com>
Newsgroups linux.kernel
Subject [PATCH v2] net: sock: move ->sk_shutdown out of bitfields.
Date 2016-05-18 14:10 +0200
Message-ID <rA8sy-1WF-9@gated-at.bofh.it> (permalink)
References <rA73s-SY-33@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


->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>
---
 include/net/sock.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/net/sock.h b/include/net/sock.h
index c9c8b19..04dc131 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -383,8 +383,7 @@ struct sock {
 	int			sk_sndbuf;
 	struct sk_buff_head	sk_write_queue;
 	kmemcheck_bitfield_begin(flags);
-	unsigned int		sk_shutdown  : 2,
-				sk_no_check_tx : 1,
+	unsigned int		sk_no_check_tx : 1,
 				sk_no_check_rx : 1,
 				sk_userlocks : 4,
 				sk_protocol  : 8,
@@ -418,6 +417,7 @@ struct sock {
 	struct timer_list	sk_timer;
 	ktime_t			sk_stamp;
 	u16			sk_tsflags;
+	u8			sk_shutdown;
 	u32			sk_tskey;
 	struct socket		*sk_socket;
 	void			*sk_user_data;
-- 
2.7.3

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: [PATCH] net: af_unix: protect ->sk_shutdown change with  lock_sock() Hannes Frederic Sowa <hannes@stressinduktion.org> - 2016-05-18 12:40 +0200
  [PATCH v2] net: sock: move ->sk_shutdown out of bitfields. Andrey Ryabinin <aryabinin@virtuozzo.com> - 2016-05-18 14:10 +0200
    Re: [PATCH v2] net: sock: move ->sk_shutdown out of bitfields. Eric Dumazet <eric.dumazet@gmail.com> - 2016-05-18 15:10 +0200
      Re: [PATCH v2] net: sock: move ->sk_shutdown out of bitfields. Andrey Ryabinin <aryabinin@virtuozzo.com> - 2016-05-18 15:30 +0200
        Re: [PATCH v2] net: sock: move ->sk_shutdown out of bitfields. Eric Dumazet <eric.dumazet@gmail.com> - 2016-05-18 15:50 +0200
      [PATCH v3] net: sock: move ->sk_shutdown out of bitfields. Andrey Ryabinin <aryabinin@virtuozzo.com> - 2016-05-18 17:00 +0200
        Re: [PATCH v3] net: sock: move ->sk_shutdown out of bitfields. Eric Dumazet <eric.dumazet@gmail.com> - 2016-05-18 17:40 +0200
          [PATCH v4] net: sock: move ->sk_shutdown out of bitfields. Andrey Ryabinin <aryabinin@virtuozzo.com> - 2016-05-18 19:00 +0200
            Re: [PATCH v4] net: sock: move ->sk_shutdown out of bitfields. Eric Dumazet <eric.dumazet@gmail.com> - 2016-05-18 19:20 +0200
            Re: [PATCH v4] net: sock: move ->sk_shutdown out of bitfields. David Miller <davem@davemloft.net> - 2016-05-21 00:10 +0200
  Re: [PATCH] net: af_unix: protect ->sk_shutdown change with  lock_sock() Andrey Ryabinin <aryabinin@virtuozzo.com> - 2016-05-18 15:00 +0200

csiph-web