Skip to contentSkip to conversation

ebtables: arpreply: Add the standard target sanity check

PATCH Superseded [email protected] 2 participants 4 messages May 12, 2017 – May 16, 2017

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ebtables: arpreply: Add the standard target sanity check

From: Gao Feng <[email protected]>

The info->target is from userspace and it would be used directly. So we need to add the sanity check to make sure it is a valid standard target, although the ebtables tool has already checked it. Kernel need to check anything from userspace.

If the target was set as an evil value, it would break the ebtables and cause a panic. Because the non-standard target is treated as one offset.

---
 net/bridge/netfilter/ebt_arpreply.c | 3 +++
 1 file changed, 3 insertions(+)
net/bridge/netfilter/ebt_arpreply.c +3 -0
index 5929309..c4886d9 100644
@@ -68,6 +68,9 @@ static int ebt_arpreply_tg_check(const struct xt_tgchk_param *par)
 	if (e->ethproto != htons(ETH_P_ARP) ||
 	    e->invflags & EBT_IPROTO)
 		return -EINVAL;
+	if (INVALID_TARGET)
+		return -EINVAL;
+
 	return 0;
 }
 
Signature · 1 line
1.9.1
#1 lore raw
Quoted 21 lines · On Fri, May 12, 2017 at 05:44:10PM +0800, [email protected] wrote:

From: Gao Feng <[email protected]>

The info->target is from userspace and it would be used directly. So we need to add the sanity check to make sure it is a valid standard target, although the ebtables tool has already checked it. Kernel need to check anything from userspace.

If the target was set as an evil value, it would break the ebtables and cause a panic. Because the non-standard target is treated as one offset.

---
 net/bridge/netfilter/ebt_arpreply.c | 3 +++
 1 file changed, 3 insertions(+)
net/bridge/netfilter/ebt_arpreply.c +0 -0
index 5929309..c4886d9 100644

net/bridge/netfilter/ebt_arpreply.c static int ebt_arpreply_tg_check(const struct xt_tgchk_param *par) · line 71

Quoted 4 lines
net/bridge/netfilter/ebt_arpreply.c +1 -0
@@ -68,6 +68,9 @@ static int ebt_arpreply_tg_check(const struct xt_tgchk_param *par)
 	if (e->ethproto != htons(ETH_P_ARP) ||
 	    e->invflags & EBT_IPROTO)
 		return -EINVAL;
+	if (INVALID_TARGET)

Please, add:

static inline bool ebt_invalid_target(int target)

{
        return (target < -NUM_STANDARD_TARGETS || target >= 0);
}

and use it in this fix.

So we can get rid of this obscure INVALID_TARGET macro.

Thanks.

#2 lore raw
Quoted 29 lines · Pablo Neira Ayuso
Quoted 21 lines · On Fri, May 12, 2017 at 05:44:10PM +0800, [email protected] wrote:

From: Gao Feng <[email protected]>

The info->target is from userspace and it would be used directly. So we need to add the sanity check to make sure it is a valid standard target, although the ebtables tool has already checked it. Kernel need to check anything from userspace.

If the target was set as an evil value, it would break the ebtables and cause a panic. Because the non-standard target is treated as one offset.

---
 net/bridge/netfilter/ebt_arpreply.c | 3 +++
 1 file changed, 3 insertions(+)
net/bridge/netfilter/ebt_arpreply.c +0 -0
index 5929309..c4886d9 100644

net/bridge/netfilter/ebt_arpreply.c static int ebt_arpreply_tg_check(const struct xt_tgchk_param *par) · line 71

Quoted 4 lines
net/bridge/netfilter/ebt_arpreply.c +1 -0
@@ -68,6 +68,9 @@ static int ebt_arpreply_tg_check(const struct xt_tgchk_param *par)
 	if (e->ethproto != htons(ETH_P_ARP) ||
 	    e->invflags & EBT_IPROTO)
 		return -EINVAL;
+	if (INVALID_TARGET)

Please, add:

Quoted 8 lines

static inline bool ebt_invalid_target(int target)

{
        return (target < -NUM_STANDARD_TARGETS || target >= 0);
}

and use it in this fix.

So we can get rid of this obscure INVALID_TARGET macro.

Once this propagates to nf-next.git, you can send a follow up patch to use this new function from more spots, so we can kill INVALID_TARGET for good.

author
#3 lore raw
Quoted 35 lines · Pablo Neira Ayuso
Quoted 34 lines · Pablo Neira Ayuso
Quoted 21 lines · On Fri, May 12, 2017 at 05:44:10PM +0800, [email protected] wrote:

From: Gao Feng <[email protected]>

The info->target is from userspace and it would be used directly. So we need to add the sanity check to make sure it is a valid standard target, although the ebtables tool has already checked it. Kernel need to check anything from userspace.

If the target was set as an evil value, it would break the ebtables and cause a panic. Because the non-standard target is treated as one offset.

---
 net/bridge/netfilter/ebt_arpreply.c | 3 +++
 1 file changed, 3 insertions(+)
net/bridge/netfilter/ebt_arpreply.c +0 -0
index 5929309..c4886d9 100644

net/bridge/netfilter/ebt_arpreply.c static int ebt_arpreply_tg_check(const struct xt_tgchk_param *par) · line 71

Quoted 4 lines
net/bridge/netfilter/ebt_arpreply.c +1 -0
@@ -68,6 +68,9 @@ static int ebt_arpreply_tg_check(const struct xt_tgchk_param *par)
 	if (e->ethproto != htons(ETH_P_ARP) ||
 	    e->invflags & EBT_IPROTO)
 		return -EINVAL;
+	if (INVALID_TARGET)

Please, add:

static inline bool ebt_invalid_target(int target)

{
        return (target < -NUM_STANDARD_TARGETS || target >= 0);
}
Quoted 7 lines
Quoted 3 lines

and use it in this fix.

So we can get rid of this obscure INVALID_TARGET macro.

Once this propagates to nf-next.git, you can send a follow up patch to use this new function from more spots, so we can kill INVALID_TARGET for good.

OK, no problem.

Regards
Feng