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


Groups > linux.kernel > #1402876 > unrolled thread

Re: [PATCH] net: af_unix: protect ->sk_shutdown change with lock_sock()

Started byHannes Frederic Sowa <hannes@stressinduktion.org>
First post2016-05-18 12:40 +0200
Last post2016-05-18 15:00 +0200
Articles 11 — 4 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  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

#1402876 — Re: [PATCH] net: af_unix: protect ->sk_shutdown change with lock_sock()

FromHannes Frederic Sowa <hannes@stressinduktion.org>
Date2016-05-18 12:40 +0200
SubjectRe: [PATCH] net: af_unix: protect ->sk_shutdown change with lock_sock()
Message-ID<rA73s-SY-33@gated-at.bofh.it>
On 18.05.2016 12:14, Andrey Ryabinin wrote:
> ->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 that by protecting writes to ->sk_shutdown with lock_sock()

Is it possible to move sk_shutdown out of the bitfields? Maybe a whole
which suites is available somewhere?

af_unix doesn't depend on the socket locks anywhere and it would keep
locking much easier if we only depend on the state lock.

Bye,
Hannes

[toc] | [next] | [standalone]


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

FromAndrey Ryabinin <aryabinin@virtuozzo.com>
Date2016-05-18 14:10 +0200
Subject[PATCH v2] net: sock: move ->sk_shutdown out of bitfields.
Message-ID<rA8sy-1WF-9@gated-at.bofh.it>
In reply to#1402876
->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

[toc] | [prev] | [next] | [standalone]


#1402964 — Re: [PATCH v2] net: sock: move ->sk_shutdown out of bitfields.

FromEric Dumazet <eric.dumazet@gmail.com>
Date2016-05-18 15:10 +0200
SubjectRe: [PATCH v2] net: sock: move ->sk_shutdown out of bitfields.
Message-ID<rA9oB-2yO-9@gated-at.bofh.it>
In reply to#1402906
On Wed, 2016-05-18 at 15:03 +0300, Andrey Ryabinin wrote:
> ->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,


Please replace by a padding, so that sk_protocol is sill a byte,
not 8 bits spaning 2 bytes in memory.

> -				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;

Thanks.

[toc] | [prev] | [next] | [standalone]


#1402974 — Re: [PATCH v2] net: sock: move ->sk_shutdown out of bitfields.

FromAndrey Ryabinin <aryabinin@virtuozzo.com>
Date2016-05-18 15:30 +0200
SubjectRe: [PATCH v2] net: sock: move ->sk_shutdown out of bitfields.
Message-ID<rA9HX-2GR-13@gated-at.bofh.it>
In reply to#1402964

On 05/18/2016 04:03 PM, Eric Dumazet wrote:
> On Wed, 2016-05-18 at 15:03 +0300, Andrey Ryabinin wrote:
>> ->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,
> 
> 
> Please replace by a padding, so that sk_protocol is sill a byte,
> not 8 bits spaning 2 bytes in memory.

I think, it would be better to have something like this:

	u16 sk_type;
	u8 sk_protocol;
	kmemcheck_bitfield_begin(flags);
	u8			sk_no_check_tx : 1,
				sk_no_check_rx : 1,
				sk_userlocks : 4,
	kmemcheck_bitfield_end(flags);

[toc] | [prev] | [next] | [standalone]


#1402992 — Re: [PATCH v2] net: sock: move ->sk_shutdown out of bitfields.

FromEric Dumazet <eric.dumazet@gmail.com>
Date2016-05-18 15:50 +0200
SubjectRe: [PATCH v2] net: sock: move ->sk_shutdown out of bitfields.
Message-ID<rAa1k-2O5-23@gated-at.bofh.it>
In reply to#1402974
On Wed, 2016-05-18 at 16:14 +0300, Andrey Ryabinin wrote:
> 
> On 05/18/2016 04:03 PM, Eric Dumazet wrote:
> > On Wed, 2016-05-18 at 15:03 +0300, Andrey Ryabinin wrote:
> >> ->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,
> > 
> > 
> > Please replace by a padding, so that sk_protocol is sill a byte,
> > not 8 bits spaning 2 bytes in memory.
> 
> I think, it would be better to have something like this:
> 
> 	u16 sk_type;
> 	u8 sk_protocol;
> 	kmemcheck_bitfield_begin(flags);
> 	u8			sk_no_check_tx : 1,
> 				sk_no_check_rx : 1,
> 				sk_userlocks : 4,
> 	kmemcheck_bitfield_end(flags);
> 
> 

