Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4635138pxj; Wed, 12 May 2021 09:43:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyviwDhdD/rXpwsxs64Cc75XmqwWRv57TfPQSTwEg9j/pyzAtJG+OF1jCr48HrKroxGsuUF X-Received: by 2002:a05:6402:31b1:: with SMTP id dj17mr44209209edb.7.1620837809085; Wed, 12 May 2021 09:43:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620837809; cv=none; d=google.com; s=arc-20160816; b=s5i1xyFf32/iZDhE7DNd6ZNCdyU56eBBAeg333ULN00QHwkdZYim+IBA0gKbvFiW1z dXXwR6C7OEe5R34E2CV43n7UPxtjGV+ubJYtlAenaoWq5zvfQBiaJ0CgVXqY91kvHgnq 0XqBmHAy6izjp4G/Sr2Re4jA3uTP5+2BH334zA3/QDOL8Om0UCyh9Kknh69S0gwYaCbE uCmedfda/8PODPL7zuCexaTA8E65lM/MYFTxStGOaFwPlmn0L/8BIKzSUnlqRj28h2EH LE8t7qV2XwNJw6ph81I356ddowxzbQzRGCgnbNmzBlBHMfY1hUSXwyWMQxkndGKQbPYI hKFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=j3vgBbUS0hekMHQU21Yquw6jtTuL4/X56v+41+0LVtw=; b=PuRrZM77Qe5ujdImMURDWg3E0mpuWwgUZmPo0nv30snJKyWanzqJtuu4qjfh2bHLVS /eLF0z9IcUXjL5Jy2Vey+FtgxpGixNgaQOp085HXOyioZs9WMbq9f0T77sgmwdIMCcKl TCuBtbIGwmr3i3d6P2UCCQrVFtLy8cgB1A7UMJpCI50dk21BptkcrDXj7QqnhHA5Dibm 2aqaqgtW4BZ6Xln88nzMKDT/07uar06Dt7SMyeCEBKy/KNEhhKot6SDTMx9F+Sk94wR7 FzE3Wyko1L5dmYDlgu7amF4rFDB04APPvmUm+n5uyBBNIA45XavQuPtkIRWlxQR2lM0C WolQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=13vMSe8w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c22si222939edv.55.2021.05.12.09.43.05; Wed, 12 May 2021 09:43:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=13vMSe8w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233868AbhELQnQ (ORCPT + 99 others); Wed, 12 May 2021 12:43:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:42206 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236945AbhELPrc (ORCPT ); Wed, 12 May 2021 11:47:32 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C727761CA1; Wed, 12 May 2021 15:24:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620833044; bh=Wt57QDeArhmn2GF4PFUp8kdwhsEB6xAJlXWdbPlBC1k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=13vMSe8w4VrqbEgaB/zVg2ghcHqj1/auiHmoCL9vPflKS5OYCWDzrYhsDaBXxSbEo xOnfIPIWgG1ue79SQNhUoOrQ9aa0IASDVbfpfcipFyrO4PYoYG8AniRRwepeUgNVmG hQMpa/YBR6l2Q4V6ILoM7PBlA1TXpECET285u0EQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jonathon Reinhart , "David S. Miller" Subject: [PATCH 5.10 527/530] net: Only allow init netns to set default tcp cong to a restricted algo Date: Wed, 12 May 2021 16:50:37 +0200 Message-Id: <20210512144837.064890189@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jonathon Reinhart commit 8d432592f30fcc34ef5a10aac4887b4897884493 upstream. 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 Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/ipv4/tcp_cong.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/net/ipv4/tcp_cong.c +++ b/net/ipv4/tcp_cong.c @@ -230,6 +230,10 @@ int tcp_set_default_congestion_control(s 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)