@@ -65,6 +65,7 @@ def exact_cu_cost(data_vec):
65
65
# fmt: off
66
66
test_vectors_all_ix = []
67
67
for op in range (0xFF ):
68
+ # for op in [0x07]:
68
69
def validate ():
69
70
for sreg in [0 , 2 , 6 , 9 , 10 , 11 ]:
70
71
for dreg in [0 , 9 , 10 , 11 ]:
@@ -169,11 +170,31 @@ def validate():
169
170
0x71e3cf81 , # magic - always SIGSTACK (ignore call_whitelist)
170
171
0x12345678 , # invalid
171
172
0x0b00c380 , # inverse of magic - just invalid
173
+ 0x3770fb22 , # syscall: sol_memset_
174
+ 1 , # success without relocation. works in v3+
175
+ 0 ,
176
+ 2 ,
177
+ 3 ,
178
+ 4 ,
179
+ 0xffffffff , # overflow ok because of negative offsets
172
180
]:
173
181
test_vectors_all_ix .append ({
174
182
"op" : f"{ op :02x} " ,
175
183
"cu_avail" : 100 ,
176
- # hashmap containing vaild pc: 0, 1, 2 (higher are trimmed)
184
+ # hashmap containing valid function
185
+ "call_whitelist" : [0x04 ],
186
+ "rodata" :
187
+ bytes ([op , ((sreg << 4 ) + dreg ) % 0xFF , 0 , 0 ]) + imm .to_bytes (4 , "little" ) + \
188
+ bytes ([0x95 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ]) + \
189
+ bytes ([0x95 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ])
190
+ })
191
+ # TODO: the following generates invalid functions to test validate()
192
+ # it's ok in v0-v2, it should return -2 in v3+
193
+ test_vectors_all_ix .append ({
194
+ "op" : f"{ op :02x} " ,
195
+ "cu_avail" : 100 ,
196
+ # hashmap containing valid pc: 0, 1, 2 (higher are trimmed)
197
+ # these are invalid fn in v3+
177
198
"call_whitelist" : [0xff ],
178
199
"rodata" :
179
200
bytes ([op , ((sreg << 4 ) + dreg ) % 0xFF , 0 , 0 ]) + imm .to_bytes (4 , "little" ) + \
@@ -248,6 +269,41 @@ def validate():
248
269
bytes ([op , ((sreg << 4 ) + dreg ) % 0xFF ]) + offset .to_bytes (2 , "little" ) + imm .to_bytes (4 , "little" ) + \
249
270
bytes ([0x95 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ])
250
271
})
272
+
273
+ if op in [0xc6 , 0xce , 0xd6 , 0xde , 0xe6 , 0xee , 0xf6 , 0xfe ]:
274
+ sreg = 2
275
+ dreg = 3
276
+ for imm in [0x0 , 0xffffffffffffffff ]:
277
+ for r3 in [
278
+ 0x80000000 , # not INT_MIN / LONG_MIN
279
+ 0xffffffff80000000 , # INT_MIN
280
+ 0x8000000000000000 , # LONG_MIN
281
+ ]:
282
+ test_vectors_all_ix .append ({
283
+ "op" : f"{ op :02x} " ,
284
+ "cu_avail" : 100 ,
285
+ "r2" : imm ,
286
+ "r3" : r3 ,
287
+ "rodata" :
288
+ bytes ([op , ((sreg << 4 ) + dreg ) % 0xFF , 0 , 0 ]) + (imm & 0xFFFFFFFF ).to_bytes (4 , "little" ) + \
289
+ bytes ([0x95 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ])
290
+ })
291
+
292
+ # syscall (v3)
293
+ if op == 0x95 :
294
+ sreg = 0
295
+ dreg = 0
296
+ for imm in [
297
+ 3 , # sol_memset_
298
+ 100 , # invalid
299
+ ]:
300
+ test_vectors_all_ix .append ({
301
+ "op" : f"{ op :02x} " ,
302
+ "cu_avail" : 100 ,
303
+ "rodata" :
304
+ bytes ([ op , 0 , 0 , 0 ]) + imm .to_bytes (4 , "little" ) + \
305
+ bytes ([0x9d , 0 , 0 , 0 , 0 , 0 , 0 , 0 ])
306
+ })
251
307
# fmt: on
252
308
253
309
@@ -320,4 +376,12 @@ def _into_key_data(key_prefix, test_vectors):
320
376
with open (f"{ OUTPUT_DIR } /{ testname } /v2/{ filename } .bin" , "wb" ) as f :
321
377
f .write (serialized_instr )
322
378
379
+ syscall_ctx .vm_ctx .sbpf_version = 3
380
+ syscall_ctx .vm_ctx .rodata = bytes (
381
+ [x if x != 0x95 else 0x9D for x in syscall_ctx .vm_ctx .rodata ]
382
+ )
383
+ serialized_instr = syscall_ctx .SerializeToString (deterministic = True )
384
+ with open (f"{ OUTPUT_DIR } /{ testname } /v3/{ filename } .bin" , "wb" ) as f :
385
+ f .write (serialized_instr )
386
+
323
387
print ("done!" )
0 commit comments