x86 bpf_jit: 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().

Signed-off-by: Feiran Zhuang  <zhuangfeiran@ict.ac.cn>
Acked-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
zhuangfeiran@ict.ac.cn 2012-03-28 23:27:00 +00:00 committed by David S. Miller
parent 7d26bb103c
commit 1d24fb3684

View File

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