Skip to contentSkip to conversation

ruleparse: arp: Fix for all-zero mask on Big Endian

PATCH In review Phil Sutter 1 participant 2 messages Jan 29 – Jan 30 netfilter

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

PATCH v2 1/1 ruleparse: arp: Fix for all-zero mask on Big Endian

With 16bit mask values, the first two bytes of bitwise.mask in struct nft_xt_ctx_reg are significant. Reading the first 32bit-sized field works only on Little Endian, on Big Endian the mask appears in the upper two bytes which are discarded when assigning to a 16bit variable.

Fixes ab2d5f8c7bbee ("nft-arp: add missing mask support")

---
Changes since v1:
- Use memcpy() to avoid gcc's -Wstrict-aliasing warning

---
 iptables/nft-ruleparse-arp.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
iptables/nft-ruleparse-arp.c +8 -4
index b0671cb0dfe8f..632e7ac94727c 100644
@@ -90,7 +90,8 @@ static void nft_arp_parse_payload(struct nft_xt_ctx *ctx,
 		if (inv)
 			fw->arp.invflags |= IPT_INV_ARPHRD;
 		if (reg->bitwise.set)
-			fw->arp.arhrd_mask = reg->bitwise.mask[0];
+			memcpy(&fw->arp.arhrd_mask, reg->bitwise.mask,
+			       sizeof(fw->arp.arhrd_mask));
 		break;
 	case offsetof(struct arphdr, ar_pro):
 		get_cmp_data(e, &ar_pro, sizeof(ar_pro), &inv);
@@ -99,7 +100,8 @@ static void nft_arp_parse_payload(struct nft_xt_ctx *ctx,
 		if (inv)
 			fw->arp.invflags |= IPT_INV_PROTO;
 		if (reg->bitwise.set)
-			fw->arp.arpro_mask = reg->bitwise.mask[0];
+			memcpy(&fw->arp.arpro_mask, reg->bitwise.mask,
+			       sizeof(fw->arp.arpro_mask));
 		break;
 	case offsetof(struct arphdr, ar_op):
 		get_cmp_data(e, &ar_op, sizeof(ar_op), &inv);
@@ -108,7 +110,8 @@ static void nft_arp_parse_payload(struct nft_xt_ctx *ctx,
 		if (inv)
 			fw->arp.invflags |= IPT_INV_ARPOP;
 		if (reg->bitwise.set)
-			fw->arp.arpop_mask = reg->bitwise.mask[0];
+			memcpy(&fw->arp.arpop_mask, reg->bitwise.mask,
+			       sizeof(fw->arp.arpop_mask));
 		break;
 	case offsetof(struct arphdr, ar_hln):
 		get_cmp_data(e, &ar_hln, sizeof(ar_hln), &inv);
@@ -117,7 +120,8 @@ static void nft_arp_parse_payload(struct nft_xt_ctx *ctx,
 		if (inv)
 			fw->arp.invflags |= IPT_INV_ARPHLN;
 		if (reg->bitwise.set)
-			fw->arp.arhln_mask = reg->bitwise.mask[0];
+			memcpy(&fw->arp.arhln_mask, reg->bitwise.mask,
+			       sizeof(fw->arp.arhln_mask));
 		break;
 	case offsetof(struct arphdr, ar_pln):
 		get_cmp_data(e, &ar_pln, sizeof(ar_pln), &inv);
Signature · 1 line
2.51.0
author reviewer
#1 lore raw
Quoted 10 lines · Phil Sutter

With 16bit mask values, the first two bytes of bitwise.mask in struct nft_xt_ctx_reg are significant. Reading the first 32bit-sized field works only on Little Endian, on Big Endian the mask appears in the upper two bytes which are discarded when assigning to a 16bit variable.

Fixes ab2d5f8c7bbee ("nft-arp: add missing mask support")

---
Changes since v1:
- Use memcpy() to avoid gcc's -Wstrict-aliasing warning

Patch applied.