* [PATCH net] virtio_net: fix memory leak inside XPD_TX with mergeable
@ 2022-08-04 6:32 Xuan Zhuo
2022-08-04 7:35 ` Jason Wang
2022-08-08 8:50 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Xuan Zhuo @ 2022-08-04 6:32 UTC (permalink / raw)
To: netdev
Cc: Michael S. Tsirkin, Jason Wang, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Alexei Starovoitov, Daniel Borkmann,
Jesper Dangaard Brouer, John Fastabend, virtualization, bpf
When we call xdp_convert_buff_to_frame() to get xdpf, if it returns
NULL, we should check if xdp_page was allocated by xdp_linearize_page().
If it is newly allocated, it should be freed here alone. Just like any
other "goto err_xdp".
Fixes: 44fa2dbd4759 ("xdp: transition into using xdp_frame for ndo_xdp_xmit")
Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
---
drivers/net/virtio_net.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index ec8e1b3108c3..3b3eebad3977 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -1057,8 +1057,11 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
case XDP_TX:
stats->xdp_tx++;
xdpf = xdp_convert_buff_to_frame(&xdp);
- if (unlikely(!xdpf))
+ if (unlikely(!xdpf)) {
+ if (unlikely(xdp_page != page))
+ put_page(xdp_page);
goto err_xdp;
+ }
err = virtnet_xdp_xmit(dev, 1, &xdpf, 0);
if (unlikely(!err)) {
xdp_return_frame_rx_napi(xdpf);
--
2.31.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net] virtio_net: fix memory leak inside XPD_TX with mergeable
2022-08-04 6:32 [PATCH net] virtio_net: fix memory leak inside XPD_TX with mergeable Xuan Zhuo
@ 2022-08-04 7:35 ` Jason Wang
2022-08-08 8:50 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Jason Wang @ 2022-08-04 7:35 UTC (permalink / raw)
To: Xuan Zhuo
Cc: netdev, Michael S. Tsirkin, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Alexei Starovoitov, Daniel Borkmann,
Jesper Dangaard Brouer, John Fastabend, virtualization,
open list:XDP (eXpress Data Path)
On Thu, Aug 4, 2022 at 2:33 PM Xuan Zhuo <xuanzhuo@linux.alibaba.com> wrote:
>
> When we call xdp_convert_buff_to_frame() to get xdpf, if it returns
> NULL, we should check if xdp_page was allocated by xdp_linearize_page().
> If it is newly allocated, it should be freed here alone. Just like any
> other "goto err_xdp".
>
> Fixes: 44fa2dbd4759 ("xdp: transition into using xdp_frame for ndo_xdp_xmit")
> Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Acked-by: Jason Wang <jasowang@redhat.com>
> ---
> drivers/net/virtio_net.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index ec8e1b3108c3..3b3eebad3977 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -1057,8 +1057,11 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
> case XDP_TX:
> stats->xdp_tx++;
> xdpf = xdp_convert_buff_to_frame(&xdp);
> - if (unlikely(!xdpf))
> + if (unlikely(!xdpf)) {
> + if (unlikely(xdp_page != page))
> + put_page(xdp_page);
> goto err_xdp;
> + }
> err = virtnet_xdp_xmit(dev, 1, &xdpf, 0);
> if (unlikely(!err)) {
> xdp_return_frame_rx_napi(xdpf);
> --
> 2.31.0
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net] virtio_net: fix memory leak inside XPD_TX with mergeable
2022-08-04 6:32 [PATCH net] virtio_net: fix memory leak inside XPD_TX with mergeable Xuan Zhuo
2022-08-04 7:35 ` Jason Wang
@ 2022-08-08 8:50 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-08-08 8:50 UTC (permalink / raw)
To: Xuan Zhuo
Cc: netdev, mst, jasowang, davem, edumazet, kuba, pabeni, ast,
daniel, hawk, john.fastabend, virtualization, bpf
Hello:
This patch was applied to netdev/net.git (master)
by David S. Miller <davem@davemloft.net>:
On Thu, 4 Aug 2022 14:32:48 +0800 you wrote:
> When we call xdp_convert_buff_to_frame() to get xdpf, if it returns
> NULL, we should check if xdp_page was allocated by xdp_linearize_page().
> If it is newly allocated, it should be freed here alone. Just like any
> other "goto err_xdp".
>
> Fixes: 44fa2dbd4759 ("xdp: transition into using xdp_frame for ndo_xdp_xmit")
> Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
>
> [...]
Here is the summary with links:
- [net] virtio_net: fix memory leak inside XPD_TX with mergeable
https://git.kernel.org/netdev/net/c/7a542bee27c6
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-08-08 8:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-04 6:32 [PATCH net] virtio_net: fix memory leak inside XPD_TX with mergeable Xuan Zhuo
2022-08-04 7:35 ` Jason Wang
2022-08-08 8:50 ` patchwork-bot+netdevbpf
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).