From: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
To: Hu Xinyao <huxinyao@kylinsec.com.cn>
Cc: Magnus Karlsson <magnus.karlsson@intel.com>,
Stanislav Fomichev <sdf@fomichev.me>,
David S.Miller <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Willem de Bruijn <willemb@google.com>,
Simon Horman <horms@kernel.org>, <netdev@vger.kernel.org>,
<bpf@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] xsk: Fix locked_vm leak on partial pin in xdp_umem_pin_pages()
Date: Mon, 30 Nov 2026 11:15:55 +0100 [thread overview]
Message-ID: <aw1M23Zw9skiqXgK@boxer> (raw)
In-Reply-To: <7E0188A1F2D2B61B+1796007332.199083-1-huxinyao@kylinsec.com.cn>
On Mon, Nov 30, 2026 at 11:55:32AM +0900, Hu Xinyao wrote:
> xdp_umem_reg() accounts umem->npgs pages against user->locked_vm via
> xdp_umem_account_pages() before calling xdp_umem_pin_pages().
>
> When pin_user_pages() pins fewer pages than requested (0 <= npgs <
> umem->npgs), xdp_umem_pin_pages() overwrites umem->npgs with npgs before
> returning -ENOMEM. xdp_umem_unaccount_pages() on the error path in
> xdp_umem_reg() then subtracts the reduced count, leaving the remaining
> pages permanently charged to user->locked_vm.
>
> Unpin the pinned pages directly without modifying umem->npgs and drop
> the now unused out_pin label.
>
> Fixes: c0c77d8fb787 ("xsk: add user memory registration support sockopt")
> Cc: stable@vger.kernel.org
> Signed-off-by: Hu Xinyao <huxinyao@kylinsec.com.cn>
Thanks for the fix, this has been already addressed here:
https://lore.kernel.org/netdev/179562059260.3381969.13546710565371160648@gmail.com/
pw-bot: reject
> ---
> net/xdp/xdp_umem.c | 11 +++--------
> 1 file changed, 3 insertions(+), 8 deletions(-)
>
> diff --git a/net/xdp/xdp_umem.c b/net/xdp/xdp_umem.c
> index cd86433..2477746 100644
> --- a/net/xdp/xdp_umem.c
> +++ b/net/xdp/xdp_umem.c
> @@ -108,18 +108,13 @@ static int xdp_umem_pin_pages(struct xdp_umem *umem, unsigned long address)
> mmap_read_unlock(current->mm);
>
> if (npgs != umem->npgs) {
> - if (npgs >= 0) {
> - umem->npgs = npgs;
> - err = -ENOMEM;
> - goto out_pin;
> - }
> - err = npgs;
> + if (npgs > 0)
> + unpin_user_pages_dirty_lock(umem->pgs, npgs, true);
> + err = npgs >= 0 ? -ENOMEM : npgs;
> goto out_pgs;
> }
> return 0;
>
> -out_pin:
> - xdp_umem_unpin_pages(umem);
> out_pgs:
> kvfree(umem->pgs);
> umem->pgs = NULL;
> --
> 2.43.0
>
>
prev parent reply other threads:[~2026-11-30 10:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 2:55 [PATCH] xsk: Fix locked_vm leak on partial pin in xdp_umem_pin_pages() Hu Xinyao
2026-11-30 2:59 ` netdev-bot+sinfo
2026-11-30 3:09 ` Hu Xinyao
2026-11-30 10:15 ` Maciej Fijalkowski [this message]
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=aw1M23Zw9skiqXgK@boxer \
--to=maciej.fijalkowski@intel.com \
--cc=bpf@vger.kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=huxinyao@kylinsec.com.cn \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=magnus.karlsson@intel.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@fomichev.me \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.