Received: by 2002:a17:90a:9103:0:0:0:0 with SMTP id k3csp11813458pjo; Thu, 2 Jan 2020 14:44:01 -0800 (PST) X-Google-Smtp-Source: APXvYqwYoM0KWWhhx4oHHll0/Pvr3vam+hQjwWXD0hyMS7PdVqCV+R4bvRhBlArVxDlB9nOzCfv8 X-Received: by 2002:a9d:6b06:: with SMTP id g6mr85925462otp.93.1578005041778; Thu, 02 Jan 2020 14:44:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578005041; cv=none; d=google.com; s=arc-20160816; b=N19mMnGEoh6OVKexbXE4E5lWzUsNrsCEz7cgfjG4gbJw9hLqZSEya+7XVuUILzY//x omUwckvXYaXJ0VyD6lDJTH6+wGuMNPHzPNvVFrpADr7BhlzjBxHBNQV1kh4uC6kUlUIs uHXnhLtXrSM+kTi6pMyXG8LwUtV2Cc2hNm9ShDtdD4NVHt0NpFJIBLCxCkZ3vMcZLUMr REkp5vRSYCFXnbawyl9QEHEbhGwWNo9gB1JrePhlJMuhevyRNs2gnr85vUOImRcgXglf Z+lhWa6yYkk8fBWR/WEzsfkrVt5cX5Pj9/nW9jCUFVArTRgRfkuw4d7x3bGjcq9kTZZa OnPQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=pACDpn5SwA1TRCpMX0coCLX0pP1owm1QkGqewEIdm5c=; b=sFCvQefMqVE7rgJo55rsQkeTR6E/ndsiaD8YUhARgc3ScRFzPP1aZFSk1dUOS/Is/e sCm3i/0OEA/6azPnokcrq/TK6+uBdoFxoVvXyh42BAZHOTtJowFNxlmb3K5f6U5es5+8 oaQKzsKhVXcxNIvze+04Qz3TnmMVHZAd5MGQowlAwbP7DzCdLbVLdoFiz19wIbs2Wf5B Y8HQPQ4qIpYe56c8xOxng1H1hwynsaZYjVaP68HHttlb0gE6FKKOBtzmUukKbzFEGm8/ 4/MuOF6o5ceu9LBPPXwidJQO5nMEcCKfPdp1BBQ2rpLdJvIn27OioHm3n0e4E1eSmCTQ aX5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dQItHsPr; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t20si21469922oth.311.2020.01.02.14.43.49; Thu, 02 Jan 2020 14:44:01 -0800 (PST) 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=@kernel.org header.s=default header.b=dQItHsPr; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731009AbgABWgw (ORCPT + 99 others); Thu, 2 Jan 2020 17:36:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:48486 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730998AbgABWgv (ORCPT ); Thu, 2 Jan 2020 17:36:51 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 61CDC20863; Thu, 2 Jan 2020 22:36:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578004609; bh=vApgtmOsQVMPYg5aH4YmE1Ihj8QEHEKdTfmokdJklfs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dQItHsPrbxxIzre/UHwnZEtp5VrKmRTaGLpjIlo9uy7rs+JKtuN3Uwb4Bjt/LbG1w S9E7af6bqi6d/qgBornt4kmCLJthJYktSd0aA1GgfJZTKxSziLZSineey/qExhAM9P 1DV9xyST1NDPbG+ux83bHWWPOZrxZumogmklOZDE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ben Hutchings , "David S. Miller" Subject: [PATCH 4.4 078/137] net: qlogic: Fix error paths in ql_alloc_large_buffers() Date: Thu, 2 Jan 2020 23:07:31 +0100 Message-Id: <20200102220557.200215811@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102220546.618583146@linuxfoundation.org> References: <20200102220546.618583146@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ben Hutchings [ Upstream commit cad46039e4c99812db067c8ac22a864960e7acc4 ] ql_alloc_large_buffers() has the usual RX buffer allocation loop where it allocates skbs and maps them for DMA. It also treats failure as a fatal error. There are (at least) three bugs in the error paths: 1. ql_free_large_buffers() assumes that the lrg_buf[] entry for the first buffer that couldn't be allocated will have .skb == NULL. But the qla_buf[] array is not zero-initialised. 2. ql_free_large_buffers() DMA-unmaps all skbs in lrg_buf[]. This is incorrect for the last allocated skb, if DMA mapping failed. 3. Commit 1acb8f2a7a9f ("net: qlogic: Fix memory leak in ql_alloc_large_buffers") added a direct call to dev_kfree_skb_any() after the skb is recorded in lrg_buf[], so ql_free_large_buffers() will double-free it. The bugs are somewhat inter-twined, so fix them all at once: * Clear each entry in qla_buf[] before attempting to allocate an skb for it. This goes half-way to fixing bug 1. * Set the .skb field only after the skb is DMA-mapped. This fixes the rest. Fixes: 1357bfcf7106 ("qla3xxx: Dynamically size the rx buffer queue ...") Fixes: 0f8ab89e825f ("qla3xxx: Check return code from pci_map_single() ...") Fixes: 1acb8f2a7a9f ("net: qlogic: Fix memory leak in ql_alloc_large_buffers") Signed-off-by: Ben Hutchings Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/qlogic/qla3xxx.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/drivers/net/ethernet/qlogic/qla3xxx.c +++ b/drivers/net/ethernet/qlogic/qla3xxx.c @@ -2752,6 +2752,9 @@ static int ql_alloc_large_buffers(struct int err; for (i = 0; i < qdev->num_large_buffers; i++) { + lrg_buf_cb = &qdev->lrg_buf[i]; + memset(lrg_buf_cb, 0, sizeof(struct ql_rcv_buf_cb)); + skb = netdev_alloc_skb(qdev->ndev, qdev->lrg_buffer_len); if (unlikely(!skb)) { @@ -2762,11 +2765,7 @@ static int ql_alloc_large_buffers(struct ql_free_large_buffers(qdev); return -ENOMEM; } else { - - lrg_buf_cb = &qdev->lrg_buf[i]; - memset(lrg_buf_cb, 0, sizeof(struct ql_rcv_buf_cb)); lrg_buf_cb->index = i; - lrg_buf_cb->skb = skb; /* * We save some space to copy the ethhdr from first * buffer @@ -2788,6 +2787,7 @@ static int ql_alloc_large_buffers(struct return -ENOMEM; } + lrg_buf_cb->skb = skb; dma_unmap_addr_set(lrg_buf_cb, mapaddr, map); dma_unmap_len_set(lrg_buf_cb, maplen, qdev->lrg_buffer_len -