Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp2262374ybi; Thu, 4 Jul 2019 07:46:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqwFfTe23UoRnw8oBj9drzOWsJhXuUZ/DV3ceUBwIfp4KB4fFZOY59Epn5YFr2jl8s97ABqv X-Received: by 2002:a63:fe51:: with SMTP id x17mr45998770pgj.61.1562251605717; Thu, 04 Jul 2019 07:46:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562251605; cv=none; d=google.com; s=arc-20160816; b=kJeEtu4YFJT8WG95QB+LMCQGNjO4T98AMkDwagClKYtTUMfm3H58aDcXzE8tnsvmyN 1/PSATRJHp5CAyWsxZI8E5HhJGF7DaYxuAm+OT3AHQbgXT8pP6AFH5EsTOGh5R0VCJ/W w8mUQCIZ23jsoFe/cBMgU+RWCWiuJDMdJ1QR+GMJOtgrC9fULwzAZtYQYlSAcbpyMMet Ecpu+clAAUoGovxtLfCgh64o32Qds61tChA6v6ympadKfM2AKMP8Om69Lmi8S1h+IgF0 znRzL3rCi9Q+KYkrA/bLhWauwI2c/V/QkoUbPt8QH7Q+SY5IrxQTIcRa1WGbrKIepe+l Bxnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:cms-type:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=nDTQvMV2GmtMsbQlwO3htPXTdx4GYhmbGKKFfHVI23s=; b=SNGYJlf67EgTmmH8f71tTL9Wcei9hH1bklunnKRi8AgelHWomV4iLd6AD6qLebSZym JBxZ2QC+Eha2BSB8eHXl0KETmIrSmQPU+Hby00XMrE6mtw8Kbm0p8v+WlRYpmLMTTQS3 ep9U0bp/2qbMchGR609JHC364Ew1/WyrDLH/WkCIEf6hr2a5feZJwVpyMwxJVRcyeXgX uAbFvpikiS7pGKGwGJmzAbF4QJMh8HvyCxCHd/enZkNGRScKzCrPRy54GyxPokbr/NJC 3Sql7PUsQamCYK5/TBhBrsoCorQtmzO8Rbb6oeQ9K8eHjK18Jl805DP8o8UIiKBW39iN kgIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=sYlNM2pL; 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=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r145si4426604pgr.553.2019.07.04.07.46.30; Thu, 04 Jul 2019 07:46:45 -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=@samsung.com header.s=mail20170921 header.b=sYlNM2pL; 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=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727651AbfGDOZP (ORCPT + 99 others); Thu, 4 Jul 2019 10:25:15 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:35354 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727585AbfGDOZN (ORCPT ); Thu, 4 Jul 2019 10:25:13 -0400 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20190704142511euoutp01c27a2ec1c204afff1038a0bf4af29616~uOmGO92PM1948519485euoutp01j for ; Thu, 4 Jul 2019 14:25:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20190704142511euoutp01c27a2ec1c204afff1038a0bf4af29616~uOmGO92PM1948519485euoutp01j DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1562250311; bh=nDTQvMV2GmtMsbQlwO3htPXTdx4GYhmbGKKFfHVI23s=; h=From:To:Cc:Subject:Date:References:From; b=sYlNM2pLc06yhX4J6R+wYpLvvxtwDi8XUPJR8xeNqRVxyhb0P8pSWuxOmV6YAU9NR avQM52l3jlCqIr/HfhHeJIkGLF2ICeAL640pfRnWtbkabgYKMSKwgmrPFq7d7pvhQ3 D2mkM/Y1ePil3BZLjJ0cgVxvHETqleUoI9eYH6kc= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20190704142510eucas1p27fcc968426a7dd34b0efc6160ebb1735~uOmFhsDX_2603626036eucas1p28; Thu, 4 Jul 2019 14:25:10 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 0F.84.04325.64C0E1D5; Thu, 4 Jul 2019 15:25:10 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20190704142509eucas1p268eb9ca87bcc0bffb60891f88f3f6642~uOmEt01Ot1504615046eucas1p2b; Thu, 4 Jul 2019 14:25:09 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20190704142509eusmtrp2a4468529258676ae900bdac389d2dafb~uOmEfOG0p0491504915eusmtrp2Y; Thu, 4 Jul 2019 14:25:09 +0000 (GMT) X-AuditID: cbfec7f5-b8fff700000010e5-5f-5d1e0c4642f7 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 7D.77.04146.54C0E1D5; Thu, 4 Jul 2019 15:25:09 +0100 (BST) Received: from imaximets.rnd.samsung.ru (unknown [106.109.129.180]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20190704142508eusmtip25289fa98246e93382b2ca1d5375d1111~uOmDvNU--1740317403eusmtip2Q; Thu, 4 Jul 2019 14:25:08 +0000 (GMT) From: Ilya Maximets To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, bpf@vger.kernel.org, xdp-newbies@vger.kernel.org, "David S. Miller" , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Magnus Karlsson , Jonathan Lemon , Jakub Kicinski , Alexei Starovoitov , Daniel Borkmann , Ilya Maximets Subject: [PATCH bpf] xdp: fix possible cq entry leak Date: Thu, 4 Jul 2019 17:25:03 +0300 Message-Id: <20190704142503.23501-1-i.maximets@samsung.com> X-Mailer: git-send-email 2.17.1 X-Brightmail-Tracker: H4sIAAAAAAAAA0VSbUhTYRjt3b279zqc3Kboi8mCUZSWWtSPC1oZVFwowb8ZI69520Q3dVPT gjK/m2UWljqGGRbqZn6Moc5MdOpmGlbLbNPCkj7U6HOWLUVz3kn/znPOc855fjwEIrrFDyaS lZmsSsmkSjAB2mF1j4Uf8xVL95iag6gF9xROLRe3Aco1aMOo+ru/EUr3tBClxkvcOGWdLcSo 7pYahHrRrcOoRsvwGlcXSHVe7wUxvrSpycmjzdo3OF3fM8ejNQ47Qhv1VzC6quwdQpeb9IB2 GcVxRLwgOolNTc5mVZEHEwTy29+N/PRp35wPulaQB6oFGuBDQHI/dOWZMQ0QECKyEcBFhxXn hgUASzSjXsUFYEX+R2TD0tTjQDmhAUDz5DyfG/4AaP17FfNsYeRuOGIYBB4cQAbDH12d67kI 2YfAh7ba9Sj/tagJgxn3YJTcDi9fu8/TAIIQklGwvQjl2rZCQ1sf4vFCsgyHz5wPvGccgZ8q R/kc9ofzNhPO4RC4ar7D4/AlOF04BzhzKYBVlhWvcAiaPo/hnjKEDIWt3ZEcfRjW3NMhHhqS ftDxZbOHRtbgzY4qLy2EpcUibnsbXOpv8F4TDJ1fXd4LaFjXbFxfF5FSWFAUXgHE2v9VdQDo QRCb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xe+uclN0B1PNUqG0b4mtud+vFBYXHLkwzXnqx91r5S1FKstO5ByN W/JsqXxIvWvhfPMJRrGWEkrfpIL53k1QUmIpzkg01GIuKk4EAHfN9OJ/AgAA X-CMS-MailID: 20190704142509eucas1p268eb9ca87bcc0bffb60891f88f3f6642 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20190704142509eucas1p268eb9ca87bcc0bffb60891f88f3f6642 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20190704142509eucas1p268eb9ca87bcc0bffb60891f88f3f6642 References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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