netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathon Reinhart <jonathon.reinhart@gmail.com>
To: Linux Netdev List <netdev@vger.kernel.org>
Cc: Eric Dumazet <edumazet@google.com>,
	"David S. Miller" <davem@davemloft.net>,
	Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>,
	David Ahern <dsahern@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>,
	Stephen Hemminger <stephen@networkplumber.org>
Subject: Re: [PATCH] net: Only allow init netns to set default tcp cong to a restricted algo
Date: Sat, 1 May 2021 04:50:43 -0400	[thread overview]
Message-ID: <CAPFHKzc4OWiL+d6kuCHT3r4A4u13oydsVA09RfG0r2Sh9dCADg@mail.gmail.com> (raw)
In-Reply-To: <20210501082822.726-1-jonathon.reinhart@gmail.com>

On Sat, May 1, 2021 at 4:29 AM Jonathon Reinhart
<jonathon.reinhart@gmail.com> wrote:
>
> tcp_set_default_congestion_control() is netns-safe in that it writes
> to &net->ipv4.tcp_congestion_control, but it also sets
> ca->flags |= TCP_CONG_NON_RESTRICTED which is not namespaced.
> This has the unintended side-effect of changing the global
> net.ipv4.tcp_allowed_congestion_control sysctl, despite the fact that it
> is read-only: 97684f0970f6 ("net: Make tcp_allowed_congestion_control
> readonly in non-init netns")
>
> Resolve this netns "leak" by only allowing the init netns to set the
> default algorithm to one that is restricted. This restriction could be
> removed if tcp_allowed_congestion_control were namespace-ified in the
> future.
>
> This bug was uncovered with
> https://github.com/JonathonReinhart/linux-netns-sysctl-verify
>
> Fixes: 6670e1524477 ("tcp: Namespace-ify sysctl_tcp_default_congestion_control")
> Signed-off-by: Jonathon Reinhart <jonathon.reinhart@gmail.com>
> ---
>  net/ipv4/tcp_cong.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/net/ipv4/tcp_cong.c b/net/ipv4/tcp_cong.c
> index 563d016e7478..db5831e6c136 100644
> --- a/net/ipv4/tcp_cong.c
> +++ b/net/ipv4/tcp_cong.c
> @@ -230,6 +230,10 @@ int tcp_set_default_congestion_control(struct net *net, const char *name)
>                 ret = -ENOENT;
>         } else if (!bpf_try_module_get(ca, ca->owner)) {
>                 ret = -EBUSY;
> +       } else if (!net_eq(net, &init_net) &&
> +                       !(ca->flags & TCP_CONG_NON_RESTRICTED)) {
> +               /* Only init netns can set default to a restricted algorithm */
> +               ret = -EPERM;
>         } else {
>                 prev = xchg(&net->ipv4.tcp_congestion_control, ca);
>                 if (prev)
> --
> 2.20.1
>

This should be targeting "net" (and stable), not "net-next". Sorry about that.

  reply	other threads:[~2021-05-01  8:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-01  8:28 [PATCH] net: Only allow init netns to set default tcp cong to a restricted algo Jonathon Reinhart
2021-05-01  8:50 ` Jonathon Reinhart [this message]
2021-05-04 19:10 ` patchwork-bot+netdevbpf

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=CAPFHKzc4OWiL+d6kuCHT3r4A4u13oydsVA09RfG0r2Sh9dCADg@mail.gmail.com \
    --to=jonathon.reinhart@gmail.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.org \
    --cc=yoshfuji@linux-ipv6.org \
    /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;
as well as URLs for NNTP newsgroup(s).