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

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

Hello.

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 74

Quoted 8 lines
net/netfilter/core.c +3 -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;

Why not just return -EINVAL and avoid unneeded 'err' initialization?

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

Quoted 4 lines
net/netfilter/core.c +1 -0
+
  	err = mutex_lock_interruptible(&nf_hook_mutex);
  	if (err < 0)
  		return err;

WBR, Sergei