Skip to content

Commit 2748087

Browse files
kuba-mooPaolo Abeni
authored andcommitted
selftests: drv-net: psp: add connection breaking tests
Add test checking conditions which lead to connections breaking. Using bad key or connection gets stuck if device key is rotated twice. Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Daniel Zahka <[email protected]> Link: https://patch.msgid.link/[email protected] Reviewed-by: Willem de Bruijn <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 81b8908 commit 2748087

File tree

1 file changed

+91
-1
lines changed
  • tools/testing/selftests/drivers/net

1 file changed

+91
-1
lines changed

tools/testing/selftests/drivers/net/psp.py

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ def _check_data_rx(cfg, exp_len):
9898
time.sleep(0.01)
9999
ksft_eq(read_len, exp_len)
100100

101+
102+
def _check_data_outq(s, exp_len, force_wait=False):
103+
outq = 0
104+
for _ in range(10):
105+
outq = _get_outq(s)
106+
if not force_wait and outq == exp_len:
107+
break
108+
time.sleep(0.01)
109+
ksft_eq(outq, exp_len)
110+
101111
#
102112
# Test case boiler plate
103113
#
@@ -372,6 +382,85 @@ def _data_basic_send(cfg, version, ipver):
372382
_close_psp_conn(cfg, s)
373383

374384

385+
def __bad_xfer_do(cfg, s, tx, version='hdr0-aes-gcm-128'):
386+
# Make sure we accept the ACK for the SPI before we seal with the bad assoc
387+
_check_data_outq(s, 0)
388+
389+
cfg.pspnl.tx_assoc({"dev-id": cfg.psp_dev_id,
390+
"version": version,
391+
"tx-key": tx,
392+
"sock-fd": s.fileno()})
393+
394+
data_len = _send_careful(cfg, s, 20)
395+
_check_data_outq(s, data_len, force_wait=True)
396+
_check_data_rx(cfg, 0)
397+
_close_psp_conn(cfg, s)
398+
399+
400+
def data_send_bad_key(cfg):
401+
""" Test send data with bad key """
402+
_init_psp_dev(cfg)
403+
404+
s = _make_psp_conn(cfg)
405+
406+
rx_assoc = cfg.pspnl.rx_assoc({"version": 0,
407+
"dev-id": cfg.psp_dev_id,
408+
"sock-fd": s.fileno()})
409+
rx = rx_assoc['rx-key']
410+
tx = _spi_xchg(s, rx)
411+
tx['key'] = (tx['key'][0] ^ 0xff).to_bytes(1, 'little') + tx['key'][1:]
412+
__bad_xfer_do(cfg, s, tx)
413+
414+
415+
def data_send_disconnect(cfg):
416+
""" Test socket close after sending data """
417+
_init_psp_dev(cfg)
418+
419+
with _make_psp_conn(cfg) as s:
420+
assoc = cfg.pspnl.rx_assoc({"version": 0,
421+
"sock-fd": s.fileno()})
422+
tx = _spi_xchg(s, assoc['rx-key'])
423+
cfg.pspnl.tx_assoc({"version": 0,
424+
"tx-key": tx,
425+
"sock-fd": s.fileno()})
426+
427+
data_len = _send_careful(cfg, s, 100)
428+
_check_data_rx(cfg, data_len)
429+
430+
s.shutdown(socket.SHUT_RDWR)
431+
s.close()
432+
433+
434+
def data_stale_key(cfg):
435+
""" Test send on a double-rotated key """
436+
_init_psp_dev(cfg)
437+
438+
s = _make_psp_conn(cfg)
439+
try:
440+
rx_assoc = cfg.pspnl.rx_assoc({"version": 0,
441+
"dev-id": cfg.psp_dev_id,
442+
"sock-fd": s.fileno()})
443+
rx = rx_assoc['rx-key']
444+
tx = _spi_xchg(s, rx)
445+
446+
cfg.pspnl.tx_assoc({"dev-id": cfg.psp_dev_id,
447+
"version": 0,
448+
"tx-key": tx,
449+
"sock-fd": s.fileno()})
450+
451+
data_len = _send_careful(cfg, s, 100)
452+
_check_data_rx(cfg, data_len)
453+
_check_data_outq(s, 0)
454+
455+
cfg.pspnl.key_rotate({"id": cfg.psp_dev_id})
456+
cfg.pspnl.key_rotate({"id": cfg.psp_dev_id})
457+
458+
s.send(b'0123456789' * 200)
459+
_check_data_outq(s, 2000, force_wait=True)
460+
finally:
461+
_close_psp_conn(cfg, s)
462+
463+
375464
def psp_ip_ver_test_builder(name, test_func, psp_ver, ipver):
376465
"""Build test cases for each combo of PSP version and IP version"""
377466
def test_case(cfg):
@@ -410,7 +499,8 @@ def main() -> None:
410499
]
411500

412501
ksft_run(cases=cases, globs=globals(),
413-
case_pfx={"dev_", "assoc_"}, args=(cfg, ))
502+
case_pfx={"dev_", "data_", "assoc_"},
503+
args=(cfg, ))
414504

415505
cfg.comm_sock.send(b"exit\0")
416506
cfg.comm_sock.close()

0 commit comments

Comments
 (0)