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: stab…@vger.kernel.org Signed-off-by: Hu Xinyao <huxi…@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