@@ -8962,13 +8962,6 @@ static bool range_within(struct bpf_reg_state *old,
8962
8962
old -> s32_max_value >= cur -> s32_max_value ;
8963
8963
}
8964
8964
8965
- /* Maximum number of register states that can exist at once */
8966
- #define ID_MAP_SIZE (MAX_BPF_REG + MAX_BPF_STACK / BPF_REG_SIZE)
8967
- struct idpair {
8968
- u32 old ;
8969
- u32 cur ;
8970
- };
8971
-
8972
8965
/* If in the old state two registers had the same id, then they need to have
8973
8966
* the same id in the new state as well. But that id could be different from
8974
8967
* the old state, so we need to track the mapping from old to new ids.
@@ -8979,11 +8972,11 @@ struct idpair {
8979
8972
* So we look through our idmap to see if this old id has been seen before. If
8980
8973
* so, we require the new id to match; otherwise, we add the id pair to the map.
8981
8974
*/
8982
- static bool check_ids (u32 old_id , u32 cur_id , struct idpair * idmap )
8975
+ static bool check_ids (u32 old_id , u32 cur_id , struct bpf_id_pair * idmap )
8983
8976
{
8984
8977
unsigned int i ;
8985
8978
8986
- for (i = 0 ; i < ID_MAP_SIZE ; i ++ ) {
8979
+ for (i = 0 ; i < BPF_ID_MAP_SIZE ; i ++ ) {
8987
8980
if (!idmap [i ].old ) {
8988
8981
/* Reached an empty slot; haven't seen this id before */
8989
8982
idmap [i ].old = old_id ;
@@ -9096,7 +9089,7 @@ static void clean_live_states(struct bpf_verifier_env *env, int insn,
9096
9089
9097
9090
/* Returns true if (rold safe implies rcur safe) */
9098
9091
static bool regsafe (struct bpf_reg_state * rold , struct bpf_reg_state * rcur ,
9099
- struct idpair * idmap )
9092
+ struct bpf_id_pair * idmap )
9100
9093
{
9101
9094
bool equal ;
9102
9095
@@ -9213,7 +9206,7 @@ static bool regsafe(struct bpf_reg_state *rold, struct bpf_reg_state *rcur,
9213
9206
9214
9207
static bool stacksafe (struct bpf_func_state * old ,
9215
9208
struct bpf_func_state * cur ,
9216
- struct idpair * idmap )
9209
+ struct bpf_id_pair * idmap )
9217
9210
{
9218
9211
int i , spi ;
9219
9212
@@ -9310,32 +9303,23 @@ static bool refsafe(struct bpf_func_state *old, struct bpf_func_state *cur)
9310
9303
* whereas register type in current state is meaningful, it means that
9311
9304
* the current state will reach 'bpf_exit' instruction safely
9312
9305
*/
9313
- static bool func_states_equal (struct bpf_func_state * old ,
9306
+ static bool func_states_equal (struct bpf_verifier_env * env , struct bpf_func_state * old ,
9314
9307
struct bpf_func_state * cur )
9315
9308
{
9316
- struct idpair * idmap ;
9317
- bool ret = false;
9318
9309
int i ;
9319
9310
9320
- idmap = kcalloc (ID_MAP_SIZE , sizeof (struct idpair ), GFP_KERNEL );
9321
- /* If we failed to allocate the idmap, just say it's not safe */
9322
- if (!idmap )
9323
- return false;
9324
-
9325
- for (i = 0 ; i < MAX_BPF_REG ; i ++ ) {
9326
- if (!regsafe (& old -> regs [i ], & cur -> regs [i ], idmap ))
9327
- goto out_free ;
9328
- }
9311
+ memset (env -> idmap_scratch , 0 , sizeof (env -> idmap_scratch ));
9312
+ for (i = 0 ; i < MAX_BPF_REG ; i ++ )
9313
+ if (!regsafe (& old -> regs [i ], & cur -> regs [i ], env -> idmap_scratch ))
9314
+ return false;
9329
9315
9330
- if (!stacksafe (old , cur , idmap ))
9331
- goto out_free ;
9316
+ if (!stacksafe (old , cur , env -> idmap_scratch ))
9317
+ return false ;
9332
9318
9333
9319
if (!refsafe (old , cur ))
9334
- goto out_free ;
9335
- ret = true;
9336
- out_free :
9337
- kfree (idmap );
9338
- return ret ;
9320
+ return false;
9321
+
9322
+ return true;
9339
9323
}
9340
9324
9341
9325
static bool states_equal (struct bpf_verifier_env * env ,
@@ -9362,7 +9346,7 @@ static bool states_equal(struct bpf_verifier_env *env,
9362
9346
for (i = 0 ; i <= old -> curframe ; i ++ ) {
9363
9347
if (old -> frame [i ]-> callsite != cur -> frame [i ]-> callsite )
9364
9348
return false;
9365
- if (!func_states_equal (old -> frame [i ], cur -> frame [i ]))
9349
+ if (!func_states_equal (env , old -> frame [i ], cur -> frame [i ]))
9366
9350
return false;
9367
9351
}
9368
9352
return true;
0 commit comments