Thread (7 messages) 7 messages, 3 authors, 2024-03-16

Re: [PATCH bpf-next v3 2/2] bpf: Check return from set_memory_rox()

From: Martin KaFai Lau <martin.lau@linux.dev>
Date: 2024-03-16 00:56:37
Also in: bpf, lkml, netdev

On 3/15/24 2:11 PM, Martin KaFai Lau wrote:
On 3/15/24 1:55 PM, Martin KaFai Lau wrote:
quoted
On 3/15/24 10:06 AM, Christophe Leroy wrote:
quoted
diff --git a/kernel/bpf/bpf_struct_ops.c b/kernel/bpf/bpf_struct_ops.c
index 43356faaa057..ca1d9b87c475 100644
--- a/kernel/bpf/bpf_struct_ops.c
+++ b/kernel/bpf/bpf_struct_ops.c
@@ -742,8 +742,11 @@ static long bpf_struct_ops_map_update_elem(struct 
bpf_map *map, void *key,
          if (err)
              goto reset_unlock;
      }
-    for (i = 0; i < st_map->image_pages_cnt; i++)
-        arch_protect_bpf_trampoline(st_map->image_pages[i], PAGE_SIZE);
+    for (i = 0; i < st_map->image_pages_cnt && !err; i++)
I was about to apply but I still think checking "&& !err" is not right given how 
"err" is used in the earlier code of this function.

The err may not be 0 in the first iteration of this for loop. Take a look at the 
"if (err > 0)" check in the "for_each_member(i, t, member)" loop above.
quoted
quoted
+        err = arch_protect_bpf_trampoline(st_map->image_pages[i], PAGE_SIZE);
+
+    if (err)
+        goto reset_unlock;
This part does not look right. The "if (err)" check should be inside the for 
loop.
Instead of adding an extra "err = 0;" before the for loop. It is better to move 
this "if (err) goto reset_unlock;" into the for loop and remove the "&& !err" 
test above.
ah. Please ignore. missed the "!err" in the for loop.



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help