Skip to content

Commit 87c97f6

Browse files
committed
selftests/bpf: null checks for bpf_rdonly_cast(..., 0) should be preserved
Signed-off-by: Eduard Zingerman <[email protected]>
1 parent 130f959 commit 87c97f6

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tools/testing/selftests/bpf/progs/mem_rdonly_untrusted.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,25 @@ int misaligned_access(void *ctx)
205205
return combine(bpf_rdonly_cast(&global, 0) + 1);
206206
}
207207

208+
__weak int return_one(void)
209+
{
210+
return 1;
211+
}
212+
213+
SEC("socket")
214+
__success
215+
__retval(1)
216+
int null_check(void *ctx)
217+
{
218+
int *p;
219+
220+
p = bpf_rdonly_cast(0, 0);
221+
if (p == 0)
222+
/* make this a function call to avoid compiler
223+
* moving r0 assignment before check.
224+
*/
225+
return return_one();
226+
return 0;
227+
}
228+
208229
char _license[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)