From: Zhu Yanjun <yanjun.zhu@intel.com>
To: zyjzyj2000@gmail.com, bjorn.topel@intel.com,
magnus.karlsson@intel.com, netdev@vger.kernel.org,
jonathan.lemon@gmail.com
Cc: Zhu Yanjun <yanjun.zhu@intel.com>, Ye Dong <dong.ye@intel.com>
Subject: [PATCH v3 1/1] xdp: avoid calling kfree twice
Date: Thu, 10 Dec 2020 23:26:10 -0500 [thread overview]
Message-ID: <20201211042610.71081-1-yanjun.zhu@intel.com> (raw)
In the function xdp_umem_pin_pages, if npgs != umem->npgs and
npgs >= 0, the function xdp_umem_unpin_pages is called. In this
function, kfree is called to handle umem->pgs, and then in the
function xdp_umem_pin_pages, kfree is called again to handle
umem->pgs. Eventually, to umem->pgs, kfree is called twice.
Since umem->pgs is set to NULL after the first kfree, the second
kfree would not trigger call trace.
Fixes: c0c77d8fb787 ("xsk: add user memory registration support sockopt")
CC: Ye Dong <dong.ye@intel.com>
Acked-by: Björn Töpel <bjorn.topel@intel.com>
Signed-off-by: Zhu Yanjun <yanjun.zhu@intel.com>
---
net/xdp/xdp_umem.c | 17 +++++------------
1 file changed, 5 insertions(+), 12 deletions(-)
diff --git a/net/xdp/xdp_umem.c b/net/xdp/xdp_umem.c
index 56a28a686988..01b31c56cead 100644
--- a/net/xdp/xdp_umem.c
+++ b/net/xdp/xdp_umem.c
@@ -97,7 +97,6 @@ static int xdp_umem_pin_pages(struct xdp_umem *umem, unsigned long address)
{
unsigned int gup_flags = FOLL_WRITE;
long npgs;
- int err;
umem->pgs = kcalloc(umem->npgs, sizeof(*umem->pgs),
GFP_KERNEL | __GFP_NOWARN);
@@ -112,20 +111,14 @@ static int xdp_umem_pin_pages(struct xdp_umem *umem, unsigned long address)
if (npgs != umem->npgs) {
if (npgs >= 0) {
umem->npgs = npgs;
- err = -ENOMEM;
- goto out_pin;
+ xdp_umem_unpin_pages(umem);
+ return -ENOMEM;
}
- err = npgs;
- goto out_pgs;
+ kfree(umem->pgs);
+ umem->pgs = NULL;
+ return (int)npgs;
}
return 0;
-
-out_pin:
- xdp_umem_unpin_pages(umem);
-out_pgs:
- kfree(umem->pgs);
- umem->pgs = NULL;
- return err;
}
static int xdp_umem_account_pages(struct xdp_umem *umem)
--
2.18.4
next reply other threads:[~2020-12-10 7:03 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-11 4:26 Zhu Yanjun [this message]
2020-12-10 23:11 ` [PATCH v3 1/1] xdp: avoid calling kfree twice Daniel Borkmann
2020-12-12 5:36 ` Rain River
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=20201211042610.71081-1-yanjun.zhu@intel.com \
--to=yanjun.zhu@intel.com \
--cc=bjorn.topel@intel.com \
--cc=dong.ye@intel.com \
--cc=jonathan.lemon@gmail.com \
--cc=magnus.karlsson@intel.com \
--cc=netdev@vger.kernel.org \
--cc=zyjzyj2000@gmail.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;
as well as URLs for NNTP newsgroup(s).