Skip to contentSkip to conversation

powerpc/bpf: Fix BPF_MOD when imm == 1

PATCH In review Thadeu Lima de Souza Cascardo 2 participants 3 messages Oct 27, 2021 Stable branch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc/bpf: Fix BPF_MOD when imm == 1

From: "Naveen N. Rao" <[email protected]>

commit 8bbc9d822421d9ac8ff9ed26a3713c9afc69d6c8 upstream.

Only ignore the operation if dividing by 1.

---
 arch/powerpc/net/bpf_jit_comp64.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
arch/powerpc/net/bpf_jit_comp64.c +8 -2
index 0752967f351b..a2750d6ffd0f 100644
@@ -415,8 +415,14 @@ static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image,
 		case BPF_ALU64 | BPF_DIV | BPF_K: /* dst /= imm */
 			if (imm == 0)
 				return -EINVAL;
-			else if (imm == 1)
-				goto bpf_alu32_trunc;
+			if (imm == 1) {
+				if (BPF_OP(code) == BPF_DIV) {
+					goto bpf_alu32_trunc;
+				} else {
+					EMIT(PPC_RAW_LI(dst_reg, 0));
+					break;
+				}
+			}
 
 			PPC_LI32(b2p[TMP_REG_1], imm);
 			switch (BPF_CLASS(code)) {
Signature · 1 line
2.32.0
#1 lore raw

PATCH 1/1 powerpc/bpf: Fix BPF_MOD when imm == 1

From: "Naveen N. Rao" <[email protected]>

commit 8bbc9d822421d9ac8ff9ed26a3713c9afc69d6c8 upstream.

Only ignore the operation if dividing by 1.

[cascardo: use PPC_LI instead of EMIT(PPC_RAW_LI)]
---
 arch/powerpc/net/bpf_jit_comp64.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
arch/powerpc/net/bpf_jit_comp64.c +8 -2
index 20bfd753bcba..81e6279c9874 100644
@@ -408,8 +408,14 @@ static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image,
 		case BPF_ALU64 | BPF_DIV | BPF_K: /* dst /= imm */
 			if (imm == 0)
 				return -EINVAL;
-			else if (imm == 1)
-				goto bpf_alu32_trunc;
+			if (imm == 1) {
+				if (BPF_OP(code) == BPF_DIV) {
+					goto bpf_alu32_trunc;
+				} else {
+					PPC_LI(dst_reg, 0);
+					break;
+				}
+			}
 
 			PPC_LI32(b2p[TMP_REG_1], imm);
 			switch (BPF_CLASS(code)) {
Signature · 1 line
2.32.0
#2 lore raw
In reply to Thadeu Lima de Souza Cascardo
Quoted 15 lines · Thadeu Lima de Souza Cascardo

From: "Naveen N. Rao" <[email protected]>

commit 8bbc9d822421d9ac8ff9ed26a3713c9afc69d6c8 upstream.

Only ignore the operation if dividing by 1.

Quoted 5 lines
---
 arch/powerpc/net/bpf_jit_comp64.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

All now queued up, thanks.

greg k-h