Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp461813pxj; Tue, 18 May 2021 07:16:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxwskZeAnlWZa6sqhszGCvAo5HMoq1mV/9SnIi5f+qYKtDZtvJrTNK+3It1r0mHe1mACDZO X-Received: by 2002:a17:906:11d3:: with SMTP id o19mr6267615eja.387.1621347402285; Tue, 18 May 2021 07:16:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621347402; cv=none; d=google.com; s=arc-20160816; b=DPfWoKW/FUXbnuYKVQAnI64wSCfocnLnOhSvnldsli4drDWYCwy5RcS7UXj9UslgzL HHureJN+pMOPPN/eBcRuCPfDu4LWj+5oDoCCM8uwVitIAlPMVK+KVl/MtFchoreOES+n TpsbfNr1bizc48CI7Qi/83aBRb8NtWPppZ3JM+iTGraTJc4enkfB7YAWS3vmQ71hQO/z CICbxGKGDxlObPQlJIWTPAX+bgZ2KQmJ7/PDyaPlGIGCUaf/vI2b/r69V5P34GsvQcq9 7gnuRYYXpLYIcgBVFOySeduH86lrMNLh94s+NgfRLVBqWhjmhN/o9ljNZGaKICyHAsl9 aMNg== 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=Gnx9Evr+KFNF77y/XM3/k2j2Fv8XL8cUP7xur26Ge9o=; b=TkSOPl1vrkPOgYilxa/ME7TDvOkx2jFFLL5dstvHKF7AsbzuFvBoQLFY2sSMtdwtrO zrZWPf1DMDfR5sofXMGVipND4zl/teMrgYOX04v6gjSQN1HukuIa+Jnx7HT68sm7BFl2 SNQQECu8DPIrVHkp4LUpKYHyNbcwpD83DGD81N4MAVHauz+YMoe//O5GDbOVJcsq8AYe 0U2QzFYll5sODeWWZwwDF/FyDD12f1ev2AYDapYiket8cqpS/E+NYCshN1AdGCjnsZ9a SJf0whSoMFPPkNO3ijTg2wCDV1ebhnvW3j8Uxl5qVt6eHGE6+hQiiklUan6W5ffFwfJv Lz8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CjO8HHTr; 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 h6si18404681ejq.486.2021.05.18.07.16.19; Tue, 18 May 2021 07:16:42 -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=CjO8HHTr; 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 S1344271AbhEQPoL (ORCPT + 99 others); Mon, 17 May 2021 11:44:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:55470 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244838AbhEQP2k (ORCPT ); Mon, 17 May 2021 11:28:40 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B804861CB8; Mon, 17 May 2021 14:37:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621262243; bh=G6hP73oeazIRH5gidff3/V9DUdiTvbXmIuGk0bUDG4k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CjO8HHTrs2NqZi3Ds10fMTMDsbscZkviJA0kU5275wiFD/DKXN4Hsybit0diyENaT Xg9mZhSqshoEo66xzrZNn2Mta1So6WQqbE+JkBeLrI0KjU4eldMgvFLUQOO2c8h0eP Ttyh/UlnMs1X2dJPM3eqmE9CWChbORNbMfoxNpf4= 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.4 138/141] netfilter: conntrack: Make global sysctls readonly in non-init netns Date: Mon, 17 May 2021 16:03:10 +0200 Message-Id: <20210517140247.475806146@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140242.729269392@linuxfoundation.org> References: <20210517140242.729269392@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 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/net/netfilter/nf_conntrack_standalone.c +++ b/net/netfilter/nf_conntrack_standalone.c @@ -1071,8 +1071,11 @@ static int nf_conntrack_standalone_init_ #endif } - if (!net_eq(&init_net, net)) + 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_BUCKETS].mode = 0444; + } net->ct.sysctl_header = register_net_sysctl(net, "net/netfilter", table); if (!net->ct.sysctl_header)