Skip to contentSkip to conversation

netfilter: fix possible ZERO_SIZE_PTR pointer dereferencing error.

PATCH Applied Xiubo Li 2 participants 2 messages Jun 2, 2016 – Jun 23, 2016

Subsystems (3)
lore
Share & tools
lore

Xiubo Li

author
#0 lore raw

PATCH v2 1/1 netfilter: fix possible ZERO_SIZE_PTR pointer dereferencing error.

Since we cannot make sure that the 'hook_mask' will always be none zero here. If it equals to zero, the num_hooks will be zero too, and then kmalloc() will return ZERO_SIZE_PTR, which is (void *)16.

Then the following error check will fails:
ops = kmalloc(sizeof(*ops) * num_hooks, GFP_KERNEL); if (ops == NULL)

          return ERR_PTR(-ENOMEM);

So this patch will fix this with just doing the zero check before kmalloc() is called.

Maybe the case above will never happen here, but in theory.

---

Changes in V2:
- Using the nf.git tree instead.

 net/netfilter/x_tables.c | 3 +++
 1 file changed, 3 insertions(+)
net/netfilter/x_tables.c +3 -0
index 582c9cf..e117fd0 100644
@@ -1221,6 +1221,9 @@ xt_hook_ops_alloc(const struct xt_table *table, nf_hookfn *fn)
 	uint8_t hooknum;
 	struct nf_hook_ops *ops;
 
+	if (!num_hooks)
+		return ERR_PTR(-EINVAL);
+
 	ops = kmalloc(sizeof(*ops) * num_hooks, GFP_KERNEL);
 	if (ops == NULL)
 		return ERR_PTR(-ENOMEM);
Signature · 1 line
1.8.3.1
maintainer Applied
#1 lore raw
Quoted 7 lines · Xiubo Li

Since we cannot make sure that the 'hook_mask' will always be none zero here. If it equals to zero, the num_hooks will be zero too, and then kmalloc() will return ZERO_SIZE_PTR, which is (void *)16.

Then the following error check will fails:
ops = kmalloc(sizeof(*ops) * num_hooks, GFP_KERNEL); if (ops == NULL)

Quoted 6 lines
          return ERR_PTR(-ENOMEM);

So this patch will fix this with just doing the zero check before kmalloc() is called.

Maybe the case above will never happen here, but in theory.

Applied, thanks.