[PATCH 7/7] v2: Check "bpf_jit_binary_lock_ro()" return value

Shahab Vahedi list+bpf at vahedi.org
Tue Apr 30 08:09:37 PDT 2024


From: Shahab Vahedi <shahab at synopsys.com>

...after the rebase.
---
 arch/arc/net/bpf_jit_core.c | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/arch/arc/net/bpf_jit_core.c b/arch/arc/net/bpf_jit_core.c
index 00c99b339b4a..6f6b4ffccf2c 100644
--- a/arch/arc/net/bpf_jit_core.c
+++ b/arch/arc/net/bpf_jit_core.c
@@ -1218,15 +1218,10 @@ static int jit_compile(struct jit_context *ctx)
  *
  * prog->jited=1, prog->jited_len=..., prog->bpf_func=...
  */
-static void jit_finalize(struct jit_context *ctx)
+static int jit_finalize(struct jit_context *ctx)
 {
 	struct bpf_prog *prog = ctx->prog;
 
-	ctx->success = true;
-	prog->bpf_func = (void *)ctx->jit.buf;
-	prog->jited_len = ctx->jit.len;
-	prog->jited = 1;
-
 	/* We're going to need this information for the "do_extra_pass()". */
 	if (ctx->need_extra_pass) {
 		ctx->jit_data->bpf_header = ctx->bpf_header;
@@ -1237,7 +1232,10 @@ static void jit_finalize(struct jit_context *ctx)
 		 * If things seem finalised, then mark the JITed memory
 		 * as R-X and flush it.
 		 */
-		bpf_jit_binary_lock_ro(ctx->bpf_header);
+		if (bpf_jit_binary_lock_ro(ctx->bpf_header)) {
+			pr_err("bpf-jit: Could not lock the JIT memory.\n");
+			return -EFAULT;
+		}
 		flush_icache_range((unsigned long)ctx->bpf_header,
 				   (unsigned long)
 				   BUF(ctx->jit.buf, ctx->jit.len));
@@ -1245,8 +1243,15 @@ static void jit_finalize(struct jit_context *ctx)
 		bpf_prog_fill_jited_linfo(prog, ctx->bpf2insn);
 	}
 
+	ctx->success = true;
+	prog->bpf_func = (void *)ctx->jit.buf;
+	prog->jited_len = ctx->jit.len;
+	prog->jited = 1;
+
 	jit_ctx_cleanup(ctx);
 	jit_dump(ctx);
+
+	return 0;
 }
 
 /*
@@ -1354,7 +1359,10 @@ static struct bpf_prog *do_normal_pass(struct bpf_prog *prog)
 		return prog;
 	}
 
-	jit_finalize(&ctx);
+	if (jit_finalize(&ctx)) {
+		jit_ctx_cleanup(&ctx);
+		return prog;
+	}
 
 	return ctx.prog;
 }
@@ -1389,7 +1397,10 @@ static struct bpf_prog *do_extra_pass(struct bpf_prog *prog)
 		return prog;
 	}
 
-	jit_finalize(&ctx);
+	if (jit_finalize(&ctx)) {
+		jit_ctx_cleanup(&ctx);
+		return prog;
+	}
 
 	return ctx.prog;
 }
-- 
2.35.8




More information about the linux-snps-arc mailing list