Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: tavip@google.com
Cc: netdev@vger.kernel.org, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, pabeni@redhat.com, willemb@google.com,
	horms@kernel.org, andrew+netdev@lunn.ch, ncardwell@google.com,
	kuniyu@google.com, dsahern@kernel.org, idosch@nvidia.com,
	john.fastabend@gmail.com, jakub@cloudflare.com,
	jiayuan.chen@linux.dev, sd@queasysnail.net, shuah@kernel.org,
	almasrymina@google.com, sdf@fomichev.me, kaiyuanz@google.com,
	ilias.apalodimas@linaro.org, hawk@kernel.org,
	mcroce@microsoft.com, herbert@gondor.apana.org.au,
	ecree.xilinx@gmail.com, bpf@vger.kernel.org,
	linux-kselftest@vger.kernel.org
Subject: Re: [PATCH net 09/10] selftests: drv-net: devmem: test unreadable kTLS RX
Date: Fri, 04 Dec 2026 22:08:01 +0000	[thread overview]
Message-ID: <179642208138.3146.6982302182502396226@kernel.org> (raw)
In-Reply-To: <62d1a0251d6eef295df7215f274cce53dec2d6e9.1796329894.git.tavip@google.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 2

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] selftests: drv-net: hardcoded UDMABUF_CREATE breaks non-
  generic arches
- [Low] In run_rx_tls()
  (tools/testing/selftests/drivers/net/hw/devmem_lib.py), the assertion…
- [Low] selftests: drv-net: devmem: check_rx_tls() missing
  ksft_disruptive decorator

--

selftests: drv-net: devmem: test unreadable kTLS RX

This adds a devmem.py test that queues unreadable devmem fragments on a
TCP socket, then installs TLS_RX on that socket. It checks that the first
recv() fails with EFAULT. The devmem RX queue is bound directly from
Python so that the test owns the TCP socket.

> diff --git a/tools/testing/selftests/drivers/net/hw/devmem_lib.py b/tools/testing/selftests/drivers/net/hw/devmem_lib.py
> index 71b916c161969..75199a01ca3fc 100644
> --- a/tools/testing/selftests/drivers/net/hw/devmem_lib.py
> +++ b/tools/testing/selftests/drivers/net/hw/devmem_lib.py

[ ... ]

> @@ -314,3 +320,203 @@ def run_rx_hds(cfg):

[ ... ]

> +def run_rx_tls(cfg):
> +    """Verify kTLS RX rejects queued unreadable devmem skbs with EFAULT."""

[ ... ]

> +        try:
> +            conn.setsockopt(SOL_TLS, TLS_RX, crypto_info)
> +        except OSError as e:
> +            if e.errno in (errno.ENOENT, errno.EOPNOTSUPP):
> +                raise KsftSkipEx("TLS_CIPHER_AES_GCM_128 unavailable") from e
> +            raise
> +
> +        with ksft_raises(OSError) as cm:
> +            conn.recv(64)
> +        ksft_eq(cm.exception.errno, errno.EFAULT)
> +        ksft_eq(conn.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR), 0)

[Severity: Low]
Can this SO_ERROR check in run_rx_tls() ever fail?

When TLS_RX is armed while the unreadable devmem skb is queued, the
parser is aborted in tls_strp_copyin():

net/tls/tls_strp.c:tls_strp_copyin() {
    ...
	if (unlikely(!skb_frags_readable(in_skb))) {
		tls_strp_abort_strp(strp, -EFAULT);
		desc->error = -EFAULT;
		return 0;
	}
    ...
}

tls_strp_abort_strp() sets strp->stopped and reports the error to user
space only through sk->sk_err.

The recv(64) then goes through tls_sw_recvmsg()->tls_rx_rec_wait() with
has_copied false, so it returns sock_error(sk):

net/tls/tls_sw.c:tls_rx_rec_wait() {
    ...
		if (sk->sk_err) {
			if (has_copied)
				return -READ_ONCE(sk->sk_err);
			return sock_error(sk);
		}
    ...
}

