Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp367718pxj; Thu, 20 May 2021 11:08:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzem8NDsCsWyhX/mnfYZHafF0IakcoOGH2yqVjZvqfk+y/KOHpxbKdsvKKY8lAKENv51TZd X-Received: by 2002:a05:6e02:ee9:: with SMTP id j9mr6571007ilk.14.1621534118477; Thu, 20 May 2021 11:08:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621534118; cv=none; d=google.com; s=arc-20160816; b=oOky4uOSVF+Bmg9RnU402rsxs0+Ht3xyOXSNT2cY0WQZVU4MxkbcOuPpbLpLvgt5zJ n2Hjx0amW8fRDPSzpP4EwTI+R/fa/1OXK5k6ETKjKfwTYdc5PsT4o/N4wICzqHqTPAD6 3kplvBigW8h6TbOpXi3GbO4rGpG/w7LhIFQAifLRM8tvQGowpRLlYUK9QEkYWb4TmAND C80G+5oqjNTBIhI6ZLl6Ke6alUhkTXUVD2ohk8njQcFTeH1NmMZJh8UjXRKC+taU5Jul ZC9E/V5NHT3eZG3i9vw8l7ObwA3n5Km0MwZujI+2lF4KKM42/wxGjKogkxdClSOSMnkW 7AZg== 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=vxSUa4pQ7qsASElDVgOh3NHS0dTSZSJzJzCyngKpBaU=; b=gSht4HGOgau2kp7A2SjNkGghcwYosUXTZN+08oUlB+CGajzbhb9YDkSo8Mox1+qW8L fqWNDI8/aBYBz8EaDibvOPjqY1TKG6MjOi2p85RYfFMKsThd6Z9wZtk/dJKyZ0b9eNNb 47O5s4TU6d++3vJytfBdgHntAwz3njc0H4SfahxWoiTr5aCc2uY/upQC1Nqow2peHRs5 IVaWrFAEzBEIBQx9Xfh3Dmqopc8uo7/nH3oIZgYZ/wDDUlGo5w333oFX6qcsPTWbvHYn mcvsWK7rqcP9mSsH5McPSBZM9go8wM1TqRiydHTlmJXqx6WQ7ghN4uWlWKqFJcXx2Xlr /Vkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=oi1pICuf; 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 a14si2804238iol.90.2021.05.20.11.08.24; Thu, 20 May 2021 11:08:38 -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=oi1pICuf; 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 S235949AbhETKNP (ORCPT + 99 others); Thu, 20 May 2021 06:13:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:39942 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232048AbhETKFb (ORCPT ); Thu, 20 May 2021 06:05:31 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6953861939; Thu, 20 May 2021 09:41:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621503676; bh=yRRgUS3ItAIl0mq5NIQKEK4SulKoRVO5gWBFjXPDg9U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oi1pICufpfJWjFNJCA8V4hylsgjL5gCZ5hed829N4/zCXK8RBQPUt9p/FGa2kxN0k XfoDWa3cvZz+bT0NKj1npcTKW9Yzb/NdVJvh3MiMx3PlHgo+EJ0u+2L92Jzk9kriA/ JDz/NlXRd2yKgHwmOtiWhWJDFz8BVwgqrh7VqboU= 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 4.19 295/425] net: Only allow init netns to set default tcp cong to a restricted algo Date: Thu, 20 May 2021 11:21:04 +0200 Message-Id: <20210520092141.145797375@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092131.308959589@linuxfoundation.org> References: <20210520092131.308959589@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 @@ -228,6 +228,10 @@ int tcp_set_default_congestion_control(s ret = -ENOENT; } else if (!try_module_get(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)