Linux HAM/Amateur Radio development
 help / color / mirror / Atom feed
From: Julian Anastasov <ja@ssi.bg>
To: Joel Granados <joel.granados@gmail.com>
Cc: mcgrof@kernel.org, Catalin Marinas <catalin.marinas@arm.com>,
	Iurii Zaikin <yzaikin@google.com>,
	Jozsef Kadlecsik <kadlec@netfilter.org>,
	Sven Schnelle <svens@linux.ibm.com>,
	Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>,
	Steffen Klassert <steffen.klassert@secunet.com>,
	Kees Cook <keescook@chromium.org>,
	"D. Wythe" <alibuda@linux.alibaba.com>,
	mptcp@lists.linux.dev, Jakub Kicinski <kuba@kernel.org>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Paolo Abeni <pabeni@redhat.com>,
	coreteam@netfilter.org, Jan Karcher <jaka@linux.ibm.com>,
	Alexander Aring <alex.aring@gmail.com>,
	Will Deacon <will@kernel.org>,
	Stefan Schmidt <stefan@datenfreihafen.org>,
	Matthieu Baerts <matthieu.baerts@tessares.net>,
	bridge@lists.linux-foundation.org, linux-arm-kernel@lists.infr
Subject: Re: [PATCH v2 10/14] netfilter: Update to register_net_sysctl_sz
Date: Tue, 1 Aug 2023 09:11:26 +0300 (EEST)	[thread overview]
Message-ID: <b8564ac4-ab65-6212-2241-0843413e05de@ssi.bg> (raw)
In-Reply-To: <20230731071728.3493794-11-j.granados@samsung.com>


	Hello,

On Mon, 31 Jul 2023, Joel Granados wrote:

> Move from register_net_sysctl to register_net_sysctl_sz for all the
> netfilter related files. Do this while making sure to mirror the NULL
> assignments with a table_size of zero for the unprivileged users.
> 
> We need to move to the new function in preparation for when we change
> SIZE_MAX to ARRAY_SIZE() in the register_net_sysctl macro. Failing to do
> so would erroneously allow ARRAY_SIZE() to be called on a pointer. We
> hold off the SIZE_MAX to ARRAY_SIZE change until we have migrated all
> the relevant net sysctl registering functions to register_net_sysctl_sz
> in subsequent commits.
> 
> Signed-off-by: Joel Granados <j.granados@samsung.com>

	The IPVS part in net/netfilter/ipvs/ looks good to me, thanks!

Acked-by: Julian Anastasov <ja@ssi.bg>

> ---
>  net/bridge/br_netfilter_hooks.c         |  3 ++-
>  net/ipv6/netfilter/nf_conntrack_reasm.c |  3 ++-
>  net/netfilter/ipvs/ip_vs_ctl.c          |  8 ++++++--
>  net/netfilter/ipvs/ip_vs_lblc.c         | 10 +++++++---
>  net/netfilter/ipvs/ip_vs_lblcr.c        | 10 +++++++---
>  net/netfilter/nf_conntrack_standalone.c |  4 +++-
>  net/netfilter/nf_log.c                  |  7 ++++---
>  7 files changed, 31 insertions(+), 14 deletions(-)
> 

...

> --- a/net/netfilter/ipvs/ip_vs_ctl.c
> +++ b/net/netfilter/ipvs/ip_vs_ctl.c
> @@ -4266,6 +4266,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct netns_ipvs *ipvs)
>  	struct net *net = ipvs->net;
>  	struct ctl_table *tbl;
>  	int idx, ret;
> +	size_t ctl_table_size = ARRAY_SIZE(vs_vars);
>  
>  	atomic_set(&ipvs->dropentry, 0);
>  	spin_lock_init(&ipvs->dropentry_lock);
> @@ -4282,8 +4283,10 @@ static int __net_init ip_vs_control_net_init_sysctl(struct netns_ipvs *ipvs)
>  			return -ENOMEM;
>  
>  		/* Don't export sysctls to unprivileged users */
> -		if (net->user_ns != &init_user_ns)
> +		if (net->user_ns != &init_user_ns) {
>  			tbl[0].procname = NULL;
> +			ctl_table_size = 0;
> +		}
>  	} else
>  		tbl = vs_vars;
>  	/* Initialize sysctl defaults */
> @@ -4353,7 +4356,8 @@ static int __net_init ip_vs_control_net_init_sysctl(struct netns_ipvs *ipvs)
>  #endif
>  
>  	ret = -ENOMEM;
> -	ipvs->sysctl_hdr = register_net_sysctl(net, "net/ipv4/vs", tbl);
> +	ipvs->sysctl_hdr = register_net_sysctl_sz(net, "net/ipv4/vs", tbl,
> +						  ctl_table_size);
>  	if (!ipvs->sysctl_hdr)
>  		goto err;
>  	ipvs->sysctl_tbl = tbl;
> diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
> index 1b87214d385e..cf78ba4ce5ff 100644
> --- a/net/netfilter/ipvs/ip_vs_lblc.c
> +++ b/net/netfilter/ipvs/ip_vs_lblc.c
> @@ -550,6 +550,7 @@ static struct ip_vs_scheduler ip_vs_lblc_scheduler = {
>  static int __net_init __ip_vs_lblc_init(struct net *net)
>  {
>  	struct netns_ipvs *ipvs = net_ipvs(net);
> +	size_t vars_table_size = ARRAY_SIZE(vs_vars_table);
>  
>  	if (!ipvs)
>  		return -ENOENT;
> @@ -562,16 +563,19 @@ static int __net_init __ip_vs_lblc_init(struct net *net)
>  			return -ENOMEM;
>  
>  		/* Don't export sysctls to unprivileged users */
> -		if (net->user_ns != &init_user_ns)
> +		if (net->user_ns != &init_user_ns) {
>  			ipvs->lblc_ctl_table[0].procname = NULL;
> +			vars_table_size = 0;
> +		}
>  
>  	} else
>  		ipvs->lblc_ctl_table = vs_vars_table;
>  	ipvs->sysctl_lblc_expiration = DEFAULT_EXPIRATION;
>  	ipvs->lblc_ctl_table[0].data = &ipvs->sysctl_lblc_expiration;
>  
> -	ipvs->lblc_ctl_header =
> -		register_net_sysctl(net, "net/ipv4/vs", ipvs->lblc_ctl_table);
> +	ipvs->lblc_ctl_header = register_net_sysctl_sz(net, "net/ipv4/vs",
> +						       ipvs->lblc_ctl_table,
> +						       vars_table_size);
>  	if (!ipvs->lblc_ctl_header) {
>  		if (!net_eq(net, &init_net))
>  			kfree(ipvs->lblc_ctl_table);
> diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
> index ad8f5fea6d3a..9eddf118b40e 100644
> --- a/net/netfilter/ipvs/ip_vs_lblcr.c
> +++ b/net/netfilter/ipvs/ip_vs_lblcr.c
> @@ -736,6 +736,7 @@ static struct ip_vs_scheduler ip_vs_lblcr_scheduler =
>  static int __net_init __ip_vs_lblcr_init(struct net *net)
>  {
>  	struct netns_ipvs *ipvs = net_ipvs(net);
> +	size_t vars_table_size = ARRAY_SIZE(vs_vars_table);
>  
>  	if (!ipvs)
>  		return -ENOENT;
> @@ -748,15 +749,18 @@ static int __net_init __ip_vs_lblcr_init(struct net *net)
>  			return -ENOMEM;
>  
>  		/* Don't export sysctls to unprivileged users */
> -		if (net->user_ns != &init_user_ns)
> +		if (net->user_ns != &init_user_ns) {
>  			ipvs->lblcr_ctl_table[0].procname = NULL;
> +			vars_table_size = 0;
> +		}
>  	} else
>  		ipvs->lblcr_ctl_table = vs_vars_table;
>  	ipvs->sysctl_lblcr_expiration = DEFAULT_EXPIRATION;
>  	ipvs->lblcr_ctl_table[0].data = &ipvs->sysctl_lblcr_expiration;
>  
> -	ipvs->lblcr_ctl_header =
> -		register_net_sysctl(net, "net/ipv4/vs", ipvs->lblcr_ctl_table);
> +	ipvs->lblcr_ctl_header = register_net_sysctl_sz(net, "net/ipv4/vs",
> +							ipvs->lblcr_ctl_table,
> +							vars_table_size);
>  	if (!ipvs->lblcr_ctl_header) {
>  		if (!net_eq(net, &init_net))
>  			kfree(ipvs->lblcr_ctl_table);

Regards

--
Julian Anastasov <ja@ssi.bg>


  reply	other threads:[~2023-08-01  6:11 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-31  7:17 [PATCH v2 00/14] sysctl: Add a size argument to register functions in sysctl Joel Granados
2023-07-31  7:17 ` [PATCH v2 01/14] sysctl: Prefer ctl_table_header in proc_sysctl Joel Granados
2023-07-31  7:17 ` [PATCH v2 02/14] sysctl: Use ctl_table_header in list_for_each_table_entry Joel Granados
2023-07-31  7:17 ` [PATCH v2 03/14] sysctl: Add ctl_table_size to ctl_table_header Joel Granados
     [not found]   ` <20230731071728.3493794-4-j.granados-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2023-07-31 18:30     ` Simon Horman
2023-07-31 19:07       ` Simon Horman
2023-08-01 10:03         ` Joel Granados
2023-07-31  7:17 ` [PATCH v2 04/14] sysctl: Add size argument to init_header Joel Granados
2023-07-31  7:17 ` [PATCH v2 05/14] sysctl: Add a size arg to __register_sysctl_table Joel Granados
2023-07-31  7:17 ` [PATCH v2 06/14] sysctl: Add size to register_sysctl Joel Granados
2023-07-31  7:17 ` [PATCH v2 07/14] sysctl: Add size arg to __register_sysctl_init Joel Granados
2023-07-31  7:17 ` [PATCH v2 08/14] sysctl: Add size to register_net_sysctl function Joel Granados
2023-07-31  7:17 ` [PATCH v2 09/14] ax.25: Update to register_net_sysctl_sz Joel Granados
     [not found] ` <20230731071728.3493794-1-j.granados-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2023-07-31  7:17   ` [PATCH v2 10/14] netfilter: " Joel Granados
2023-08-01  6:11     ` Julian Anastasov [this message]
2023-07-31  7:17   ` [PATCH v2 11/14] networking: " Joel Granados
2023-08-08 11:20     ` Przemek Kitszel
2023-08-08 14:24       ` Joel Granados
2023-08-08 15:23       ` Joel Granados
2023-07-31  7:17 ` [PATCH v2 12/14] vrf: " Joel Granados
2023-07-31  7:17 ` [PATCH v2 13/14] sysctl: SIZE_MAX->ARRAY_SIZE in register_net_sysctl Joel Granados
2023-07-31  7:17 ` [PATCH v2 14/14] sysctl: Use ctl_table_size as stopping criteria for list macro Joel Granados
2023-07-31 20:50 ` [PATCH v2 00/14] sysctl: Add a size argument to register functions in sysctl Luis Chamberlain
2023-08-01 10:01   ` Joel Granados
2023-07-31 21:36 ` Luis Chamberlain
2023-08-01  9:35   ` Joel Granados
2023-08-07 21:44   ` Luis Chamberlain
2023-08-07 23:00     ` Chris Maness
2023-08-07 23:43       ` Luis Chamberlain
2023-08-08  2:50         ` Chris Maness
2023-08-08  3:00           ` Luis Chamberlain
2023-08-08  3:07             ` Chris Maness
2023-08-08 13:59               ` Joel Granados
2023-08-08 13:58           ` Joel Granados
2023-08-08  2:09     ` Jakub Kicinski
2023-08-08  2:34       ` Luis Chamberlain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b8564ac4-ab65-6212-2241-0843413e05de@ssi.bg \
    --to=ja@ssi.bg \
    --cc=alex.aring@gmail.com \
    --cc=alibuda@linux.alibaba.com \
    --cc=bridge@lists.linux-foundation.org \
    --cc=catalin.marinas@arm.com \
    --cc=coreteam@netfilter.org \
    --cc=gor@linux.ibm.com \
    --cc=jaka@linux.ibm.com \
    --cc=joel.granados@gmail.com \
    --cc=kadlec@netfilter.org \
    --cc=keescook@chromium.org \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infr \
    --cc=marcelo.leitner@gmail.com \
    --cc=matthieu.baerts@tessares.net \
    --cc=mcgrof@kernel.org \
    --cc=mptcp@lists.linux.dev \
    --cc=pabeni@redhat.com \
    --cc=stefan@datenfreihafen.org \
    --cc=steffen.klassert@secunet.com \
    --cc=svens@linux.ibm.com \
    --cc=will@kernel.org \
    --cc=yzaikin@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox