@@ -974,21 +974,37 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)
974
974
int pass ;
975
975
int flen ;
976
976
struct bpf_binary_header * bpf_hdr ;
977
+ struct bpf_prog * org_fp = fp ;
978
+ struct bpf_prog * tmp_fp ;
979
+ bool bpf_blinded = false;
977
980
978
981
if (!bpf_jit_enable )
979
- return fp ;
982
+ return org_fp ;
983
+
984
+ tmp_fp = bpf_jit_blind_constants (org_fp );
985
+ if (IS_ERR (tmp_fp ))
986
+ return org_fp ;
987
+
988
+ if (tmp_fp != org_fp ) {
989
+ bpf_blinded = true;
990
+ fp = tmp_fp ;
991
+ }
980
992
981
993
flen = fp -> len ;
982
994
addrs = kzalloc ((flen + 1 ) * sizeof (* addrs ), GFP_KERNEL );
983
- if (addrs == NULL )
984
- return fp ;
995
+ if (addrs == NULL ) {
996
+ fp = org_fp ;
997
+ goto out ;
998
+ }
999
+
1000
+ memset (& cgctx , 0 , sizeof (struct codegen_context ));
985
1001
986
- cgctx .idx = 0 ;
987
- cgctx .seen = 0 ;
988
1002
/* Scouting faux-generate pass 0 */
989
- if (bpf_jit_build_body (fp , 0 , & cgctx , addrs ))
1003
+ if (bpf_jit_build_body (fp , 0 , & cgctx , addrs )) {
990
1004
/* We hit something illegal or unsupported. */
1005
+ fp = org_fp ;
991
1006
goto out ;
1007
+ }
992
1008
993
1009
/*
994
1010
* Pretend to build prologue, given the features we've seen. This will
@@ -1003,8 +1019,10 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)
1003
1019
1004
1020
bpf_hdr = bpf_jit_binary_alloc (alloclen , & image , 4 ,
1005
1021
bpf_jit_fill_ill_insns );
1006
- if (!bpf_hdr )
1022
+ if (!bpf_hdr ) {
1023
+ fp = org_fp ;
1007
1024
goto out ;
1025
+ }
1008
1026
1009
1027
code_base = (u32 * )(image + FUNCTION_DESCR_SIZE );
1010
1028
@@ -1041,6 +1059,10 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)
1041
1059
1042
1060
out :
1043
1061
kfree (addrs );
1062
+
1063
+ if (bpf_blinded )
1064
+ bpf_jit_prog_release_other (fp , fp == org_fp ? tmp_fp : org_fp );
1065
+
1044
1066
return fp ;
1045
1067
}
1046
1068
0 commit comments