net: drop skbs in napi->rx_list when removing the napi context.
Subsystems (3)
PATCH 1/1 net: drop skbs in napi->rx_list when removing the napi context.
The napi->rx_list is used to hold the GRO_NORMAL skbs before passing them to the stack, these skbs only passed to stack at the flush time or when the list's weight matches the predefined condition. In case the rx_list contains pending skbs when we remove the napi context, we need to clean out this list, otherwise, a memory leak will happen.
--- net/core/dev.c | 7 +++++++ 1 file changed, 7 insertions(+)
net/core/dev.c +7 -0
@@ -7038,6 +7038,13 @@ void __netif_napi_del(struct napi_struct *napi)list_del_rcu (&napi->dev_list);napi_free_frags (napi); +if (napi->rx_count) { +struct sk_buff *skb, *n; + +list_for_each_entry_safe (skb, n, &napi->rx_list, list) +kfree_skb (skb); + } +flush_gro_hash (napi); napi->gro_bitmask =0 ;
--
2.25.1
Quoted 6 lines · On Thu, 12 Aug 2021 07:59:59 +0800 Nguyen Dinh Phi wrote:
The
napi->rx_listis used to hold theGRO_NORMALskbs before passing them to the stack, these skbs only passed to stack at the flush time or when the list's weight matches the predefined condition. In case therx_listcontains pending skbs when we remove the napi context, we need to clean out this list, otherwise, a memory leak will happen.
Thanks for your fix.
#syz test git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
--- net/core/dev.c | 7 +++++++ 1 file changed, 7 insertions(+)
net/core/dev.c +7 -0
@@ -7038,6 +7038,13 @@ void __netif_napi_del(struct napi_struct *napi)list_del_rcu (&napi->dev_list);napi_free_frags (napi); +if (napi->rx_count) { +struct sk_buff *skb, *n; + +list_for_each_entry_safe (skb, n, &napi->rx_list, list) +kfree_skb (skb); + } +flush_gro_hash (napi); napi->gro_bitmask =0 ;
--
2.25.1
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
syzbot
syzbotRe: [syzbot] memory leak in packet_sendmsg
syzbot tried to test the proposed patch but the build/boot failed:
Hello,
syzbot tried to test the proposed patch but the build/boot failed:
failed to apply patch:
checking file net/core/dev.c
patch: **** unexpected end of file in patch
Tested on:
commit: 761c6d7e Merge tag 'arc-5.14-rc6' of git://git.kernel... git tree: upstream dashboard link: https://syzkaller.appspot.com/bug?extid=989efe781c74de1ddb54
compiler:
patch: https://syzkaller.appspot.com/x/patch.diff?x=147a5779300000
Quoted 9 lines · Nguyen Dinh Phi
The
napi->rx_listis used to hold theGRO_NORMALskbs before passing them to the stack, these skbs only passed to stack at the flush time or when the list's weight matches the predefined condition. In case therx_listcontains pending skbs when we remove the napi context, we need to clean out this list, otherwise, a memory leak will happen.Signed-off-by Nguyen Dinh Phi <[email protected]>Reported-by [email protected]
Thank you for working on this.
Please add a Fixes: tag, otherwise you are asking maintainers and stable teams to find the original bug,
while you are in a much better position, since you spent time on fixing the issue.
Also I object to this fix.
If packets have been stored temporarily in GRO, they should be released at some point,
normally at the end of a napi poll.
By released, I mean that these packets should reach the upper stack, instead of being dropped without
any notification.
It seems a call to gro_normal_list() is missing somewhere.
Can you find where ?
Thanks !
Quoted 25 lines
--- net/core/dev.c | 7 +++++++ 1 file changed, 7 insertions(+)net/core/dev.c +7
-1@@ -7038,6 +7038,13 @@ void __netif_napi_del(struct napi_struct *napi)list_del_rcu (&napi->dev_list);napi_free_frags (napi); +if (napi->rx_count) { +struct sk_buff *skb, *n; + +list_for_each_entry_safe (skb, n, &napi->rx_list, list) +kfree_skb (skb); + } +flush_gro_hash (napi); napi->gro_bitmask =0 ; --2.25.1
Quoted 10 lines · Eric Dumazet
Also I object to this fix.
If packets have been stored temporarily in GRO, they should be released at some point,
normally at the end of a napi poll.By released, I mean that these packets should reach the upper stack, instead of being dropped without
any notification.
Quoted 6 lines
It seems a call to
gro_normal_list()is missing somewhere.Can you find where ?
Thanks !
H Eric,
I think the location that should have a call to gro_normal_list() is __netif_napi_del(). Let say, if the driver call a function that lead to gro_normal_one(), and add a skb to the rx_list while the napi poll is not scheduled, and the driver remove the napi context before a napi poll could be triggered, then the added skb will be lost.
Actually, this was the first solution that I tried with syzbot (It passed the test too). Best regards,
Phi
_______________________________________________
Linux-kernel-mentees mailing list [email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
Quoted 15 lines · Phi Nguyen
Quoted 14 lines · Eric Dumazet
Also I object to this fix.
If packets have been stored temporarily in GRO, they should be released at some point,
normally at the end of a napi poll.By released, I mean that these packets should reach the upper stack, instead of being dropped without
any notification.It seems a call to
gro_normal_list()is missing somewhere.Can you find where ?
Quoted 8 lines
Quoted 2 lines
Thanks !
H Eric,I think the location that should have a call to
gro_normal_list()is__netif_napi_del(). Let say, if the driver call a function that lead togro_normal_one(), and add a skb to therx_listwhile the napi poll is not scheduled, and the driver remove the napi context before a napi poll could be triggered, then the added skb will be lost.Actually, this was the first solution that I tried with syzbot (It passed the test too). Best regards,
Phi
I think the real bug is in drivers/net/tun.c
It can call napi_gro_frags() and I do not see corresponding napi_complete()
This seems completely bogus.
Your patch only works around one the many bugs caused by
commit 90e33d45940793def6f773b2d528e9f3c84ffdc7 tun: enable napi_gro_frags() for TUN/TAP driver
I suggest not adding your patch, because we should fix the root cause.
Quoted 37 lines · Eric Dumazet
Quoted 11 lines · Phi Nguyen
Quoted 10 lines · Eric Dumazet
Also I object to this fix.
If packets have been stored temporarily in GRO, they should be released at some point,
normally at the end of a napi poll.By released, I mean that these packets should reach the upper stack, instead of being dropped without
any notification.Quoted 8 lines
Quoted 6 lines
It seems a call to
gro_normal_list()is missing somewhere.Can you find where ?
Thanks !
H Eric,I think the location that should have a call to
gro_normal_list()is
__netif_napi_del(). Let say, if the driver call a function that lead togro_normal_one(), and add a skb to therx_listwhile the napi poll is not scheduled, and the driver remove the napi context before a napi poll could be triggered, then the added skb will be lost.Quoted 2 lines
Actually, this was the first solution that I tried with syzbot (It
passed the test too).
Quoted 2 lines
Best regards,
PhiI think the real bug is in
drivers/net/tun.cIt can call
napi_gro_frags()and I do not see correspondingnapi_complete()
Quoted 7 lines
This seems completely bogus.
Your patch only works around one the many bugs caused by commit
90e33d45940793def6f773b2d528e9f3c84ffdc7tun: enablenapi_gro_frags()for TUN/TAP driverI suggest not adding your patch, because we should fix the root cause.
Yes, it truely comes from tun driver. But it was there before listified RX added (that time the skb will be put to stack immediately), that why I made the fix in dev.c. I thought I should change the later commit.