sock_error() does xchg(&sk->sk_err, 0). By the time
getsockopt(SO_ERROR) runs, sk_err has already been cleared. SO_ERROR
then falls back to sk_err_soft, which is also 0 for this flow. The check
reads 0 no matter what the kernel did.

The assertion looks like it backs up the "rejects the record cleanly"
wording in the commit message. It doesn't say anything about the state
of the socket after the error, though. For example, the strparser stays
stopped for good.

Would it make more sense to check that SO_ERROR == EFAULT before the
recv(), to show that the error was latched during setsockopt(TLS_RX)?
Another option is to check how a second recv() behaves. If neither is
wanted, could this line be dropped? The main EFAULT check above is still
meaningful.

> +        conn.close()

[ ... ]

> @@ -314,3 +320,203 @@ def run_rx_hds(cfg):
>              cmd(f"dd if=/dev/zero bs={size} count=1 2>/dev/null | "
>                  f"{socat}", host=cfg.remote, shell=True)
>          ksft_eq(ncdevmem.ret, 0, f"HDS failed for payload size {size}")
> +
> +
> +SOL_TLS = 282
> +TLS_RX = 2
> +TLS_1_2_VERSION = 0x0303
> +TLS_CIPHER_AES_GCM_128 = 51
> +TCP_ULP = 31
> +UDMABUF_FLAGS_CLOEXEC = 0x01
> +UDMABUF_CREATE = 0x40187542
> +NUM_DEVMEM_PAGES = 16000
> +
> +
> +class _Udmabuf:
> +    """Small udmabuf wrapper for Python socket protocol tests."""
> +
> +    def __init__(self, size=None):
> +        if size is None:
> +            size = os.sysconf("SC_PAGE_SIZE") * NUM_DEVMEM_PAGES
> +        self.size = size
> +        self.dmabuf_fd = -1
> +        self.devfd = -1
> +        self.memfd = -1
> +        try:
> +            self.memfd = os.memfd_create("devmem-test", os.MFD_ALLOW_SEALING)
> +            os.ftruncate(self.memfd, size)
> +            fcntl.fcntl(self.memfd, fcntl.F_ADD_SEALS, fcntl.F_SEAL_SHRINK)
> +            try:
> +                self.devfd = os.open("/dev/udmabuf", os.O_RDONLY)
> +            except OSError as e:
> +                if e.errno in (errno.ENOENT, errno.ENODEV, errno.EACCES):
> +                    raise KsftSkipEx(f"/dev/udmabuf unavailable: {e}") from e
> +                raise
> +            req = bytearray(struct.pack("IIQQ", self.memfd,
> +                                        UDMABUF_FLAGS_CLOEXEC, 0, size))
> +            self.dmabuf_fd = fcntl.ioctl(self.devfd, UDMABUF_CREATE, req)
> +        except BaseException:
> +            self.close()
> +            raise
> +
> +    def close(self):
> +        """Close file descriptors."""
> +        for attr in ("dmabuf_fd", "devfd", "memfd"):
> +            fd = getattr(self, attr, -1)
> +            if fd >= 0:
> +                os.close(fd)
> +                setattr(self, attr, -1)
> +
> +
> +def _restore_hds(ethnl, ifindex, orig_split, has_thresh, orig_thresh):
> +    req = {'header': {'dev-index': ifindex}, 'tcp-data-split': 'unknown'}
> +    if has_thresh:
> +        req['hds-thresh'] = orig_thresh
> +    ethnl.rings_set(req)
> +    cur = ethnl.rings_get({'header': {'dev-index': ifindex}})
> +    if cur.get('tcp-data-split') != orig_split:
> +        ethnl.rings_set({'header': {'dev-index': ifindex},
> +                         'tcp-data-split': orig_split})
> +
> +
> +def _setup_devmem_rx_queue(cfg):
> +    """Isolate and bind one devmem RX queue; return its queue ID."""
> +    require_devmem(cfg)
> +    ethnl = EthtoolFamily()
> +    channels = ethnl.channels_get({'header': {'dev-index': cfg.ifindex}})
> +    qcnt = channels.get('rx-count', 0) + channels.get('combined-count', 0)
> +    if qcnt < 2:
> +        raise KsftSkipEx("Test requires at least 2 RX queues")
> +
> +    rxq = qcnt - 1
> +    ubuf = _Udmabuf()
> +    defer(ubuf.close)
> +
> +    rings = ethnl.rings_get({'header': {'dev-index': cfg.ifindex}})
> +    orig_split = rings.get('tcp-data-split', 'unknown')
> +    has_thresh = 'hds-thresh' in rings
> +    orig_thresh = rings.get('hds-thresh', 0)
> +    req = {'header': {'dev-index': cfg.ifindex}, 'tcp-data-split': 'enabled'}

