Netdev List
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: Eric Dumazet <edumazet@google.com>
Cc: "David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	netdev@vger.kernel.org, Simon Horman <horms@kernel.org>,
	eric.dumazet@gmail.com,
	syzbot+b3e02953598f447d4d2a@syzkaller.appspotmail.com,
	Martin KaFai Lau <kafai@fb.com>
Subject: Re: [PATCH net] net: restrict SO_REUSEPORT to TCP, UDP and SCTP sockets
Date: Tue, 31 Dec 2024 18:33:39 +0000	[thread overview]
Message-ID: <20241231183339.6ee59b64@dsl-u17-10> (raw)
In-Reply-To: <20241230193430.3148259-1-edumazet@google.com>

On Mon, 30 Dec 2024 19:34:30 +0000
Eric Dumazet <edumazet@google.com> wrote:

> After blamed commit, crypto sockets could accidentally be destroyed
> from RCU callback, as spotted by zyzbot [1].
> 
> Trying to acquire a mutex in RCU callback is not allowed.
> 
> Restrict SO_REUSEPORT socket option to TCP, UDP and SCTP sockets.
> 
...
> 
> Fixes: 8c7138b33e5c ("net: Unpublish sk from sk_reuseport_cb before call_rcu")
> Reported-by: syzbot+b3e02953598f447d4d2a@syzkaller.appspotmail.com
> Closes: https://lore.kernel.org/netdev/6772f2f4.050a0220.2f3838.04cb.GAE@google.com/T/#u
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Martin KaFai Lau <kafai@fb.com>
> ---
>  include/net/sock.h | 7 +++++++
>  net/core/sock.c    | 6 +++++-
>  2 files changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/include/net/sock.h b/include/net/sock.h
> index 7464e9f9f47c..4010fd759e2a 100644
> --- a/include/net/sock.h
> +++ b/include/net/sock.h
> @@ -2730,6 +2730,13 @@ static inline bool sk_is_tcp(const struct sock *sk)
>  	       sk->sk_protocol == IPPROTO_TCP;
>  }
>  
> +static inline bool sk_is_sctp(const struct sock *sk)
> +{
> +	return sk_is_inet(sk) &&
> +	       sk->sk_type == SOCK_STREAM &&
> +	       sk->sk_protocol == IPPROTO_SCTP;
> +}

Isn't SCTP SOCK_SEQPACKET ?
In any case the sk_type test is redundant (for inet sockets).

If support is needed for raw (ip) sockets is it enough to just
check sk_is_inet() ?

	David

> +
>  static inline bool sk_is_udp(const struct sock *sk)
>  {
>  	return sk_is_inet(sk) &&
> diff --git a/net/core/sock.c b/net/core/sock.c
> index 74729d20cd00..56e8517da8dc 100644
> --- a/net/core/sock.c
> +++ b/net/core/sock.c
> @@ -1295,7 +1295,11 @@ int sk_setsockopt(struct sock *sk, int level, int optname,
>  		sk->sk_reuse = (valbool ? SK_CAN_REUSE : SK_NO_REUSE);
>  		break;
>  	case SO_REUSEPORT:
> -		sk->sk_reuseport = valbool;
> +		if (valbool && !sk_is_tcp(sk) && !sk_is_udp(sk) &&
> +		    !sk_is_sctp(sk))
> +			ret = -EOPNOTSUPP;
> +		else
> +			sk->sk_reuseport = valbool;
>  		break;
>  	case SO_DONTROUTE:
>  		sock_valbool_flag(sk, SOCK_LOCALROUTE, valbool);


      parent reply	other threads:[~2024-12-31 18:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-30 19:34 [PATCH net] net: restrict SO_REUSEPORT to TCP, UDP and SCTP sockets Eric Dumazet
2024-12-31  0:07 ` Jakub Kicinski
2024-12-31 12:44   ` Eric Dumazet
2025-01-10 19:13     ` Martin KaFai Lau
2024-12-31 18:33 ` David Laight [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241231183339.6ee59b64@dsl-u17-10 \
    --to=david.laight.linux@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=eric.dumazet@gmail.com \
    --cc=horms@kernel.org \
    --cc=kafai@fb.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=syzbot+b3e02953598f447d4d2a@syzkaller.appspotmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox