Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp2991612ybi; Thu, 4 Jul 2019 23:49:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqyUMO3wyzGZrUxD18izryOcpm7LVDZSxCJgEDr5mgjcfnM0nCfVfxNZB2AF1PczYNknT85Z X-Received: by 2002:a63:c84d:: with SMTP id l13mr3252145pgi.154.1562309375705; Thu, 04 Jul 2019 23:49:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562309375; cv=none; d=google.com; s=arc-20160816; b=xNmsa17UUtfOeG+IoBbysMAdnAKbu0nRFzc2BJxPE7l+rf4Wa0SeQ12SLJLYnPoOSI c65VqlzjKf7ez2GeYrPoQrSvSquU+xfKbpV0LhaxevVvghIYaaymPWzjlKWNBv+SxTJV V1wTWIAoViMPcOXJb7+LE4iUJqmspi2yrQKCcLPClHkntapey7bhIL14VGeyu5CUp6Ks XDrkLzhGPfNIyUvhKj3I+AVRSbH6IrDpMo8qM7rcybqggd11/ENcgFZa3QTFtcRfCUF5 CHQA5t4pBZOrw1qlWVTA3mobJDW0QlFjGpPRqjAk44pg75ldroAq2Pdcnlhv5TeghkAw yHMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=swKFyl1Mf/5O9xSZN9816MAkarsTElOMsmp/B3xHLTU=; b=foWMUzSXM9kYC5YCPIFbbUaXQfhYoz5lq1z8jcFnsjRjWm8BHC9VW3ChkqNzgkSkiL YfIidjm6ZcwbgyiODBCI549Vz2/OhBWP40Ok5FGgwlzGDRAn9ZYOh0/hkIert0PK0u9x NSX6F+3B0ufQowhimQ0ClktXf7O9aUdRTvnAuVKP3hufbdE5IN3sswkT6pddIk4NaIU+ iG7cPc7RsQVQvpPyVVVGYbEqSi7oiEuAEa5TO+2840q6Ylj3mWAUm6n6AvgwgSPAZKYv 1zMq60l9PQo+ivbkwwsygs6uH86e9S8t2pzXa8q1niHrLvsH41YUbmlULbMPRXo7oDP3 123Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=OixdgawK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u190si6067877pgu.61.2019.07.04.23.49.20; Thu, 04 Jul 2019 23:49:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=OixdgawK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727654AbfGEGnJ (ORCPT + 99 others); Fri, 5 Jul 2019 02:43:09 -0400 Received: from mail-qt1-f196.google.com ([209.85.160.196]:43966 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725894AbfGEGnJ (ORCPT ); Fri, 5 Jul 2019 02:43:09 -0400 Received: by mail-qt1-f196.google.com with SMTP id w17so7020002qto.10; Thu, 04 Jul 2019 23:43:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=swKFyl1Mf/5O9xSZN9816MAkarsTElOMsmp/B3xHLTU=; b=OixdgawKakxbcPW/B3nm7ThpZyyj4849Rnwe/iKe6lB80wLa40HwpnUrxCsRGl6Ash zcAcLIFNx7/BKKBMLaBVHcGSpM2x2ftivGOyJl8vvpcGbngHirGf1eWGWYbL+SkxJmDR Zoj4XxGzsMMgIdCC7WGMK6n8L/M8Yq+M03WJSwBBFFSrF/jL3a8Kig33BOLn2SHCTqEk eTr8QpBIAZwVL8l6BqLS28vZROqCwMWvinF17JRj0NymczehVXtSfgE2WuGHf1GXHVKW IZzhF852T3dmqYyFaJ0quAlSnkLn9O4vgD6mCGwSQ3zakPkASfGmJh4bRiZvh7SHB2+u FV9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=swKFyl1Mf/5O9xSZN9816MAkarsTElOMsmp/B3xHLTU=; b=a+AGc+dBvT6HFt8ib7E39dhO+qxye9yglDbFuDCBmDt2LOJ0rw/3AJmWm2m4JG/Uqr X7PbfxEiwdUwUQ2pzDsNB06pASxkgpkr2tTHcJcFH65n/yB1cX/+5fMEet+pdm7KnyZG sqbSA54yk0vwTYK83daDmkAGRtS/b8rv2H2NxsB6HAR+URHyvNaM+tgIcELDYtWMriNy mRTYs1GjKVAty1NuZLLJYW+A9PkPMKMoO7xBhwh2iYVk48NXQ4N2ZymVT7+G0mbMi4Hz BlNhrPnHwp9H2dTQw0rwLSJGWtTXmWBbj3il6BSrG6SG7ciylaDlCpTil8jo1GIVDC/F vUuw== X-Gm-Message-State: APjAAAWsLCDQd9+E9XyGrwTKspJ6CQYGE03DxGTb0h2Z0tU7M0B8V67E 59u80GR6OVM5JVt5n3d/N4m9x93p2v4yEAxpSnOYjZGr4vg= X-Received: by 2002:ac8:4442:: with SMTP id m2mr1375964qtn.107.1562308987980; Thu, 04 Jul 2019 23:43:07 -0700 (PDT) MIME-Version: 1.0 References: <20190704142503.23501-1-i.maximets@samsung.com> In-Reply-To: <20190704142503.23501-1-i.maximets@samsung.com> From: =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= Date: Fri, 5 Jul 2019 08:42:56 +0200 Message-ID: Subject: Re: [PATCH bpf] xdp: fix possible cq entry leak To: Ilya Maximets Cc: Netdev , LKML , bpf , Xdp , "David S. Miller" , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Magnus Karlsson , Jonathan Lemon , Jakub Kicinski , Alexei Starovoitov , Daniel Borkmann Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 4 Jul 2019 at 16:25, 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. > Good catch, Ilya! Thanks for the patch! Acked-by: Bj=C3=B6rn T=C3=B6pel > Fixes: 35fcde7f8deb ("xsk: support for Tx") > Signed-off-by: Ilya Maximets > --- > 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 m= sghdr *m, > > mutex_lock(&xs->mutex); > > + if (xs->queue_id >=3D 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 >=3D xs->dev->real_num_tx_queues) > - goto out; > - > len =3D desc.len; > skb =3D sock_alloc_send_skb(sk, len, 1, &err); > if (unlikely(!skb)) { > @@ -253,7 +250,7 @@ static int xsk_generic_xmit(struct sock *sk, struct m= sghdr *m, > addr =3D desc.addr; > buffer =3D xdp_umem_get_data(xs->umem, addr); > err =3D 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 >