From: Daniel Zahka <daniel.zahka@gmail.com>
To: Jakub Kicinski <kuba@kernel.org>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
Shuah Khan <shuah@kernel.org>
Cc: Willem de Bruijn <willemb@google.com>,
Breno Leitao <leitao@debian.org>, Petr Machata <petrm@nvidia.com>,
Yuyang Huang <yuyanghuang@google.com>,
Xiao Liang <shaw.leon@gmail.com>,
Carolina Jubran <cjubran@nvidia.com>,
Donald Hunter <donald.hunter@gmail.com>,
netdev@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: [PATCH net-next v2 6/8] selftests: drv-net: psp: add connection breaking tests
Date: Thu, 25 Sep 2025 14:16:42 -0700 [thread overview]
Message-ID: <20250925211647.3450332-7-daniel.zahka@gmail.com> (raw)
In-Reply-To: <20250925211647.3450332-1-daniel.zahka@gmail.com>
From: Jakub Kicinski <kuba@kernel.org>
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 <kuba@kernel.org>
Signed-off-by: Daniel Zahka <daniel.zahka@gmail.com>
---
tools/testing/selftests/drivers/net/psp.py | 90 +++++++++++++++++++++-
1 file changed, 89 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/drivers/net/psp.py b/tools/testing/selftests/drivers/net/psp.py
index b4d97a9a5fbc..f9647371b791 100755
--- a/tools/testing/selftests/drivers/net/psp.py
+++ b/tools/testing/selftests/drivers/net/psp.py
@@ -15,6 +15,10 @@ from lib.py import NetDrvEpEnv, PSPFamily, NlError
from lib.py import bkg, rand_port, wait_port_listen
+class PSPExceptShortIO(Exception):
+ pass
+
+
def _get_outq(s):
one = b'\0' * 4
outq = fcntl.ioctl(s.fileno(), termios.TIOCOUTQ, one)
@@ -99,6 +103,16 @@ def _check_data_rx(cfg, exp_len):
time.sleep(0.01)
ksft_eq(read_len, exp_len)
+
+def _check_data_outq(s, exp_len, force_wait=False):
+ outq = 0
+ for _ in range(10):
+ outq = _get_outq(s)
+ if not force_wait and outq == exp_len:
+ break
+ time.sleep(0.01)
+ ksft_eq(outq, exp_len)
+
#
# Test cases
#
@@ -324,6 +338,80 @@ def _data_basic_send(cfg, version, ipver):
_close_psp_conn(cfg, s)
+def __bad_xfer_do(cfg, s, tx, version='hdr0-aes-gcm-128'):
+ # Make sure we accept the ACK for the SPI before we seal with the bad assoc
+ _check_data_outq(s, 0)
+
+ cfg.pspnl.tx_assoc({"dev-id": cfg.psp_dev_id,
+ "version": version,
+ "tx-key": tx,
+ "sock-fd": s.fileno()})
+
+ data_len = _send_careful(cfg, s, 20)
+ _check_data_outq(s, data_len, force_wait=True)
+ _check_data_rx(cfg, 0)
+ _close_psp_conn(cfg, s)
+
+
+def data_send_bad_key(cfg):
+ """ Test send data with bad key """
+ s = _make_psp_conn(cfg)
+
+ rx_assoc = cfg.pspnl.rx_assoc({"version": 0,
+ "dev-id": cfg.psp_dev_id,
+ "sock-fd": s.fileno()})
+ rx = rx_assoc['rx-key']
+ tx = _spi_xchg(s, rx)
+ tx['key'] = (tx['key'][0] ^ 0xff).to_bytes(1, 'little') + tx['key'][1:]
+ __bad_xfer_do(cfg, s, tx)
+
+
+def data_send_disconnect(cfg):
+ """ Test socket close after sending data """
+ with _make_psp_conn(cfg) as s:
+ assoc = cfg.pspnl.rx_assoc({"version": 0,
+ "sock-fd": s.fileno()})
+ tx = _spi_xchg(s, assoc['rx-key'])
+ cfg.pspnl.tx_assoc({"version": 0,
+ "tx-key": tx,
+ "sock-fd": s.fileno()})
+
+ data_len = _send_careful(cfg, s, 100)
+ _check_data_rx(cfg, data_len)
+
+ s.shutdown(socket.SHUT_RDWR)
+ s.close()
+
+
+def data_stale_key(cfg):
+ """ Test send on a double-rotated key """
+
+ s = _make_psp_conn(cfg)
+ try:
+ rx_assoc = cfg.pspnl.rx_assoc({"version": 0,
+ "dev-id": cfg.psp_dev_id,
+ "sock-fd": s.fileno()})
+ rx = rx_assoc['rx-key']
+ tx = _spi_xchg(s, rx)
+
+ cfg.pspnl.tx_assoc({"dev-id": cfg.psp_dev_id,
+ "version": 0,
+ "tx-key": tx,
+ "sock-fd": s.fileno()})
+
+ data_len = _send_careful(cfg, s, 100)
+ _check_data_rx(cfg, data_len)
+ _check_data_outq(s, 0)
+
+ cfg.pspnl.key_rotate({"id": cfg.psp_dev_id})
+ cfg.pspnl.key_rotate({"id": cfg.psp_dev_id})
+
+ s.send(b'0123456789' * 200)
+ _check_data_outq(s, 2000, force_wait=True)
+ finally:
+ _close_psp_conn(cfg, s)
+
+
def psp_ip_ver_test_builder(name, test_func, psp_ver, ipver):
"""Build test cases for each combo of PSP version and IP version"""
def test_case(cfg):
@@ -374,7 +462,7 @@ def main() -> None:
if cfg.psp_dev_id is not None:
ksft_run(cases=cases, globs=globals(),
- case_pfx={"dev_", "assoc_"},
+ case_pfx={"dev_", "data_", "assoc_"},
args=(cfg, ))
else:
ksft_pr("No PSP device found, skipping all tests")
--
2.47.3
next prev parent reply other threads:[~2025-09-25 21:16 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-25 21:16 [PATCH net-next v2 0/8] psp: add a kselftest suite and netdevsim implementation Daniel Zahka
2025-09-25 21:16 ` [PATCH net-next v2 1/8] netdevsim: a basic test PSP implementation Daniel Zahka
2025-09-25 21:16 ` [PATCH net-next v2 2/8] selftests: drv-net: base device access API test Daniel Zahka
2025-09-25 21:16 ` [PATCH net-next v2 3/8] selftests: drv-net: add PSP responder Daniel Zahka
2025-09-25 21:16 ` [PATCH net-next v2 4/8] selftests: drv-net: psp: add basic data transfer and key rotation tests Daniel Zahka
2025-09-25 21:16 ` [PATCH net-next v2 5/8] selftests: drv-net: psp: add association tests Daniel Zahka
2025-09-25 21:16 ` Daniel Zahka [this message]
2025-09-25 21:16 ` [PATCH net-next v2 7/8] selftests: drv-net: psp: add test for auto-adjusting TCP MSS Daniel Zahka
2025-09-25 21:16 ` [PATCH net-next v2 8/8] selftests: drv-net: psp: add tests for destroying devices Daniel Zahka
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250925211647.3450332-7-daniel.zahka@gmail.com \
--to=daniel.zahka@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=cjubran@nvidia.com \
--cc=davem@davemloft.net \
--cc=donald.hunter@gmail.com \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=leitao@debian.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=petrm@nvidia.com \
--cc=shaw.leon@gmail.com \
--cc=shuah@kernel.org \
--cc=willemb@google.com \
--cc=yuyanghuang@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox