mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] xsk: Fix locked_vm leak on partial pin in xdp_umem_pin_pages()
@ 2026-11-30  2:55 Hu Xinyao
  2026-11-30  2:59 ` netdev-bot+sinfo
  2026-11-30 10:15 ` Maciej Fijalkowski
  0 siblings, 2 replies; 4+ messages in thread
From: Hu Xinyao @ 2026-11-30  2:55 UTC (permalink / raw)
  To: Magnus Karlsson, Maciej Fijalkowski
  Cc: Stanislav Fomichev, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
	netdev, bpf, linux-kernel

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>
---
 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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] xsk: Fix locked_vm leak on partial pin in xdp_umem_pin_pages()
  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
  1 sibling, 1 reply; 4+ messages in thread
From: netdev-bot+sinfo @ 2026-11-30  2:59 UTC (permalink / raw)
  To: Hu Xinyao
  Cc: Magnus Karlsson, Maciej Fijalkowski, Stanislav Fomichev,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Willem de Bruijn, Simon Horman, netdev, bpf, linux-kernel

Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - How the issue was discovered, e.g. hit in production, hit during
   development, syzbot report, manual code inspection, LLM or static
   analysis tool scan.

 - Whether the issue was actually triggered, or is only theoretical
   (e.g. found by LLM and not proven at runtime). If it was triggered
   please include the symptoms, like the stack trace or kernel messages.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] xsk: Fix locked_vm leak on partial pin in xdp_umem_pin_pages()
  2026-11-30  2:59 ` netdev-bot+sinfo
@ 2026-11-30  3:09   ` Hu Xinyao
  0 siblings, 0 replies; 4+ messages in thread
From: Hu Xinyao @ 2026-11-30  3:09 UTC (permalink / raw)
  To: netdev-bot+sinfo
  Cc: Magnus Karlsson, Maciej Fijalkowski, Stanislav Fomichev,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Willem de Bruijn, Simon Horman, netdev, bpf, linux-kernel

On Mon, 30 Nov 2026, netdev-bot+sinfo@kernel.org wrote:
>  - How the issue was discovered, e.g. hit in production, hit during
>    development, syzbot report, manual code inspection, LLM or static
>    analysis tool scan.
>
>  - Whether the issue was actually triggered, or is only theoretical
>    (e.g. found by LLM and not proven at runtime). If it was triggered
>    please include the symptoms, like the stack trace or kernel messages.

1. Discovery: Found during a GLM-5.4-assisted code audit of
   net/xdp/xdp_umem.c and verified manually against v7.3.6 and mainline.

2. Testing: Compile-tested only (CONFIG_XDP_SOCKETS=y with -Werror); not
   triggered at runtime. By inspection, setsockopt(XDP_UMEM_REG) on a
   multi-page range where a trailing page is unmapped or read-only
   (pin_user_pages() passes FOLL_WRITE) results in 0 < npgs < umem->npgs
   and takes this error path.

Thanks,
Hu Xinyao

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] xsk: Fix locked_vm leak on partial pin in xdp_umem_pin_pages()
  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 10:15 ` Maciej Fijalkowski
  1 sibling, 0 replies; 4+ messages in thread
From: Maciej Fijalkowski @ 2026-11-30 10:15 UTC (permalink / raw)
  To: Hu Xinyao
  Cc: Magnus Karlsson, Stanislav Fomichev, David S.Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Willem de Bruijn,
	Simon Horman, netdev, bpf, linux-kernel

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
> 
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-30 10:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®