Skip to contentSkip to conversation

netfilter: avoid array overflow in nf_register_hook

PATCH In review Dong Fang 2 participants 2 messages Aug 23, 2013 – Aug 24, 2013

Subsystems (3)
lore
Share & tools
lore

Dong Fang

author
#0 lore raw

PATCH 1/1 netfilter: avoid array overflow in nf_register_hook

This patch fix the array overflow in nf_register_hook function

---
 net/netfilter/core.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
net/netfilter/core.c +4 -1
index 2217363..819eee1 100644
@@ -68,8 +68,11 @@ static DEFINE_MUTEX(nf_hook_mutex);
 int nf_register_hook(struct nf_hook_ops *reg)
 {
 	struct nf_hook_ops *elem;
-	int err;
+	int err = -EINVAL;
 
+	if (reg->pf >= NFPROTO_NUMPROTO || reg->hooknum >= NF_MAX_HOOKS)
+		return err;
+
 	err = mutex_lock_interruptible(&nf_hook_mutex);
 	if (err < 0)
 		return err;
Signature · 1 line
1.7.1
#1 lore raw
Quoted 12 lines · Dong Fang

This patch fix the array overflow in nf_register_hook function

---
 net/netfilter/core.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
net/netfilter/core.c +0 -0
index 2217363..819eee1 100644

net/netfilter/core.c static DEFINE_MUTEX(nf_hook_mutex); · line 75

Quoted 9 lines
net/netfilter/core.c +4 -1
@@ -68,8 +68,11 @@ static DEFINE_MUTEX(nf_hook_mutex);
 int nf_register_hook(struct nf_hook_ops *reg)
 {
 	struct nf_hook_ops *elem;
-	int err;
+	int err = -EINVAL;
 
+	if (reg->pf >= NFPROTO_NUMPROTO || reg->hooknum >= NF_MAX_HOOKS)
+		return err;
+

Thats a bug in the caller.

We want a hard crash so that the poor netfilter guy who made this error can fix the bug before sending us a buggy patch.