Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4301625pxu; Tue, 1 Dec 2020 01:17:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJxdzPCRTnPJyhhlmvG+BkNSkS+U/fGWnT48RFEYuSBQwNpZTjyg7Jo0PHW8iY1gZ085WBt0 X-Received: by 2002:a05:6402:714:: with SMTP id w20mr2051540edx.252.1606814261265; Tue, 01 Dec 2020 01:17:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606814261; cv=none; d=google.com; s=arc-20160816; b=Ku5gNftGY6R8pivGf3NZVDKHkwmZgqjhwt2Iv7gckibQ/HkpbfGDzHRflVntOEnSLj 4YceTWUG6W0+rdiBd1HhnqLvRowU4r16LbpWLQxwqpgPUmHR6RdMrPxJTPk7Ms4X+aFu LdmN+mXp2D+IV38gRRh6XGrltu0GYgGnkTsUHu+VAwJvyUI8iSWUapeiuTWOVWIbXSbk HWLbfyFTxa8WjD3FbHaipkNOKGfndh0AW8ngW87qZuAtCxoIOsnkK/lvhCz4VSmDDmso WT1Ucnr2GzbtRvWessPxpb2mVcdpP5s3tseLpScU0VINDz8zetPxnLGUD8xkG74D9NqJ 4U0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Ia00DLdKcyr6xkWssb+qmDMZZLzH06LeX+rCiey14lA=; b=tZeTsec7U4EhQu2MKguT9gh66OiC006WlUUdtt+SED6wgfs8pCUfAuTEH7XyfUF3dE 1+YZrlTYNnfgKYVZNLHSurplSKDlhr2qB8BHqy7wMMdUhnelb4+u9baDRHqksLqFYt68 3d6Iz0En2WQ3mcMh97v3GZ9cuD16Ah4W9rnwZbGOTjXt4dtBrpIJQFoghvk+Ngp5eZPF jBYWHN8kKx489crkj3jqDpJwQkcbY3SH0QWKNMGtTn7sNl6+a5XlhMbrsXOO63GWb8IR FkDieNshk/ImFiHAv7pommaQ9I+gacuu73vG1O3e2kUxhPIXQl1XjrIVy2f8bYkHbZC3 njOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gLFjtH0l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h4si740114edv.124.2020.12.01.01.17.18; Tue, 01 Dec 2020 01:17:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gLFjtH0l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390302AbgLAJO0 (ORCPT + 99 others); Tue, 1 Dec 2020 04:14:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:51684 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390169AbgLAJNy (ORCPT ); Tue, 1 Dec 2020 04:13:54 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 8308520770; Tue, 1 Dec 2020 09:13:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606814019; bh=6TvL/hUeQqKv6hDCPBdWHDaRD5UHa64vcBKjcH3i18s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gLFjtH0lllITPy7gz1Ghmh35OK7i7/90NlTZiQ8oczlopFkblclzxLp7cmtfeYhoW 4COwVGw8t0WJU65qpkITibLEXkHFFGTXpBZuKzxXOEB0CufyHJbLZ2IOQ9JDFSvIQi MxvzdBd/FrHocYP3ifo8zjLbbAyS8QWIZYlaZSpA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ido Segev , Shay Agroskin , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.9 111/152] net: ena: handle bad request id in ena_netdev Date: Tue, 1 Dec 2020 09:53:46 +0100 Message-Id: <20201201084726.383820177@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201201084711.707195422@linuxfoundation.org> References: <20201201084711.707195422@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Shay Agroskin [ Upstream commit 5b7022cf1dc0d721bd4b5f3bada05bd8ced82fe0 ] After request id is checked in validate_rx_req_id() its value is still used in the line rx_ring->free_ids[next_to_clean] = rx_ring->ena_bufs[i].req_id; even if it was found to be out-of-bound for the array free_ids. The patch moves the request id to an earlier stage in the napi routine and makes sure its value isn't used if it's found out-of-bounds. Fixes: 30623e1ed116 ("net: ena: avoid memory access violation by validating req_id properly") Signed-off-by: Ido Segev Signed-off-by: Shay Agroskin Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/ethernet/amazon/ena/ena_eth_com.c | 3 ++ drivers/net/ethernet/amazon/ena/ena_netdev.c | 43 +++++-------------- 2 files changed, 14 insertions(+), 32 deletions(-) diff --git a/drivers/net/ethernet/amazon/ena/ena_eth_com.c b/drivers/net/ethernet/amazon/ena/ena_eth_com.c index ccd4405895651..336f115e8091f 100644 --- a/drivers/net/ethernet/amazon/ena/ena_eth_com.c +++ b/drivers/net/ethernet/amazon/ena/ena_eth_com.c @@ -538,6 +538,7 @@ int ena_com_rx_pkt(struct ena_com_io_cq *io_cq, { struct ena_com_rx_buf_info *ena_buf = &ena_rx_ctx->ena_bufs[0]; struct ena_eth_io_rx_cdesc_base *cdesc = NULL; + u16 q_depth = io_cq->q_depth; u16 cdesc_idx = 0; u16 nb_hw_desc; u16 i = 0; @@ -565,6 +566,8 @@ int ena_com_rx_pkt(struct ena_com_io_cq *io_cq, do { ena_buf[i].len = cdesc->length; ena_buf[i].req_id = cdesc->req_id; + if (unlikely(ena_buf[i].req_id >= q_depth)) + return -EIO; if (++i >= nb_hw_desc) break; diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c b/drivers/net/ethernet/amazon/ena/ena_netdev.c index a3a8edf9a734d..0a8520a2e4649 100644 --- a/drivers/net/ethernet/amazon/ena/ena_netdev.c +++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c @@ -801,24 +801,6 @@ static void ena_free_all_io_tx_resources(struct ena_adapter *adapter) adapter->num_io_queues); } -static int validate_rx_req_id(struct ena_ring *rx_ring, u16 req_id) -{ - if (likely(req_id < rx_ring->ring_size)) - return 0; - - netif_err(rx_ring->adapter, rx_err, rx_ring->netdev, - "Invalid rx req_id: %hu\n", req_id); - - u64_stats_update_begin(&rx_ring->syncp); - rx_ring->rx_stats.bad_req_id++; - u64_stats_update_end(&rx_ring->syncp); - - /* Trigger device reset */ - rx_ring->adapter->reset_reason = ENA_REGS_RESET_INV_RX_REQ_ID; - set_bit(ENA_FLAG_TRIGGER_RESET, &rx_ring->adapter->flags); - return -EFAULT; -} - /* ena_setup_rx_resources - allocate I/O Rx resources (Descriptors) * @adapter: network interface device structure * @qid: queue index @@ -1368,15 +1350,10 @@ static struct sk_buff *ena_rx_skb(struct ena_ring *rx_ring, struct ena_rx_buffer *rx_info; u16 len, req_id, buf = 0; void *va; - int rc; len = ena_bufs[buf].len; req_id = ena_bufs[buf].req_id; - rc = validate_rx_req_id(rx_ring, req_id); - if (unlikely(rc < 0)) - return NULL; - rx_info = &rx_ring->rx_buffer_info[req_id]; if (unlikely(!rx_info->page)) { @@ -1452,10 +1429,6 @@ static struct sk_buff *ena_rx_skb(struct ena_ring *rx_ring, len = ena_bufs[buf].len; req_id = ena_bufs[buf].req_id; - rc = validate_rx_req_id(rx_ring, req_id); - if (unlikely(rc < 0)) - return NULL; - rx_info = &rx_ring->rx_buffer_info[req_id]; } while (1); @@ -1704,12 +1677,18 @@ static int ena_clean_rx_irq(struct ena_ring *rx_ring, struct napi_struct *napi, error: adapter = netdev_priv(rx_ring->netdev); - u64_stats_update_begin(&rx_ring->syncp); - rx_ring->rx_stats.bad_desc_num++; - u64_stats_update_end(&rx_ring->syncp); + if (rc == -ENOSPC) { + u64_stats_update_begin(&rx_ring->syncp); + rx_ring->rx_stats.bad_desc_num++; + u64_stats_update_end(&rx_ring->syncp); + adapter->reset_reason = ENA_REGS_RESET_TOO_MANY_RX_DESCS; + } else { + u64_stats_update_begin(&rx_ring->syncp); + rx_ring->rx_stats.bad_req_id++; + u64_stats_update_end(&rx_ring->syncp); + adapter->reset_reason = ENA_REGS_RESET_INV_RX_REQ_ID; + } - /* Too many desc from the device. Trigger reset */ - adapter->reset_reason = ENA_REGS_RESET_TOO_MANY_RX_DESCS; set_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags); return 0; -- 2.27.0