No. This would add extra 32 bits for KMEMCHECK users.

Check kmemcheck_bitfield_begin definition.

These fields are together to fill 32 bits.

[toc] | [prev] | [next] | [standalone]


#1403051 — [PATCH v3] net: sock: move ->sk_shutdown out of bitfields.

FromAndrey Ryabinin <aryabinin@virtuozzo.com>
Date2016-05-18 17:00 +0200
Subject[PATCH v3] net: sock: move ->sk_shutdown out of bitfields.
Message-ID<rAb73-3s8-11@gated-at.bofh.it>
In reply to#1402964
->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>
---

Changes since v1:
 - move sk_shutdown into a separate byte instead of locking
	AF_UNIX sockets.

Changes since v2:
 - reorder bitfields, so that sk_type/sk_protocol still fit in
    separate 2-bytes/byte.
	
 include/net/sock.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/net/sock.h b/include/net/sock.h
index c9c8b19..1c019d4 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -383,12 +383,11 @@ struct sock {
 	int			sk_sndbuf;
 	struct sk_buff_head	sk_write_queue;
 	kmemcheck_bitfield_begin(flags);
-	unsigned int		sk_shutdown  : 2,
+	unsigned int		sk_type : 16,
+				sk_protocol : 8,
 				sk_no_check_tx : 1,
 				sk_no_check_rx : 1,
-				sk_userlocks : 4,
-				sk_protocol  : 8,
-				sk_type      : 16;
+				sk_userlocks : 4;
 #define SK_PROTOCOL_MAX U8_MAX
 	kmemcheck_bitfield_end(flags);
 	int			sk_wmem_queued;
@@ -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

[toc] | [prev] | [next] | [standalone]


#1403104 — Re: [PATCH v3] net: sock: move ->sk_shutdown out of bitfields.

FromEric Dumazet <eric.dumazet@gmail.com>
Date2016-05-18 17:40 +0200
SubjectRe: [PATCH v3] net: sock: move ->sk_shutdown out of bitfields.
Message-ID<rAbJM-3Wj-27@gated-at.bofh.it>
In reply to#1403051
On Wed, 2016-05-18 at 17:36 +0300, Andrey Ryabinin wrote:
> ->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>
> ---
> 
> Changes since v1:
>  - move sk_shutdown into a separate byte instead of locking
> 	AF_UNIX sockets.
> 
> Changes since v2:
>  - reorder bitfields, so that sk_type/sk_protocol still fit in
>     separate 2-bytes/byte.
> 	

I suggested to use an explicit padding, to clearly show that two bits
are available there. You also could add a comment to remind the rules.

Something like :

diff --git a/include/net/sock.h b/include/net/sock.h
index c9c8b19df27c558354687119db60c0716909ea3f..4e239a7ef4f67b1988fe119d81566d1465a2b596 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -382,8 +382,10 @@ struct sock {
 	atomic_t		sk_omem_alloc;
 	int			sk_sndbuf;
 	struct sk_buff_head	sk_write_queue;
+
+	/* because of non atomicity rules, all changes are protected by socket lock */
 	kmemcheck_bitfield_begin(flags);
-	unsigned int		sk_shutdown  : 2,
+	unsigned int		sk_padding   : 2,
 				sk_no_check_tx : 1,
 				sk_no_check_rx : 1,
 				sk_userlocks : 4,
@@ -391,6 +393,7 @@ struct sock {
 				sk_type      : 16;
 #define SK_PROTOCOL_MAX U8_MAX
 	kmemcheck_bitfield_end(flags);
+
 	int			sk_wmem_queued;
 	gfp_t			sk_allocation;
 	u32			sk_pacing_rate; /* bytes per second */
@@ -418,6 +421,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;

[toc] | [prev] | [next] | [standalone]


#1403151 — [PATCH v4] net: sock: move ->sk_shutdown out of bitfields.

FromAndrey Ryabinin <aryabinin@virtuozzo.com>
Date2016-05-18 19:00 +0200
Subject[PATCH v4] net: sock: move ->sk_shutdown out of bitfields.
Message-ID<rAcZb-4DW-5@gated-at.bofh.it>
In reply to#1403104
->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>
---

Changes since v1:
 - move sk_shutdown into a separate byte instead of locking
	AF_UNIX sockets.

Changes since v2:
 - reorder bitfields, so that sk_type/sk_protocol still fit in
    separate 2-bytes/byte.

Changes since v3:
  - padding and comment per Eric.

 include/net/sock.h | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/include/net/sock.h b/include/net/sock.h
index c9c8b19..649d2a8 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -382,8 +382,13 @@ struct sock {
 	atomic_t		sk_omem_alloc;
 	int			sk_sndbuf;
 	struct sk_buff_head	sk_write_queue;
+
+	/*
+	 * Because of non atomicity rules, all
+	 * changes are protected by socket lock.
+	 */
 	kmemcheck_bitfield_begin(flags);
-	unsigned int		sk_shutdown  : 2,
+	unsigned int		sk_padding : 2,
 				sk_no_check_tx : 1,
 				sk_no_check_rx : 1,
 				sk_userlocks : 4,
@@ -391,6 +396,7 @@ struct sock {
 				sk_type      : 16;
 #define SK_PROTOCOL_MAX U8_MAX
 	kmemcheck_bitfield_end(flags);
+
 	int			sk_wmem_queued;
 	gfp_t			sk_allocation;
 	u32			sk_pacing_rate; /* bytes per second */
@@ -418,6 +424,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

[toc] | [prev] | [next] | [standalone]


#1403166 — Re: [PATCH v4] net: sock: move ->sk_shutdown out of bitfields.

FromEric Dumazet <eric.dumazet@gmail.com>
Date2016-05-18 19:20 +0200
SubjectRe: [PATCH v4] net: sock: move ->sk_shutdown out of bitfields.
Message-ID<rAdiy-4ZK-7@gated-at.bofh.it>
In reply to#1403151
On Wed, 2016-05-18 at 19:19 +0300, Andrey Ryabinin wrote:
> ->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>

[toc] | [prev] | [next] | [standalone]


#1404745 — Re: [PATCH v4] net: sock: move ->sk_shutdown out of bitfields.

FromDavid Miller <davem@davemloft.net>
Date2016-05-21 00:10 +0200
SubjectRe: [PATCH v4] net: sock: move ->sk_shutdown out of bitfields.
Message-ID<rB0Mi-3lX-5@gated-at.bofh.it>
In reply to#1403151
From: Andrey Ryabinin <aryabinin@virtuozzo.com>
Date: Wed, 18 May 2016 19:19:27 +0300

> ->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>

Looks good, applied and queued up for -stable.

Thanks.

[toc] | [prev] | [next] | [standalone]


#1402962

FromAndrey Ryabinin <aryabinin@virtuozzo.com>
Date2016-05-18 15:00 +0200
Message-ID<rA9eW-2gz-13@gated-at.bofh.it>
In reply to#1402876

On 05/18/2016 01:38 PM, Hannes Frederic Sowa wrote:
> On 18.05.2016 12:14, Andrey Ryabinin wrote:
>> ->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 that by protecting writes to ->sk_shutdown with lock_sock()
> 
> Is it possible to move sk_shutdown out of the bitfields? Maybe a whole
> which suites is available somewhere?
> 

Agreed. I see two possible 16-bit holes - one after 'sk_gso_max_segs'
and one more after 'sk_tsflags'.


> af_unix doesn't depend on the socket locks anywhere and it would keep
> locking much easier if we only depend on the state lock.
> 
> Bye,
> Hannes
> 
> 

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web