[PATCH nf-next] netfilter: log: Check param to avoid overflow in nf_log_set

Subsystems: netfilter, networking [general], the rest

STALE3641d

3 messages, 3 authors, 2016-08-29 · open the first message on its own page

[PATCH nf-next] netfilter: log: Check param to avoid overflow in nf_log_set

From: <hidden>
Date: 2016-08-28 14:32:28

From: Gao Feng <redacted>

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 <redacted>
---
 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

Re: [PATCH nf-next] netfilter: log: Check param to avoid overflow in nf_log_set

From: Feng Gao <hidden>
Date: 2016-08-28 22:36:14

On Sun, Aug 28, 2016 at 10:30 PM,  [off-list ref] wrote:
quoted hunk
From: Gao Feng <redacted>

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 <redacted>
---
 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.

Re: [PATCH nf-next] netfilter: log: Check param to avoid overflow in nf_log_set

From: Pablo Neira Ayuso <pablo@netfilter.org>
Date: 2016-08-29 09:55:25

On Sun, Aug 28, 2016 at 10:30:18PM +0800, fgao@ikuai8.com wrote:
quoted hunk
From: Gao Feng <redacted>

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 <redacted>
---
 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!
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help