[Severity: Low]
Should check_rx_tls() be marked @ksft_disruptive, like check_rx(),
check_tx() and check_tx_chunks() in this file?

run_rx_tls() calls _setup_devmem_rx_queue(), which changes the NIC
configuration in several ways:

- it flips tcp-data-split and hds-thresh through ethnl.rings_set(),
  and restores them again in _restore_hds()
- it rewrites the RSS indirection table with ethtool -X
- it binds a devmem RX queue

Some devmem capable drivers bounce the interface on a ring change.
bnxt_set_ringparam() calls bnxt_close_nic() and bnxt_open_nic() when
the device is running. gve does something similar through
gve_adjust_config(). Either way NETIF can go down briefly.

drivers/net/README.rst says tests that may disconnect NETIF must be
annotated with @ksft_disruptive, so that runs with DISRUPTIVE=False on
single-interface hosts skip them. As written, this test still runs in
that mode. It can drop the connection the harness relies on to reach
the remote.

> +    if has_thresh:
> +        req['hds-thresh'] = 0
> +    ethnl.rings_set(req)
> +    defer(_restore_hds, ethnl, cfg.ifindex, orig_split, has_thresh,
> +          orig_thresh)
> +
> +    ethtool(f"-X {cfg.ifname} equal {rxq}")
> +    defer(ethtool, f"-X {cfg.ifname} default")
> +
> +    netdevnl = NetdevFamily()
> +    netdevnl.bind_rx({
> +        "ifindex": cfg.ifindex,
> +        "fd": ubuf.dmabuf_fd,
> +        "queues": [{"type": "rx", "id": rxq}],
> +    })
> +    defer(netdevnl.close)
> +    return rxq
> +
> +
> +def _steer_tcp_flow(cfg, port, rxq, src_port):
> +    proto = f"tcp{cfg.addr_ipver}"
> +    spec5 = (f"flow-type {proto} src-ip {cfg.remote_addr} dst-ip {cfg.addr} "
> +             f"src-port {src_port} dst-port {port} queue {rxq}")
> +    spec3 = (f"flow-type {proto} dst-ip {cfg.addr} dst-port {port} "
> +             f"queue {rxq}")
> +    try:
> +        out = ethtool(f"-N {cfg.ifname} {spec5}").stdout
> +    except CmdExitFailure:
> +        out = ethtool(f"-N {cfg.ifname} {spec3}").stdout
> +    rule_id = int(re.search(r"ID (\d+)", out).group(1))
> +    defer(ethtool, f"-N {cfg.ifname} delete {rule_id}")
> +    return rule_id
> +
> +
> +def _remote_py(cfg, script, bg=False):
> +    cfg.require_cmd("python3", local=False, remote=True)
> +    b64 = base64.b64encode(script.encode("utf-8")).decode("ascii")
> +    py_cmd = f"python3 -c 'import base64; exec(base64.b64decode(\"{b64}\"))'"
> +    if bg:
> +        return bkg(py_cmd, host=cfg.remote, exit_wait=True)
> +    return cmd(py_cmd, host=cfg.remote)
> +
> +
> +def _listen_tcp(cfg, port):
> +    af = socket.AF_INET6 if cfg.addr_ipver == "6" else socket.AF_INET
> +    srv = socket.socket(af, socket.SOCK_STREAM)
> +    defer(srv.close)
> +    srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
> +    srv.settimeout(5.0)
> +    srv.bind((cfg.addr, port))
> +    srv.listen(1)
> +    return srv, af
> +
> +
> +def _tcp_inq(sock):
> +    buf = fcntl.ioctl(sock.fileno(), termios.FIONREAD, b"\x00\x00\x00\x00")
> +    return struct.unpack("i", buf)[0]
> +
> +
> +def run_rx_tls(cfg):
> +    """Verify kTLS RX rejects queued unreadable devmem skbs with EFAULT."""
> +    rxq = _setup_devmem_rx_queue(cfg)
> +    port = rand_port()
> +    srv, af = _listen_tcp(cfg, port)
> +
> +    sender_script = f"""
> +import socket
> +s = socket.socket({int(af)}, socket.SOCK_STREAM)
> +s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
> +s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
> +s.bind(("{cfg.remote_addr}", 0))
> +s.connect(("{cfg.addr}", {port}))
> +s.sendall(b"\\x17\\x03\\x03\\x00\\x20" + (b"\\x05" * 8))
> +s.recv(1)
> +s.sendall(b"\\x11" * 24)
> +try:
> +    s.recv(1)
> +except OSError:
> +    pass
> +s.close()
> +"""
> +    with _remote_py(cfg, sender_script, bg=True):
> +        conn, peer = srv.accept()
> +        defer(conn.close)
> +        conn.settimeout(5.0)
> +
> +        ksft_busy_wait(lambda: _tcp_inq(conn) >= 13, deadline=5,
> +                       comment="Timed out waiting for TLS header")
> +        ksft_eq(len(conn.recv(13, socket.MSG_PEEK)), 13)
> +
> +        _steer_tcp_flow(cfg, port, rxq, peer[1])
> +        conn.sendall(b"G")
> +
> +        ksft_busy_wait(lambda: _tcp_inq(conn) >= 37, deadline=5,
> +                       comment="Timed out waiting for devmem TLS payload")
> +        ksft_eq(_tcp_inq(conn), 37)
> +
> +        try:
> +            conn.setsockopt(socket.IPPROTO_TCP, TCP_ULP, b"tls\x00")
> +        except OSError as e:
> +            if e.errno in (errno.ENOENT, errno.EOPNOTSUPP):
> +                raise KsftSkipEx("TLS ULP is not available") from e
> +            raise
> +
> +        crypto_info = struct.pack("=HH8s16s4s8s",
> +                                  TLS_1_2_VERSION,
> +                                  TLS_CIPHER_AES_GCM_128,
> +                                  b"\x01" * 8,
> +                                  b"\x02" * 16,
> +                                  b"\x03" * 4,
> +                                  b"\x04" * 8)
> +        try:
> +            conn.setsockopt(SOL_TLS, TLS_RX, crypto_info)
> +        except OSError as e:
> +            if e.errno in (errno.ENOENT, errno.EOPNOTSUPP):
> +                raise KsftSkipEx("TLS_CIPHER_AES_GCM_128 unavailable") from e
> +            raise
> +
> +        with ksft_raises(OSError) as cm:
> +            conn.recv(64)
> +        ksft_eq(cm.exception.errno, errno.EFAULT)
> +        ksft_eq(conn.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR), 0)
> +        conn.close()

