netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH nf-next] netfilter: log: Check param to avoid overflow in nf_log_set
@ 2016-08-28 14:30 fgao
  2016-08-28 22:36 ` Feng Gao
  2016-08-29  9:55 ` Pablo Neira Ayuso
  0 siblings, 2 replies; 3+ messages in thread
From: fgao @ 2016-08-28 14:30 UTC (permalink / raw)
  To: pablo, kaber, davem, netfilter-devel, coreteam, netdev
  Cc: gfree.wind, Gao Feng

From: Gao Feng <fgao@ikuai8.com>

The nf_log_set is an interface function, so it should do the strict sanity
check of parameters. Add  one sanity check for pf, it could not exceed
NFPROTO_NUMPROTO, and print error log when pf is invalid.

Signed-off-by: Gao Feng <fgao@ikuai8.com>
---
 net/netfilter/nf_log.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
index aa5847a..02ce0b9 100644
--- a/net/netfilter/nf_log.c
+++ b/net/netfilter/nf_log.c
@@ -43,8 +43,10 @@ void nf_log_set(struct net *net, u_int8_t pf, const struct nf_logger *logger)
 {
 	const struct nf_logger *log;
 
-	if (pf == NFPROTO_UNSPEC)
+	if (pf == NFPROTO_UNSPEC || pf >= NFPROTO_NUMPROTO) {
+		pr_err("Wrong pf(%d) for nf log", pf);
 		return;
+	}
 
 	mutex_lock(&nf_log_mutex);
 	log = nft_log_dereference(net->nf.nf_loggers[pf]);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH nf-next] netfilter: log: Check param to avoid overflow in nf_log_set
  2016-08-28 14:30 [PATCH nf-next] netfilter: log: Check param to avoid overflow in nf_log_set fgao
@ 2016-08-28 22:36 ` Feng Gao
  2016-08-29  9:55 ` Pablo Neira Ayuso
  1 sibling, 0 replies; 3+ messages in thread
From: Feng Gao @ 2016-08-28 22:36 UTC (permalink / raw)
  To: Gao Feng
  Cc: Pablo Neira Ayuso, Patrick McHardy, David S. Miller,
	Netfilter Developer Mailing List, coreteam,
	Linux Kernel Network Developers

On Sun, Aug 28, 2016 at 10:30 PM,  <fgao@ikuai8.com> wrote:
> From: Gao Feng <fgao@ikuai8.com>
>
> The nf_log_set is an interface function, so it should do the strict sanity
> check of parameters. Add  one sanity check for pf, it could not exceed
> NFPROTO_NUMPROTO, and print error log when pf is invalid.
>
> Signed-off-by: Gao Feng <fgao@ikuai8.com>
> ---
>  net/netfilter/nf_log.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
> index aa5847a..02ce0b9 100644
> --- a/net/netfilter/nf_log.c
> +++ b/net/netfilter/nf_log.c
> @@ -43,8 +43,10 @@ void nf_log_set(struct net *net, u_int8_t pf, const struct nf_logger *logger)
>  {
>         const struct nf_logger *log;
>
> -       if (pf == NFPROTO_UNSPEC)
> +       if (pf == NFPROTO_UNSPEC || pf >= NFPROTO_NUMPROTO) {
> +               pr_err("Wrong pf(%d) for nf log", pf);
>                 return;
> +       }
>
>         mutex_lock(&nf_log_mutex);
>         log = nft_log_dereference(net->nf.nf_loggers[pf]);
> --
> 1.9.1
>
>

BTW, another similar interface function "nf_log_register" checks
sanity of param "pf".
So I think nf_log_set also need to check if param "pf" exceeds the valid range.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH nf-next] netfilter: log: Check param to avoid overflow in nf_log_set
  2016-08-28 14:30 [PATCH nf-next] netfilter: log: Check param to avoid overflow in nf_log_set fgao
  2016-08-28 22:36 ` Feng Gao
@ 2016-08-29  9:55 ` Pablo Neira Ayuso
  1 sibling, 0 replies; 3+ messages in thread
From: Pablo Neira Ayuso @ 2016-08-29  9:55 UTC (permalink / raw)
  To: fgao; +Cc: kaber, davem, netfilter-devel, coreteam, netdev, gfree.wind

On Sun, Aug 28, 2016 at 10:30:18PM +0800, fgao@ikuai8.com wrote:
> From: Gao Feng <fgao@ikuai8.com>
> 
> The nf_log_set is an interface function, so it should do the strict sanity
> check of parameters. Add  one sanity check for pf, it could not exceed
> NFPROTO_NUMPROTO, and print error log when pf is invalid.
> 
> Signed-off-by: Gao Feng <fgao@ikuai8.com>
> ---
>  net/netfilter/nf_log.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
> index aa5847a..02ce0b9 100644
> --- a/net/netfilter/nf_log.c
> +++ b/net/netfilter/nf_log.c
> @@ -43,8 +43,10 @@ void nf_log_set(struct net *net, u_int8_t pf, const struct nf_logger *logger)
>  {
>  	const struct nf_logger *log;
>  
> -	if (pf == NFPROTO_UNSPEC)
> +	if (pf == NFPROTO_UNSPEC || pf >= NFPROTO_NUMPROTO) {
> +		pr_err("Wrong pf(%d) for nf log", pf);
>  		return;

I'd suggest you change this function nf_log_set() to:

        int nf_log_set(struct net *net, ...)

And update the callsites.

Then, you can simply return -EOPNOTSUPP instead and remove that
pr_err() message. This message is very unlikely to be displayed.

Thanks!

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-08-29  9:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-28 14:30 [PATCH nf-next] netfilter: log: Check param to avoid overflow in nf_log_set fgao
2016-08-28 22:36 ` Feng Gao
2016-08-29  9:55 ` Pablo Neira Ayuso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).