bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf] xdp: fix possible cq entry leak
       [not found] <CGME20190704142509eucas1p268eb9ca87bcc0bffb60891f88f3f6642@eucas1p2.samsung.com>
@ 2019-07-04 14:25 ` Ilya Maximets
  2019-07-05  6:42   ` Björn Töpel
  2019-07-12 13:07   ` Daniel Borkmann
  0 siblings, 2 replies; 4+ messages in thread
From: Ilya Maximets @ 2019-07-04 14:25 UTC (permalink / raw)
  To: netdev
  Cc: linux-kernel, bpf, xdp-newbies, David S. Miller,
	Björn Töpel, Magnus Karlsson, Jonathan Lemon,
	Jakub Kicinski, Alexei Starovoitov, Daniel Borkmann,
	Ilya Maximets

Completion queue address reservation could not be undone.
In case of bad 'queue_id' or skb allocation failure, reserved entry
will be leaked reducing the total capacity of completion queue.

Fix that by moving reservation to the point where failure is not
possible. Additionally, 'queue_id' checking moved out from the loop
since there is no point to check it there.

Fixes: 35fcde7f8deb ("xsk: support for Tx")
Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
---
 net/xdp/xsk.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
index f53a6ef7c155..703cf5ea448b 100644
--- a/net/xdp/xsk.c
+++ b/net/xdp/xsk.c
@@ -226,6 +226,9 @@ static int xsk_generic_xmit(struct sock *sk, struct msghdr *m,
 
 	mutex_lock(&xs->mutex);
 
+	if (xs->queue_id >= xs->dev->real_num_tx_queues)
+		goto out;
+
 	while (xskq_peek_desc(xs->tx, &desc)) {
 		char *buffer;
 		u64 addr;
@@ -236,12 +239,6 @@ static int xsk_generic_xmit(struct sock *sk, struct msghdr *m,
 			goto out;
 		}
 
-		if (xskq_reserve_addr(xs->umem->cq))
-			goto out;
-
-		if (xs->queue_id >= xs->dev->real_num_tx_queues)
-			goto out;
-
 		len = desc.len;
 		skb = sock_alloc_send_skb(sk, len, 1, &err);
 		if (unlikely(!skb)) {
@@ -253,7 +250,7 @@ static int xsk_generic_xmit(struct sock *sk, struct msghdr *m,
 		addr = desc.addr;
 		buffer = xdp_umem_get_data(xs->umem, addr);
 		err = skb_store_bits(skb, 0, buffer, len);
-		if (unlikely(err)) {
+		if (unlikely(err) || xskq_reserve_addr(xs->umem->cq)) {
 			kfree_skb(skb);
 			goto out;
 		}
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf] xdp: fix possible cq entry leak
  2019-07-04 14:25 ` [PATCH bpf] xdp: fix possible cq entry leak Ilya Maximets
@ 2019-07-05  6:42   ` Björn Töpel
  2019-07-08 21:25     ` William Tu
  2019-07-12 13:07   ` Daniel Borkmann
  1 sibling, 1 reply; 4+ messages in thread
From: Björn Töpel @ 2019-07-05  6:42 UTC (permalink / raw)
  To: Ilya Maximets
  Cc: Netdev, LKML, bpf, Xdp, David S. Miller, Björn Töpel,
	Magnus Karlsson, Jonathan Lemon, Jakub Kicinski,
	Alexei Starovoitov, Daniel Borkmann

On Thu, 4 Jul 2019 at 16:25, Ilya Maximets <i.maximets@samsung.com> wrote:
>
> Completion queue address reservation could not be undone.
> In case of bad 'queue_id' or skb allocation failure, reserved entry
> will be leaked reducing the total capacity of completion queue.
>
> Fix that by moving reservation to the point where failure is not
> possible. Additionally, 'queue_id' checking moved out from the loop
> since there is no point to check it there.
>

Good catch, Ilya! Thanks for the patch!

Acked-by: Björn Töpel <bjorn.topel@intel.com>

> Fixes: 35fcde7f8deb ("xsk: support for Tx")
> Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
> ---
>  net/xdp/xsk.c | 11 ++++-------
>  1 file changed, 4 insertions(+), 7 deletions(-)
>
> diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
> index f53a6ef7c155..703cf5ea448b 100644
> --- a/net/xdp/xsk.c
> +++ b/net/xdp/xsk.c
> @@ -226,6 +226,9 @@ static int xsk_generic_xmit(struct sock *sk, struct msghdr *m,
>
>         mutex_lock(&xs->mutex);
>
> +       if (xs->queue_id >= xs->dev->real_num_tx_queues)
> +               goto out;
> +
>         while (xskq_peek_desc(xs->tx, &desc)) {
>                 char *buffer;
>                 u64 addr;
> @@ -236,12 +239,6 @@ static int xsk_generic_xmit(struct sock *sk, struct msghdr *m,
>                         goto out;
>                 }
>
> -               if (xskq_reserve_addr(xs->umem->cq))
> -                       goto out;
> -
> -               if (xs->queue_id >= xs->dev->real_num_tx_queues)
> -                       goto out;
> -
>                 len = desc.len;
>                 skb = sock_alloc_send_skb(sk, len, 1, &err);
>                 if (unlikely(!skb)) {
> @@ -253,7 +250,7 @@ static int xsk_generic_xmit(struct sock *sk, struct msghdr *m,
>                 addr = desc.addr;
>                 buffer = xdp_umem_get_data(xs->umem, addr);
>                 err = skb_store_bits(skb, 0, buffer, len);
> -               if (unlikely(err)) {
> +               if (unlikely(err) || xskq_reserve_addr(xs->umem->cq)) {
>                         kfree_skb(skb);
>                         goto out;
>                 }
> --
> 2.17.1
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf] xdp: fix possible cq entry leak
  2019-07-05  6:42   ` Björn Töpel
@ 2019-07-08 21:25     ` William Tu
  0 siblings, 0 replies; 4+ messages in thread
From: William Tu @ 2019-07-08 21:25 UTC (permalink / raw)
  To: Björn Töpel
  Cc: Ilya Maximets, Netdev, LKML, bpf, Xdp, David S. Miller,
	Björn Töpel, Magnus Karlsson, Jonathan Lemon,
	Jakub Kicinski, Alexei Starovoitov, Daniel Borkmann

On Thu, Jul 4, 2019 at 11:49 PM Björn Töpel <bjorn.topel@gmail.com> wrote:
>
> On Thu, 4 Jul 2019 at 16:25, Ilya Maximets <i.maximets@samsung.com> wrote:
> >
> > Completion queue address reservation could not be undone.
> > In case of bad 'queue_id' or skb allocation failure, reserved entry
> > will be leaked reducing the total capacity of completion queue.
> >
> > Fix that by moving reservation to the point where failure is not
> > possible. Additionally, 'queue_id' checking moved out from the loop
> > since there is no point to check it there.
> >
>
> Good catch, Ilya! Thanks for the patch!
>
> Acked-by: Björn Töpel <bjorn.topel@intel.com>
>
Thanks
Tested-by: William Tu <u9012063@gmail.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf] xdp: fix possible cq entry leak
  2019-07-04 14:25 ` [PATCH bpf] xdp: fix possible cq entry leak Ilya Maximets
  2019-07-05  6:42   ` Björn Töpel
@ 2019-07-12 13:07   ` Daniel Borkmann
  1 sibling, 0 replies; 4+ messages in thread
From: Daniel Borkmann @ 2019-07-12 13:07 UTC (permalink / raw)
  To: Ilya Maximets, netdev
  Cc: linux-kernel, bpf, xdp-newbies, David S. Miller,
	Björn Töpel, Magnus Karlsson, Jonathan Lemon,
	Jakub Kicinski, Alexei Starovoitov

On 07/04/2019 04:25 PM, Ilya Maximets wrote:
> Completion queue address reservation could not be undone.
> In case of bad 'queue_id' or skb allocation failure, reserved entry
> will be leaked reducing the total capacity of completion queue.
> 
> Fix that by moving reservation to the point where failure is not
> possible. Additionally, 'queue_id' checking moved out from the loop
> since there is no point to check it there.
> 
> Fixes: 35fcde7f8deb ("xsk: support for Tx")
> Signed-off-by: Ilya Maximets <i.maximets@samsung.com>

Applied, thanks!

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-07-12 13:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20190704142509eucas1p268eb9ca87bcc0bffb60891f88f3f6642@eucas1p2.samsung.com>
2019-07-04 14:25 ` [PATCH bpf] xdp: fix possible cq entry leak Ilya Maximets
2019-07-05  6:42   ` Björn Töpel
2019-07-08 21:25     ` William Tu
2019-07-12 13:07   ` Daniel Borkmann

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).