[Severity: Medium]
Will this ioctl number work on all architectures?

UDMABUF_CREATE is hardcoded here with the asm-generic _IOW() encoding.
The uapi header defines it as _IOW('u', 0x42, struct udmabuf_create).
The direction bits of that macro depend on the architecture.

On powerpc, mips, sparc and alpha, _IOC_WRITE is 4U and _IOC_DIRSHIFT
is 29. On parisc, _IOC_WRITE is 2U. On all of these the kernel's value
is 0x80187542, not 0x40187542.

udmabuf_ioctl() switches on the kernel-compiled UDMABUF_CREATE and
returns -ENOTTY for anything else. So _Udmabuf.__init__() fails with
OSError(ENOTTY) on every run on those architectures.

The skip handling does not cover this case. Only the os.open() of
/dev/udmabuf is turned into KsftSkipEx. ncdevmem is built against the
real linux/udmabuf.h, so require_devmem() succeeds before we get here.
The result is a hard failure on otherwise working setups, for example
ppc64le with a devmem capable NIC. The next patch in the series also
uses _Udmabuf(), so it has the same problem.

Could the request number be derived from the per-arch _IOC layout,
for example keyed on platform.machine(), instead of using a fixed
constant? Or is there a better way to get the value from the real
header?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1796329894.git.tavip%40google.com

  parent reply	other threads:[~2026-12-04 22:08 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 21:09 [PATCH net 00/10] net: fix unreadable net_iov skb handling across networking paths Octavian Purdila
2026-12-03 21:09 ` [PATCH net 01/10] net: gro: free skb on napi_frags_skb() header pull failure Octavian Purdila
2026-12-04 18:31   ` Mina Almasry
2026-12-03 21:09 ` [PATCH net 02/10] net: gro: reset unreadable and pp_recycle in napi_reuse_skb Octavian Purdila
2026-12-04 18:32   ` Mina Almasry
2026-12-04 21:07     ` Octavian Purdila
2026-12-04 22:07   ` netdev-bot+sashiko
2026-12-03 21:09 ` [PATCH net 03/10] inet: frag: reject fragments with mixed readability in reassembly Octavian Purdila
2026-12-04 18:38   ` Mina Almasry
2026-12-04 21:09     ` Octavian Purdila
2026-12-04 22:07   ` netdev-bot+sashiko
2026-12-03 21:09 ` [PATCH net 04/10] net: skbuff, skmsg, strparser: reject unreadable frags Octavian Purdila
2026-12-04 18:58   ` Mina Almasry
2026-12-04 21:25     ` Octavian Purdila
2026-12-04 22:07   ` netdev-bot+sashiko
2026-12-03 21:09 ` [PATCH net 05/10] tls: reject unreadable skbs in tls_strp Octavian Purdila
2026-12-04 18:44   ` Mina Almasry
2026-12-04 22:24     ` Octavian Purdila
2026-12-04 22:07   ` netdev-bot+sashiko
2026-12-03 21:09 ` [PATCH net 06/10] tcp: reject unreadable skbs on TCP-MD5 and TCP-AO Octavian Purdila
2026-12-04 18:46   ` Mina Almasry
2026-12-04 22:26     ` Octavian Purdila
2026-12-04 22:07   ` netdev-bot+sashiko
2026-12-03 21:09 ` [PATCH net 07/10] net: kunit: test unreadable net_iov napi_gro_frags Octavian Purdila
2026-12-04 18:47   ` Mina Almasry
2026-12-04 22:07   ` netdev-bot+sashiko
2026-12-03 21:09 ` [PATCH net 08/10] net: kunit: test unreadable net_iov defrag and skb helpers Octavian Purdila
2026-12-04 22:07   ` netdev-bot+sashiko
2026-12-03 21:09 ` [PATCH net 09/10] selftests: drv-net: devmem: test unreadable kTLS RX Octavian Purdila
2026-12-04 18:48   ` Mina Almasry
2026-12-04 22:28     ` Octavian Purdila
2026-12-04 22:08   ` netdev-bot+sashiko [this message]
2026-12-03 21:09 ` [PATCH net 10/10] selftests: drv-net: devmem: test unreadable skbs on TCP-MD5 and TCP-AO Octavian Purdila
2026-12-04 22:08   ` netdev-bot+sashiko

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=179642208138.3146.6982302182502396226@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=almasrymina@google.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=bpf@vger.kernel.org \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=ecree.xilinx@gmail.com \
    --cc=edumazet@kernel.org \
    --cc=hawk@kernel.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=horms@kernel.org \
    --cc=idosch@nvidia.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jakub@cloudflare.com \
    --cc=jiayuan.chen@linux.dev \
    --cc=john.fastabend@gmail.com \
    --cc=kaiyuanz@google.com \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mcroce@microsoft.com \
    --cc=ncardwell@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sd@queasysnail.net \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=tavip@google.com \
    --cc=willemb@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