]> git.baikalelectronics.ru Git - kernel.git/commit
skbuff: Fix a potential race while recycling page_pool packets
authorIlias Apalodimas <ilias.apalodimas@linaro.org>
Fri, 16 Jul 2021 07:02:18 +0000 (10:02 +0300)
committerDavid S. Miller <davem@davemloft.net>
Fri, 16 Jul 2021 18:37:00 +0000 (11:37 -0700)
commita6169ba76c009db6c1aa411d3a615b89f06e1a56
tree2f8486b71126e60458c257fd72c0561a8e68b8e6
parentfb8a5b2d303dc3627403787c2bda59a56d521634
skbuff: Fix a potential race while recycling page_pool packets

As Alexander points out, when we are trying to recycle a cloned/expanded
SKB we might trigger a race.  The recycling code relies on the
pp_recycle bit to trigger,  which we carry over to cloned SKBs.
If that cloned SKB gets expanded or if we get references to the frags,
call skb_release_data() and overwrite skb->head, we are creating separate
instances accessing the same page frags.  Since the skb_release_data()
will first try to recycle the frags,  there's a potential race between
the original and cloned SKB, since both will have the pp_recycle bit set.

Fix this by explicitly those SKBs not recyclable.
The atomic_sub_return effectively limits us to a single release case,
and when we are calling skb_release_data we are also releasing the
option to perform the recycling, or releasing the pages from the page pool.

Fixes: 6ed271e54c26 ("page_pool: Allow drivers to hint on SKB recycling")
Reported-by: Alexander Duyck <alexanderduyck@fb.com>
Suggested-by: Alexander Duyck <alexanderduyck@fb.com>
Reviewed-by: Alexander Duyck <alexanderduyck@fb.com>
Acked-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/core/skbuff.c