Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2467434pxb; Mon, 19 Apr 2021 06:29:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw58OrlVRJb0P0x5oUo9oEWVZGbVzesglKkMSdFL27aACG6EFTnKMB6vigO1uyL9xbldgmr X-Received: by 2002:a05:6402:11c9:: with SMTP id j9mr25443652edw.348.1618838949355; Mon, 19 Apr 2021 06:29:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618838949; cv=none; d=google.com; s=arc-20160816; b=Xc7GKW/S2GWC0WLoo+PjDifbKQHyWqujZoX6N3KI2ByfZJ6ABS7pROGUuN1kFobSOt n0esGl/G7l4CZX5sl4mNklWhd+7+j9STSnyClRDtxy4Iy0NYwd3yJAzekjGwALUYSwUq m+iMnarDTat5Luzbpfn8uo/+OB8PBCTPyEmyBNkGMy5XNyC0LNM1jwqq6HpHh/VKH7JC VcYYeUrK9gt5mZsXfVl7sZE56R5oOU+C7uC+rr4zRCD7aXkocw9BSrYIM3vDORLvfp6W Q5mCHOKbBopfi8qQH5xJQ7t4NkuxNvANGlW200yfMqcX+51SVVCIe2qyRhxEOdulBBpb EaDA== 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=FLk28VmDISP7yNzqd2ovlApkxHSrgawzc6FKTbp2B9o=; b=YW8gFtKdEG74TkRMyh+ZSbpGCtj+skT6f+WlUhRFWkKhMFz+sC0KCgMSZIQ3Tes5QG 7vWmeTRCrQMNiwOGYN4n76Z20eAn4snzzUOHGdXc2FWn4Orm6fj4zK+yu98I9S51GxBE xyPDgOelcB5zj/5ph/VRXqDxMURdUYfV6HAeQmEP5fU5bInFaCbjJ9zPEsaYXUgD0Ess KYGQRS4CTxAoQwE42TboCUAhGKO0rg1EgHznuciGn1Jwbj61iIAExR1SOLxIq3sf6DdQ PQNWWiV6M/1YCQZ7HwUTwretbZsSZX26vFYLJ13abmUhKBIBdYuiXm4am8dF2TP1e0L0 2P3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=abPj3s6C; 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 pv1si12371602ejb.679.2021.04.19.06.28.45; Mon, 19 Apr 2021 06:29:09 -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=abPj3s6C; 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 S241362AbhDSN1Z (ORCPT + 99 others); Mon, 19 Apr 2021 09:27:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:56846 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241384AbhDSNU2 (ORCPT ); Mon, 19 Apr 2021 09:20:28 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0E9DB613EF; Mon, 19 Apr 2021 13:16:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1618838187; bh=HNSAbn1dJChIE2tqJjtRXwhmvHD7qjazVNsMwlUNazM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=abPj3s6Ck7KfA86rp97WFthz7zS84qKx11qZvzDHCqtZ1/XIyooWY96gf/GYav+QT ekGFsj+SOYBv5Bmx7hs0l7h0ONGP3kiPHRJLfnVHNJp4HQk/qUIRPDtT6AvrlOy512 W5CphUd1pmcd0U+aa6Dw4k3mf4D0BQAc08Vw44Fs= 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 073/103] net: Make tcp_allowed_congestion_control readonly in non-init netns Date: Mon, 19 Apr 2021 15:06:24 +0200 Message-Id: <20210419130530.324159057@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210419130527.791982064@linuxfoundation.org> References: <20210419130527.791982064@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 97684f0970f6e112926de631fdd98d9693c7e5c1 upstream. Currently, tcp_allowed_congestion_control is global and writable; writing to it in any net namespace will leak into all other net namespaces. tcp_available_congestion_control and tcp_allowed_congestion_control are the only sysctls in ipv4_net_table (the per-netns sysctl table) with a NULL data pointer; their handlers (proc_tcp_available_congestion_control and proc_allowed_congestion_control) have no other way of referencing a struct net. Thus, they operate globally. Because ipv4_net_table does not use designated initializers, there is no easy way to fix up this one "bad" table entry. However, the data pointer updating logic shouldn't be applied to NULL pointers anyway, so we instead force these entries to be read-only. These sysctls used to exist in ipv4_table (init-net only), but they were moved to the per-net ipv4_net_table, presumably without realizing that tcp_allowed_congestion_control was writable and thus introduced a leak. Because the intent of that commit was only to know (i.e. read) "which congestion algorithms are available or allowed", this read-only solution should be sufficient. The logic added in recent commit 31c4d2f160eb: ("net: Ensure net namespace isolation of sysctls") does not and cannot check for NULL data pointers, because other table entries (e.g. /proc/sys/net/netfilter/nf_log/) have .data=NULL but use other methods (.extra2) to access the struct net. Fixes: 9cb8e048e5d9 ("net/ipv4/sysctl: show tcp_{allowed, available}_congestion_control in non-initial netns") Signed-off-by: Jonathon Reinhart Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/ipv4/sysctl_net_ipv4.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) --- a/net/ipv4/sysctl_net_ipv4.c +++ b/net/ipv4/sysctl_net_ipv4.c @@ -1369,9 +1369,19 @@ static __net_init int ipv4_sysctl_init_n if (!table) goto err_alloc; - /* Update the variables to point into the current struct net */ - for (i = 0; i < ARRAY_SIZE(ipv4_net_table) - 1; i++) - table[i].data += (void *)net - (void *)&init_net; + for (i = 0; i < ARRAY_SIZE(ipv4_net_table) - 1; i++) { + if (table[i].data) { + /* Update the variables to point into + * the current struct net + */ + table[i].data += (void *)net - (void *)&init_net; + } else { + /* Entries without data pointer are global; + * Make them read-only in non-init_net ns + */ + table[i].mode &= ~0222; + } + } } net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);