Netdev List
 help / color / mirror / Atom feed
From: Dairui Zhang <zhangdairui@gmail.com>
To: netdev@vger.kernel.org
Cc: Dairui Zhang <zhangdairui@gmail.com>,
	Jakub Kicinski <kuba@kernel.org>,
	Mina Almasry <almasrymina@google.com>,
	Stanislav Fomichev <sdf@fomichev.me>, David Wei <dw@davidwei.uk>
Subject: [BUG] net: devmem: NETDEV_CMD_BIND_TX has no permission check and no accounting
Date: Mon, 21 Sep 2026 01:47:27 +0800	[thread overview]
Message-ID: <20260920174727.1332115-1-zhangdairui@gmail.com> (raw)

NETDEV_CMD_BIND_TX appears to be the only mutating devmem genl
command with no permission enforcement:

        BIND_RX        GENL_UNS_ADMIN_PERM
        QUEUE_CREATE   GENL_ADMIN_PERM
        BIND_TX        (just GENL_CMD_CAP_DO)

GENL_CMD_CAP_DO is only metadata - genetlink only enforces
GENL_ADMIN_PERM / GENL_UNS_ADMIN_PERM - and
netdev_nl_bind_tx_doit() (net/core/netdev-genl.c:1155) has no
capable() of its own either. As far as I can tell that means any
user can call it, on any netns; it's been like this since
8802087d20c0 and is still true in mainline today.

On its own that would just be an exposure question, but the bind
path also does no accounting at all:

  - no limit per socket or per user (the only bound is the 2^32
    xarray id space),
  - allocations use GFP_KERNEL, not GFP_KERNEL_ACCOUNT
    (devmem.c:207), so memcg can't throttle them,
  - nothing deduplicates repeated binds of the same dmabuf fd, each
    one doing a full dma_buf_attach + map_attachment plus a gen_pool
    and a per-page tx_vec,
  - everything is held until the netlink socket is closed.

So an unprivileged user with a dmabuf fd can loop BIND_TX on a
NETMEM_TX_DMA device (fbnic, gve, mlx5, bnxt) and eat kernel memory
and IOMMU mappings until the machine falls over. gve is the GCE
guest NIC, which makes "any user inside a GCE VM" the most obvious
victim scenario.

e302aa3d00fb ("net: devmem: allow bind-rx from non-init user
namespaces") revisited the bind-rx permission flags a few months ago
(GENL_ADMIN_PERM -> GENL_UNS_ADMIN_PERM, for the container use
cases) and left bind-tx alone, which is what makes me suspect an
oversight rather than a design choice. I could be missing some
context though, so asking before sending any patch.

Questions:

  1. Is bind-tx meant to be unprivileged (like AF_XDP TX), or is it
     just missing GENL_UNS_ADMIN_PERM like bind-rx?
  2. If unprivileged is the intent, is a per-socket cap plus
     GFP_KERNEL_ACCOUNT acceptable?
  3. Should repeated binds of the same dmabuf fd be deduplicated?

Happy to send the patch for whichever model you pick.

Thanks,
Dairui Zhang

             reply	other threads:[~2026-09-20 17:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-20 17:47 Dairui Zhang [this message]
2026-09-21 18:07 ` [BUG] net: devmem: NETDEV_CMD_BIND_TX has no permission check and no accounting Dairui Zhang
     [not found]   ` <CAHS8izOM-Mjh_s=0K=8rDdvDdwORCsNMiKf7eoir97i95DkqEg@mail.gmail.com>
2026-09-21 18:34     ` Stanislav Fomichev
2026-09-21 18:43       ` Dairui Zhang

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=20260920174727.1332115-1-zhangdairui@gmail.com \
    --to=zhangdairui@gmail.com \
    --cc=almasrymina@google.com \
    --cc=dw@davidwei.uk \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=sdf@fomichev.me \
    /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