Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4755355pxj; Wed, 12 May 2021 12:30:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJweS2ITPFH9nb1a41/+2sibQzLfycTLRffnRMXalm4Rk4U4NqxNySx+DDYs+0vepDonj31b X-Received: by 2002:a17:906:90c9:: with SMTP id v9mr744644ejw.102.1620847801956; Wed, 12 May 2021 12:30:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620847801; cv=none; d=google.com; s=arc-20160816; b=IS9oZFan2FAgTpcHyVcksLES4NJC68b8Sf832chPcymlfQ4WyYNBF3uaEgPYtwrBOQ k5WsG87YWtYIaMLCsHaIy3bBKCcUSFtvGuaEPEBbrdFAgh4wtbAercpYKXTgdc4Id52C 5TvQVoJpxjNrw2iavp4yaJYoMtI05RkYChs4eNQ0//9XdnCTjq5G3mp///7qKHlqq/4q T1HYJj1serUZjcmudQAtxTWudTi1H0gc+ypk6n0YGoeqFtcCzE4lMcphb3Em1/UmoguP h5bClrH9xN14+Ya/VxDYSJvHq4hEjrXuKo+8HiUYvouPbmc9CpQGeo9CQJF0Jw/iCqyK jRHQ== 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=wcN6A1PO8yHiKeI1fjIMfG6F5QXHmmoDp6OyU0mfPxGNq3Hxh/3oY2p0wlmJXs4z8l XlOp55//mQvygRduly6Ti2d4Rg447s0rsu0qmUEJNos76/JuiIXb+S/gS2k3EAf16ZAJ J7Y0ovUkdKdysT6BEs0CeeCKXlnpywN4IOfIcQn4sYi3w5boX3OMdTd7DEuQsrErZdF/ EmZ4enymF+3H+qadm3lsvrCAoHNMeUey9VV0JGn5zSFxnpYjIOrLN/e2Yz7bZK98udF5 oRVtRqihsVKln80+uARMThZ+CP+skeIYwjH4UH3BU0yjc+l1eeanh1EJO2K+TWnQbc5R 4WfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=oUQX2abf; 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 f8si483178edx.424.2021.05.12.12.29.38; Wed, 12 May 2021 12:30:01 -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=oUQX2abf; 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 S1379688AbhELTUJ (ORCPT + 99 others); Wed, 12 May 2021 15:20:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:48032 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244738AbhELQvI (ORCPT ); Wed, 12 May 2021 12:51:08 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4215461C87; Wed, 12 May 2021 16:17:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620836260; bh=Wt57QDeArhmn2GF4PFUp8kdwhsEB6xAJlXWdbPlBC1k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oUQX2abfvJDnfYb2BX8Gz9ZlTES/yI5pOBhEt+sNxt9upmB9+xz/5JnLEAmZDPdDD FRLfySzCSg/GlIOtGFFqy1QTWhZHN5PwHhTzA1oB1AB+Cqnucg+hh2HqKcF9T+nWud jPUs6iPkAAJF/eVsvTb0Z9tgHoXNBmv0ApSiAocY= 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.12 674/677] net: Only allow init netns to set default tcp cong to a restricted algo Date: Wed, 12 May 2021 16:52:00 +0200 Message-Id: <20210512144859.753028072@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144837.204217980@linuxfoundation.org> References: <20210512144837.204217980@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)