Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp402832pxy; Wed, 5 May 2021 05:12:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwl6qcTS7Bp0tGvxtOGV5vPaUXdl/ewGu+p8bRHUPpNliPxECbtDg+fwAMWgF+0zAxcUFjl X-Received: by 2002:a17:906:b048:: with SMTP id bj8mr27186273ejb.236.1620216729799; Wed, 05 May 2021 05:12:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620216729; cv=none; d=google.com; s=arc-20160816; b=gK2S5f6okTck4lY2M4/CxWgXtwZc81x7OYqh/RNGw0MWlc9HIKZqCwCc2Twwq0wONi NJ8xmZ/Vj/AiT6BnBvjd/BVaXt1nYd44iD/UZ9aQ1lPCB3X6tznYObwDrPRNYdYanE2+ HJFhHVZ5h88ZMgLD04tFtvHFU5kqcbauItjqS/tmBO9RQU84y3dXqwY3raGP6JQSXDyk crhDbdqr42AWB9zQ8Jxu7dteDiR3x+SqbyWo6oGgjHitgIGV9sbQxVsoq4fycqvX3x61 0tdgPf/2CgN8wMQzWxwg6AzRETijpEX5N429OJwOrkPT/0MROQUMAbOkNHQi6uzI8DDE guaQ== 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=VJozDLeZRByF1s3VlZSg3C4yxznf1egubt/9lhknKrA=; b=QKyM71IZW9AgzHJe/cZNfHqwOhjD9ll5qbSeInilFzcDF6I1An6TDYUzUCD5n4X0bV 3t0m2YAya3tF2+L6Fyatv9ZTNVa1zcTDsc2uKwEKP4PPXhF0VWYlPRzBSCdoL7JHd9Ms QRj7smBU9Jr0bZbzIYMB0lWR+cXtGRM9pXvOGXYh3GxGg8LIr+IbCiMk5ta9NLS6EG27 rwk0kgPMjPNhTcFugyh2Xau+mgCNT+IUVIRlulUOz3KF3uKyiyccoq8c2YyzgghUsbCi yR35MtCmZ5prKlJ5G6Y/oZ5yfey+4JPByw0rg5kMKa4Uvjse2+yQA+WbhWgWqRB8PNV1 Y78A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fkBT7OhZ; 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 o6si2777067edi.18.2021.05.05.05.11.36; Wed, 05 May 2021 05:12: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=fkBT7OhZ; 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 S233521AbhEEMIX (ORCPT + 99 others); Wed, 5 May 2021 08:08:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:47482 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231995AbhEEMHg (ORCPT ); Wed, 5 May 2021 08:07:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 519B1610A2; Wed, 5 May 2021 12:06:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620216399; bh=jfsNba7U9iA8JZj5ycsqVMIeZBeB2IQaEFt7ctlUEek=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fkBT7OhZ3iCUiG9jJQYEiknRiHXmqOuIshnCHLBV8cprMe1SrXE6ruy4hlvWz7IfU IMqO5MnJeK921l9ci8mnmSkxeTmn4iwX7bgOtIBuoXJb7XihzAV7p+gMYfeeWW+Ixq ZLG1A/8nN+02zkH1kWhSDBlJ9AN0G7kCxq2487xc= 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 02/29] netfilter: conntrack: Make global sysctls readonly in non-init netns Date: Wed, 5 May 2021 14:05:05 +0200 Message-Id: <20210505112326.279633427@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210505112326.195493232@linuxfoundation.org> References: <20210505112326.195493232@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 2671fa4dc0109d3fb581bc3078fdf17b5d9080f6 upstream. These sysctls point to global variables: - NF_SYSCTL_CT_MAX (&nf_conntrack_max) - NF_SYSCTL_CT_EXPECT_MAX (&nf_ct_expect_max) - NF_SYSCTL_CT_BUCKETS (&nf_conntrack_htable_size_user) Because their data pointers are not updated to point to per-netns structures, they must be marked read-only in a non-init_net ns. Otherwise, changes in any net namespace are reflected in (leaked into) all other net namespaces. This problem has existed since the introduction of net namespaces. The current logic marks them read-only only if the net namespace is owned by an unprivileged user (other than init_user_ns). Commit d0febd81ae77 ("netfilter: conntrack: re-visit sysctls in unprivileged namespaces") "exposes all sysctls even if the namespace is unpriviliged." Since we need to mark them readonly in any case, we can forego the unprivileged user check altogether. Fixes: d0febd81ae77 ("netfilter: conntrack: re-visit sysctls in unprivileged namespaces") Signed-off-by: Jonathon Reinhart Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/netfilter/nf_conntrack_standalone.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) --- a/net/netfilter/nf_conntrack_standalone.c +++ b/net/netfilter/nf_conntrack_standalone.c @@ -1060,16 +1060,10 @@ static int nf_conntrack_standalone_init_ nf_conntrack_standalone_init_dccp_sysctl(net, table); nf_conntrack_standalone_init_gre_sysctl(net, table); - /* Don't allow unprivileged users to alter certain sysctls */ - if (net->user_ns != &init_user_ns) { + /* Don't allow non-init_net ns to alter global sysctls */ + if (!net_eq(&init_net, net)) { table[NF_SYSCTL_CT_MAX].mode = 0444; table[NF_SYSCTL_CT_EXPECT_MAX].mode = 0444; - table[NF_SYSCTL_CT_HELPER].mode = 0444; -#ifdef CONFIG_NF_CONNTRACK_EVENTS - table[NF_SYSCTL_CT_EVENTS].mode = 0444; -#endif - table[NF_SYSCTL_CT_BUCKETS].mode = 0444; - } else if (!net_eq(&init_net, net)) { table[NF_SYSCTL_CT_BUCKETS].mode = 0444; }