Skip to contentSkip to conversation

fix a bug in emitting the 16-bit immediate operand of AND

PATCH Applied [email protected] 3 participants 3 messages Mar 29, 2012

Subsystems (5)
Networking Network drivers x86 BPF +1 more subsystems
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix a bug in emitting the 16-bit immediate operand of AND

When K >= 0xFFFF0000, AND needs the two least significant bytes of K as its operand, but EMIT2() gives it the least significant byte of K and 0x2. EMIT() should be used here to replace EMIT2().

---
 arch/x86/net/bpf_jit_comp.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/net/bpf_jit_comp.c +1 -1
index 5671752..5a5b6e4 100644
@@ -289,7 +289,7 @@ void bpf_jit_compile(struct sk_filter *fp)
 					EMIT2(0x24, K & 0xFF); /* and imm8,%al */
 				} else if (K >= 0xFFFF0000) {
 					EMIT2(0x66, 0x25);	/* and imm16,%ax */
-					EMIT2(K, 2);
+					EMIT(K, 2);
 				} else {
 					EMIT1_off32(0x25, K);	/* and imm32,%eax */
 				}
Signature · 1 line
1.7.5.4
Acked-by on v1 1/1
#1 lore raw
Quoted 14 lines · Le jeudi 29 mars 2012 à 17:27 +0800, [email protected] a écrit :

When K >= 0xFFFF0000, AND needs the two least significant bytes of K as its operand, but EMIT2() gives it the least significant byte of K and 0x2. EMIT() should be used here to replace EMIT2().

---
 arch/x86/net/bpf_jit_comp.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/net/bpf_jit_comp.c +0 -0
index 5671752..5a5b6e4 100644

arch/x86/net/bpf_jit_comp.c void bpf_jit_compile(struct sk_filter *fp) · line 295

Quoted 8 lines
arch/x86/net/bpf_jit_comp.c +1 -1
@@ -289,7 +289,7 @@ void bpf_jit_compile(struct sk_filter *fp)
 					EMIT2(0x24, K & 0xFF); /* and imm8,%al */
 				} else if (K >= 0xFFFF0000) {
 					EMIT2(0x66, 0x25);	/* and imm16,%ax */
-					EMIT2(K, 2);
+					EMIT(K, 2);
 				} else {
 					EMIT1_off32(0x25, K);	/* and imm32,%eax */
 				}

Good catch, thanks !

maintainer Applied
#2 lore raw

From: Eric Dumazet <[email protected]>
Date: Thu, 29 Mar 2012 13:45:25 +0200

Quoted 26 lines · Le jeudi 29 mars 2012 à 17:27 +0800, [email protected] a écrit :
Quoted 14 lines

When K >= 0xFFFF0000, AND needs the two least significant bytes of K as its operand, but EMIT2() gives it the least significant byte of K and 0x2. EMIT() should be used here to replace EMIT2().

---
 arch/x86/net/bpf_jit_comp.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/net/bpf_jit_comp.c +0 -0
index 5671752..5a5b6e4 100644

arch/x86/net/bpf_jit_comp.c void bpf_jit_compile(struct sk_filter *fp) · line 295

Quoted 8 lines
arch/x86/net/bpf_jit_comp.c +1 -1
@@ -289,7 +289,7 @@ void bpf_jit_compile(struct sk_filter *fp)
 					EMIT2(0x24, K & 0xFF); /* and imm8,%al */
 				} else if (K >= 0xFFFF0000) {
 					EMIT2(0x66, 0x25);	/* and imm16,%ax */
-					EMIT2(K, 2);
+					EMIT(K, 2);
 				} else {
 					EMIT1_off32(0x25, K);	/* and imm32,%eax */
 				}

Good catch, thanks !

Quoted 1 line

Applied.