Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3782570ybl; Mon, 27 Jan 2020 10:18:32 -0800 (PST) X-Google-Smtp-Source: APXvYqxLmDXn1OsloashntBKJu++Ycj49z1a8877piKw2scSt/RkNRNotmHq6P7mI7YI704yzs+J X-Received: by 2002:a05:6830:2099:: with SMTP id y25mr12858176otq.87.1580149112118; Mon, 27 Jan 2020 10:18:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580149112; cv=none; d=google.com; s=arc-20160816; b=E0QX+iI5YErxD0d1g2J9jkgdToFrOI+2T0D5Bs63s/4tiwHaK+XhdUH2TUAdJeGeFL +Nch3pCnwsRUbLTSc2g39FT/a2ZYljUwK9GIE/Dv34GpAmB3QaP9WklMGmcN2VPUcWBR zqmd4SvKhXCCIgPdrMdnjwNWZveIk9LXZOXUWjFo/ss6xULHyeszqHyJV821V3DPnNeK taAId6+KC2P/fuVnaFJXyWjpsd883t+rTd7QxDIdsJFjLxAPyBOWC+Lv19BuTF5TTCho cPV6U1m2kD/GGBg68QdB9gwxFdvKYoL/f44OkDO+UgJ8fMtVzrNJ0BQJaJkFhV/kEJpe T9kw== 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:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=17hofFYQTtjNbqjxyYvhl99eulnsmz9UAg3bHRKU70c=; b=NHMrvdV3Tf3yhoKJJEWGrtEi+EkIf7sMG6UqXTMQwowjemKoFQmsVb9aCNYMSVR9O5 ZyaJOWdd+dX2/t/f+PlbRQLMNK6O/nGx99BX6yNqjhvxlF/l75+Onlfe+YB+/XAtPuR3 paz6oW7kto3GQfLf2vT8VSeo/UwAiVu+Zx/ZbTr2OhDDlk4tP32izJFlVleiBJiuQovz jCrjV62MsSZEXRQHJ3IRtqdRtoCT5evLFIxoZFugMTUz/Uz7MOGyIayRRLQ4crNkC3zg uQ4QLA8XlG8MAj+2umK1J4SW8rZMWL+QtOBZcLtLNEjrUeBtr8vcowTnPk6L5YNGUZa9 8USg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@nbd.name header.s=20160729 header.b=Uhw4JOGz; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x12si1667664oto.194.2020.01.27.10.18.08; Mon, 27 Jan 2020 10:18:32 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@nbd.name header.s=20160729 header.b=Uhw4JOGz; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726922AbgA0SR6 (ORCPT + 99 others); Mon, 27 Jan 2020 13:17:58 -0500 Received: from nbd.name ([46.4.11.11]:48208 "EHLO nbd.name" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726921AbgA0SR5 (ORCPT ); Mon, 27 Jan 2020 13:17:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nbd.name; s=20160729; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=17hofFYQTtjNbqjxyYvhl99eulnsmz9UAg3bHRKU70c=; b=Uhw4JOGzeScetpkUexfLaw3kAF uVBwFOZGjqfFjKwhyyfcjvFNKWKuZTkLy11Ga1HSs+HNQGSSkuXQRpSa5HArvwRHnVSTC9WO3toFx 4atVy1Ry5ckAvID63tbqJMT4cCBiARf+kZu/gWEW9qXr3NGtO4LF94pctw+yga0le8AU=; Received: from [178.162.209.132] (helo=maeck.local) by ds12 with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iw8xP-0007dc-K4 for linux-wireless@vger.kernel.org; Mon, 27 Jan 2020 19:17:55 +0100 Received: by maeck.local (Postfix, from userid 501) id 207D17A566E4; Mon, 27 Jan 2020 19:17:54 +0100 (CET) From: Felix Fietkau To: linux-wireless@vger.kernel.org Subject: [PATCH 2/5] mt76: fix handling full tx queues in mt76_dma_tx_queue_skb_raw Date: Mon, 27 Jan 2020 19:17:51 +0100 Message-Id: <20200127181754.2810-2-nbd@nbd.name> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200127181754.2810-1-nbd@nbd.name> References: <20200127181754.2810-1-nbd@nbd.name> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Fixes a theoretical issue where it could potentially overwrite an existing descriptor entry (and leaking its skb) Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/dma.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/dma.c b/drivers/net/wireless/mediatek/mt76/dma.c index e69329feed78..bcb11bb9aeeb 100644 --- a/drivers/net/wireless/mediatek/mt76/dma.c +++ b/drivers/net/wireless/mediatek/mt76/dma.c @@ -271,10 +271,13 @@ mt76_dma_tx_queue_skb_raw(struct mt76_dev *dev, enum mt76_txq_id qid, struct mt76_queue_buf buf; dma_addr_t addr; + if (q->queued + 1 >= q->ndesc - 1) + goto error; + addr = dma_map_single(dev->dev, skb->data, skb->len, DMA_TO_DEVICE); if (unlikely(dma_mapping_error(dev->dev, addr))) - return -ENOMEM; + goto error; buf.addr = addr; buf.len = skb->len; @@ -285,6 +288,10 @@ mt76_dma_tx_queue_skb_raw(struct mt76_dev *dev, enum mt76_txq_id qid, spin_unlock_bh(&q->lock); return 0; + +error: + dev_kfree_skb(skb); + return -ENOMEM; } static int -- 2.24.0