From patchwork Mon Apr 18 23:17:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Grundler X-Patchwork-Id: 12817153 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E0E8C433F5 for ; Mon, 18 Apr 2022 23:18:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234663AbiDRXUq (ORCPT ); Mon, 18 Apr 2022 19:20:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234591AbiDRXUm (ORCPT ); Mon, 18 Apr 2022 19:20:42 -0400 Received: from mail-qk1-x72c.google.com (mail-qk1-x72c.google.com [IPv6:2607:f8b0:4864:20::72c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D28823BC8 for ; Mon, 18 Apr 2022 16:18:01 -0700 (PDT) Received: by mail-qk1-x72c.google.com with SMTP id s4so12365753qkh.0 for ; Mon, 18 Apr 2022 16:18:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uzTGDQP0f95uJjkIzcCv5mUHYF5rmou/7UB+HwmJESo=; b=LnzjpeDIks5TxNNm0jxFG63+BZztr6COd+ExcQMvzsOqsM2haLamtMZKk1rooCKegZ w8gBU/C1SS8idFiRcEUjcNBkHGFgTft3LgIZVsVd9IbJQSPzZGwR2f603crEAbL8kW/J 8b25ke05TK3yGUKeqeKEO2VSaHD7XesZa1wMI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uzTGDQP0f95uJjkIzcCv5mUHYF5rmou/7UB+HwmJESo=; b=09UK7E45rpOx1SgC9OsLe2ApN17FAgiCiumMsWU6ZIoNZalg6b4rMNnWyOkEjOkOfF /U7FNVhL9iNa9m7c9hfEQXeZ6vXj9CVm0qRoHYATc3UnFXi2TmRNu7mSd5D15yoc2+c2 JSeXl1oMmqrQedobqPgic2aU9JwFE5gk/NJfbSa6VQm/8sg0iu4BSGSBo/fj3RMeC2JQ g9n/oI+YQRPjm8Ga/O6WdTwQ687iIHHCBhLd0XZSEY/5dCSGdVYr0v7ITGlchflAlOEr k9hMjOOzgDpd7IyUIE3UQeyy26dB2m2VWtU7Jbh7SIqfI/iU1VFMzM2ZzjOUs6kQ9tZ1 OU2g== X-Gm-Message-State: AOAM530sdirwaQWuxqnx6iyt4rGTasVeMNi+my4u9sTvwfrfOfWIz6Bu MYbSoUP8yNjNX08bRABUAI7Ikw== X-Google-Smtp-Source: ABdhPJxsj1wrb92DBhSr8MmPgWD1TRSXaztHAb6okgzlnASHT8TV/adbzOw2yNkVM0aCjPWfsKYqqg== X-Received: by 2002:a05:620a:1724:b0:69e:883a:85b6 with SMTP id az36-20020a05620a172400b0069e883a85b6mr6297843qkb.247.1650323880498; Mon, 18 Apr 2022 16:18:00 -0700 (PDT) Received: from grundler-glapstation.lan ([70.134.62.80]) by smtp.gmail.com with ESMTPSA id a1-20020a05622a02c100b002f17cba4930sm8214048qtx.85.2022.04.18.16.17.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 16:18:00 -0700 (PDT) From: Grant Grundler To: Igor Russkikh Cc: Jakub Kicinski , Paolo Abeni , netdev , "David S . Miller" , LKML , Aashay Shringarpure , Yi Chou , Shervin Oloumi , Grant Grundler Subject: [PATCH 1/5] net: atlantic: limit buff_ring index value Date: Mon, 18 Apr 2022 16:17:42 -0700 Message-Id: <20220418231746.2464800-2-grundler@chromium.org> X-Mailer: git-send-email 2.36.0.rc0.470.gd361397f0d-goog In-Reply-To: <20220418231746.2464800-1-grundler@chromium.org> References: <20220418231746.2464800-1-grundler@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org buff->next is pulled from data DMA'd by the NIC and later used to index into the buff_ring[] array. Verify the index is within the size of the array. Reported-by: Aashay Shringarpure Reported-by: Yi Chou Reported-by: Shervin Oloumi Signed-off-by: Grant Grundler --- drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_b0.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_b0.c b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_b0.c index d875ce3ec759..e72b9d86f6ad 100644 --- a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_b0.c +++ b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_b0.c @@ -981,7 +981,9 @@ int hw_atl_b0_hw_ring_rx_receive(struct aq_hw_s *self, struct aq_ring_s *ring) if (buff->is_lro) { /* LRO */ - buff->next = rxd_wb->next_desc_ptr; + buff->next = + (rxd_wb->next_desc_ptr < ring->size) ? + rxd_wb->next_desc_ptr : 0U; ++ring->stats.rx.lro_packets; } else { /* jumbo */ From patchwork Mon Apr 18 23:17:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Grundler X-Patchwork-Id: 12817154 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1998DC433EF for ; Mon, 18 Apr 2022 23:18:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234720AbiDRXUr (ORCPT ); Mon, 18 Apr 2022 19:20:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234676AbiDRXUq (ORCPT ); Mon, 18 Apr 2022 19:20:46 -0400 Received: from mail-qt1-x833.google.com (mail-qt1-x833.google.com [IPv6:2607:f8b0:4864:20::833]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AEBD23BF1 for ; Mon, 18 Apr 2022 16:18:06 -0700 (PDT) Received: by mail-qt1-x833.google.com with SMTP id fu34so2405983qtb.8 for ; Mon, 18 Apr 2022 16:18:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eGBuACRZ04g6eXXx9CXhc711yGsiIwo7BTuVUQLo/jM=; b=G3M7J2O5fbNDam/Y7wWtwO5oA+WoYmzO9/zF1ye07nxXMQvQMMCgSua+DdGg/Dzs4m iU8SUNeel2RNbTUSXTaZLngqjTqH9tou5OPzyYqHt92aR0aSHi8S8fPPeTrwqkCxRAeO LT4pFnU4i9IrYrafJ7/snP7CCh6S4W9Jspcls= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eGBuACRZ04g6eXXx9CXhc711yGsiIwo7BTuVUQLo/jM=; b=nPPf6/ALoyyGvC1U0WbJ7cJVCNXooGhuRutUZqbmdGNtOsXynHkXBmMHgFGFSh49x0 teK3S3PFkZ9zvHh9p2bXBMtq6i+rB+0jFcec3k++9OCurQAeu0Vu+bt/9GTgKMr8cAV6 Db5YGwpLyV01qdpv9reIuUgaf84rAfTKbeuoggoNxjK8bNSY5WIBS/2PyKjUhxnUqG9C SBHR3YqM3nmWyW2IjkfWcMRENS0umPyX7QFxSYkNUPPjlAx/579sBVgVjZY/GjtoP00Q UDwBTET8/9XSNW0gw8aKFNg8pdNxi9cu25qSri+lEN4QZAMiYfNbTWueyf3PYmqsl0nB Mdew== X-Gm-Message-State: AOAM530fojcUgj2fBNzdSi6y+RyQckwqBrO/kPCcfYhO6CIrmXCTh7Rr KOiSQgoSyEM4YNRCJoNuSLHvyQ== X-Google-Smtp-Source: ABdhPJxioJWtCIZdI8QrOclHvABvNGY9w+WxiL5bLKmhJNjlF1WwIj69Ea9szcH4umCtMgFfGbSBKQ== X-Received: by 2002:ac8:5c14:0:b0:2f2:121:66d4 with SMTP id i20-20020ac85c14000000b002f2012166d4mr3945977qti.675.1650323885286; Mon, 18 Apr 2022 16:18:05 -0700 (PDT) Received: from grundler-glapstation.lan ([70.134.62.80]) by smtp.gmail.com with ESMTPSA id a1-20020a05622a02c100b002f17cba4930sm8214048qtx.85.2022.04.18.16.18.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 16:18:05 -0700 (PDT) From: Grant Grundler To: Igor Russkikh Cc: Jakub Kicinski , Paolo Abeni , netdev , "David S . Miller" , LKML , Aashay Shringarpure , Yi Chou , Shervin Oloumi , Grant Grundler Subject: [PATCH 2/5] net: atlantic: fix "frag[0] not initialized" Date: Mon, 18 Apr 2022 16:17:43 -0700 Message-Id: <20220418231746.2464800-3-grundler@chromium.org> X-Mailer: git-send-email 2.36.0.rc0.470.gd361397f0d-goog In-Reply-To: <20220418231746.2464800-1-grundler@chromium.org> References: <20220418231746.2464800-1-grundler@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org In aq_ring_rx_clean(), if buff->is_eop is not set AND buff->len < AQ_CFG_RX_HDR_SIZE, then hdr_len remains equal to buff->len and skb_add_rx_frag(xxx, *0*, ...) is not called. The loop following this code starts calling skb_add_rx_frag() starting with i=1 and thus frag[0] is never initialized. Since i is initialized to zero at the top of the primary loop, we can just reference and post-increment i instead of hardcoding the 0 when calling skb_add_rx_frag() the first time. Reported-by: Aashay Shringarpure Reported-by: Yi Chou Reported-by: Shervin Oloumi Signed-off-by: Grant Grundler --- drivers/net/ethernet/aquantia/atlantic/aq_ring.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_ring.c b/drivers/net/ethernet/aquantia/atlantic/aq_ring.c index 77e76c9efd32..440423b0e8ea 100644 --- a/drivers/net/ethernet/aquantia/atlantic/aq_ring.c +++ b/drivers/net/ethernet/aquantia/atlantic/aq_ring.c @@ -446,7 +446,7 @@ int aq_ring_rx_clean(struct aq_ring_s *self, ALIGN(hdr_len, sizeof(long))); if (buff->len - hdr_len > 0) { - skb_add_rx_frag(skb, 0, buff->rxdata.page, + skb_add_rx_frag(skb, i++, buff->rxdata.page, buff->rxdata.pg_off + hdr_len, buff->len - hdr_len, AQ_CFG_RX_FRAME_MAX); @@ -455,7 +455,6 @@ int aq_ring_rx_clean(struct aq_ring_s *self, if (!buff->is_eop) { buff_ = buff; - i = 1U; do { next_ = buff_->next; buff_ = &self->buff_ring[next_]; From patchwork Mon Apr 18 23:17:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Grundler X-Patchwork-Id: 12817155 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E05AC433F5 for ; Mon, 18 Apr 2022 23:18:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234754AbiDRXUu (ORCPT ); Mon, 18 Apr 2022 19:20:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234731AbiDRXUr (ORCPT ); Mon, 18 Apr 2022 19:20:47 -0400 Received: from mail-qt1-x833.google.com (mail-qt1-x833.google.com [IPv6:2607:f8b0:4864:20::833]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9655523BD9 for ; Mon, 18 Apr 2022 16:18:07 -0700 (PDT) Received: by mail-qt1-x833.google.com with SMTP id z19so11121299qtw.2 for ; Mon, 18 Apr 2022 16:18:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cm6vrPc6zBxtc8mQWliADJPsKgyQwKE9+4mqmo5RZKE=; b=U8a3jSUSPI7w+GxtadKgv7/XegggLYVFgOz+hbw1AvD0DG03H+DOlpsGSI6Nhwu7dd qkPGuqZr5UIW/puXFV8QaEpgY8yYz+xeQ8UH+989o0lXmrOmvXwHXy6rbIlhTMF11tyD 1/0Q5Ao2CUxstvd2S0cJxiugKkXr5HGO3TbbI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cm6vrPc6zBxtc8mQWliADJPsKgyQwKE9+4mqmo5RZKE=; b=cPQV9JopnU2nZ+NRQQLE6iGu6NOF5iPLpRSE7AakOxrv9FvAA5+XzAISbYQioeYd75 x6S8+1xcXpBXon6GxmKXJcxHujr8ZRSBNRF/VBciCrHZEorjAhfHWg0fb7/QHAHJ8Wxh NkrsZ2lfvmt9N0b5nMUaFx4zuiO1twCDlUn2DJ5omltUQY5xBxwxr3TSGQiRz63f5QaM tqyrzME8xKWVyIKCMwM9hNjBcwJPBxnT1o7aGh9phRBuT2y8VeirVSDrn9jvrOjJUKB/ Xs/2rZF0SJyPdIbd2raYz9YGbXSXfGYx20Io6j3KF+sqwSy7CkBYarpR2275vGeZx8IJ UjSw== X-Gm-Message-State: AOAM530M061ajuy5MhmI82GbapYL/6XtE4jPIijH/kpnIHAuQM8fp0fX Y5NImn6cfLUcu54wfzqnP+YfGwpp1HnPCA== X-Google-Smtp-Source: ABdhPJy+508q4T003VTS1J7WP9dq1N2Y5oaYvHODfUb7OW6Ht+xF09/KjxlhYz+MfAtfzD6Y71opyA== X-Received: by 2002:a05:622a:6182:b0:2f1:e351:abcf with SMTP id hh2-20020a05622a618200b002f1e351abcfmr8548180qtb.321.1650323886785; Mon, 18 Apr 2022 16:18:06 -0700 (PDT) Received: from grundler-glapstation.lan ([70.134.62.80]) by smtp.gmail.com with ESMTPSA id a1-20020a05622a02c100b002f17cba4930sm8214048qtx.85.2022.04.18.16.18.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 16:18:06 -0700 (PDT) From: Grant Grundler To: Igor Russkikh Cc: Jakub Kicinski , Paolo Abeni , netdev , "David S . Miller" , LKML , Aashay Shringarpure , Yi Chou , Shervin Oloumi , Grant Grundler Subject: [PATCH 3/5] net: atlantic: reduce scope of is_rsc_complete Date: Mon, 18 Apr 2022 16:17:44 -0700 Message-Id: <20220418231746.2464800-4-grundler@chromium.org> X-Mailer: git-send-email 2.36.0.rc0.470.gd361397f0d-goog In-Reply-To: <20220418231746.2464800-1-grundler@chromium.org> References: <20220418231746.2464800-1-grundler@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Don't defer handling the err case outside the loop. That's pointless. And since is_rsc_complete is only used inside this loop, declare it inside the loop to reduce it's scope. Signed-off-by: Grant Grundler --- drivers/net/ethernet/aquantia/atlantic/aq_ring.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_ring.c b/drivers/net/ethernet/aquantia/atlantic/aq_ring.c index 440423b0e8ea..bc1952131799 100644 --- a/drivers/net/ethernet/aquantia/atlantic/aq_ring.c +++ b/drivers/net/ethernet/aquantia/atlantic/aq_ring.c @@ -346,7 +346,6 @@ int aq_ring_rx_clean(struct aq_ring_s *self, int budget) { struct net_device *ndev = aq_nic_get_ndev(self->aq_nic); - bool is_rsc_completed = true; int err = 0; for (; (self->sw_head != self->hw_head) && budget; @@ -366,6 +365,8 @@ int aq_ring_rx_clean(struct aq_ring_s *self, if (!buff->is_eop) { buff_ = buff; do { + bool is_rsc_completed = true; + if (buff_->next >= self->size) { err = -EIO; goto err_exit; @@ -377,18 +378,16 @@ int aq_ring_rx_clean(struct aq_ring_s *self, next_, self->hw_head); - if (unlikely(!is_rsc_completed)) - break; + if (unlikely(!is_rsc_completed)) { + err = 0; + goto err_exit; + } buff->is_error |= buff_->is_error; buff->is_cso_err |= buff_->is_cso_err; } while (!buff_->is_eop); - if (!is_rsc_completed) { - err = 0; - goto err_exit; - } if (buff->is_error || (buff->is_lro && buff->is_cso_err)) { buff_ = buff; From patchwork Mon Apr 18 23:17:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Grundler X-Patchwork-Id: 12817156 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF74EC433EF for ; Mon, 18 Apr 2022 23:18:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234834AbiDRXUw (ORCPT ); Mon, 18 Apr 2022 19:20:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234785AbiDRXUt (ORCPT ); Mon, 18 Apr 2022 19:20:49 -0400 Received: from mail-qt1-x835.google.com (mail-qt1-x835.google.com [IPv6:2607:f8b0:4864:20::835]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 091FA24080 for ; Mon, 18 Apr 2022 16:18:09 -0700 (PDT) Received: by mail-qt1-x835.google.com with SMTP id fu34so2406043qtb.8 for ; Mon, 18 Apr 2022 16:18:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NlRd4j5md/1GciWxxdILk90+l0dQrFXO0akgvKuGKys=; b=hOG03vLUq3iZ50ueHjZVfyhoguvGmU1Wah3UxbLvRBUMDP7zKkkkBuYjd7CwcdDpmd wvvPtX/TM+hZxbHCcAAw7kNp7MW8z7+1X6+Xn1Ap+JnbWmme+Uhk6SUloc93MCqSiBSy dPQSoaoWybf/RQ5HVgmoPZD+Gdyrau6flv0MU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NlRd4j5md/1GciWxxdILk90+l0dQrFXO0akgvKuGKys=; b=XnUStgDRhXexnk2igQP4GA1yjAnmse49WAvf/iw0Y+ntabxJmEQd+U2fBQPWOfz7Ik axT9CEEljD05dQljI/80PQ8sCpSKMRS+KBJwp0weHXF3Wp4T3QfbOaUv+tm/T8VcK9C9 pwyRklfxB/e46O4NtBpo1GyXkQN2PkVuuxSXd1VJQDVieGsc0UtyARj41mz7XPnHaqwL 9sMDLneYl9ar/Woh52jiIhfURzr7anT4Bttfa54OHsuAKiK/jU9C4W7OUyQusDyy3eeT qQQ5Q0Vki/zub8xOZclRh/bhtsAZoPCWgvu3HKTn8OKxjs23QAObJWLbsMyoa1HY9AF5 174A== X-Gm-Message-State: AOAM532JAyV35AryayaxjV98Bi+c06WwCTTJP0aqk4VlvReHFoa9fHxX FFgzjYoOkwtCrTVsKW14S/xK1AUyQ1mPPA== X-Google-Smtp-Source: ABdhPJz4CCSb9zYc5fCCMVLbVMjPO5dyAl5MissvY4yDiiQdYIkuU7OrNjGBrPyf5pI+AKWPBQ6/zw== X-Received: by 2002:a05:622a:40f:b0:2f1:f97b:7519 with SMTP id n15-20020a05622a040f00b002f1f97b7519mr6638240qtx.391.1650323888201; Mon, 18 Apr 2022 16:18:08 -0700 (PDT) Received: from grundler-glapstation.lan ([70.134.62.80]) by smtp.gmail.com with ESMTPSA id a1-20020a05622a02c100b002f17cba4930sm8214048qtx.85.2022.04.18.16.18.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 16:18:07 -0700 (PDT) From: Grant Grundler To: Igor Russkikh Cc: Jakub Kicinski , Paolo Abeni , netdev , "David S . Miller" , LKML , Aashay Shringarpure , Yi Chou , Shervin Oloumi , Grant Grundler Subject: [PATCH 4/5] net: atlantic: add check for MAX_SKB_FRAGS Date: Mon, 18 Apr 2022 16:17:45 -0700 Message-Id: <20220418231746.2464800-5-grundler@chromium.org> X-Mailer: git-send-email 2.36.0.rc0.470.gd361397f0d-goog In-Reply-To: <20220418231746.2464800-1-grundler@chromium.org> References: <20220418231746.2464800-1-grundler@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Enforce that the CPU can not get stuck in an infinite loop. Reported-by: Aashay Shringarpure Reported-by: Yi Chou Reported-by: Shervin Oloumi Signed-off-by: Grant Grundler --- drivers/net/ethernet/aquantia/atlantic/aq_ring.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_ring.c b/drivers/net/ethernet/aquantia/atlantic/aq_ring.c index bc1952131799..8201ce7adb77 100644 --- a/drivers/net/ethernet/aquantia/atlantic/aq_ring.c +++ b/drivers/net/ethernet/aquantia/atlantic/aq_ring.c @@ -363,6 +363,7 @@ int aq_ring_rx_clean(struct aq_ring_s *self, continue; if (!buff->is_eop) { + unsigned int frag_cnt = 0U; buff_ = buff; do { bool is_rsc_completed = true; @@ -371,6 +372,8 @@ int aq_ring_rx_clean(struct aq_ring_s *self, err = -EIO; goto err_exit; } + + frag_cnt++; next_ = buff_->next, buff_ = &self->buff_ring[next_]; is_rsc_completed = @@ -378,7 +381,8 @@ int aq_ring_rx_clean(struct aq_ring_s *self, next_, self->hw_head); - if (unlikely(!is_rsc_completed)) { + if (unlikely(!is_rsc_completed) || + frag_cnt > MAX_SKB_FRAGS) { err = 0; goto err_exit; } From patchwork Mon Apr 18 23:17:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Grundler X-Patchwork-Id: 12817157 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2CB91C433F5 for ; Mon, 18 Apr 2022 23:18:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234817AbiDRXVC (ORCPT ); Mon, 18 Apr 2022 19:21:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234808AbiDRXUu (ORCPT ); Mon, 18 Apr 2022 19:20:50 -0400 Received: from mail-qt1-x830.google.com (mail-qt1-x830.google.com [IPv6:2607:f8b0:4864:20::830]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 754BD23BE8 for ; Mon, 18 Apr 2022 16:18:10 -0700 (PDT) Received: by mail-qt1-x830.google.com with SMTP id hf18so10639775qtb.0 for ; Mon, 18 Apr 2022 16:18:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0dcJHoI59iupk/XZrTeiSOhbOxLwLKCBzj4Z2fI2tTc=; b=LhCy4Xw3XN068oiUmiq1/1Q8uv7ZgPx8f0g98Osy317QhjxRDf3CkOOZPc1ftvYJnJ gxOnCH8bESAgzEqHoyAL70WuiVudZ2fj2ItxFXVGHqPNIU0Hj+kI/gpT7q3dnW+7t9YN ffDvkK5FKc6Flz2lKRs5lZvpB7Mi0a3S+yVSA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0dcJHoI59iupk/XZrTeiSOhbOxLwLKCBzj4Z2fI2tTc=; b=7HkmPkVGIVC0kIkHXzdHloxt9YalaORVcpkGw/g31srhMdUyMliQu64qmrwKEy+YIW jjTLjS6rtUtPFsJ6812qtkTV49HOpYddMNiOPZg9XQZVpebQYAC5+un4egS3p2V6mJZ7 Jf+2x9hdniFUhlDcl9+ezo62+n1kxY+FMnw0PSDbEOPpKScT64wsLYg+72JClJanMIDb logEQor9wAUq2nLHr3msNU/Djv0f1YE8cRjn+NLXVdch2qMfVwthrzcwzHTwuM284r22 /Babyjizw6QVL5pMl6hWa2PlEBO8uMgy2MTSee6rJoUxBRT9b4teBlyTPLr1AkKM6PxA 6wug== X-Gm-Message-State: AOAM532TKbvm8RrQ9yRZyomrdTF71hUN3WOWFcGfZsYPh+vkOJ+HcZqK u54V5JYasnll2xwetEMdK1FnNA== X-Google-Smtp-Source: ABdhPJzVmagn0Rfc5cXZudhsLyucFUBeBfCKmqRoxtX4m60vigQt1WYkqD8XBGNWp/r7n0HZ6vDLmg== X-Received: by 2002:ac8:5206:0:b0:2f1:e8cc:7800 with SMTP id r6-20020ac85206000000b002f1e8cc7800mr8620403qtn.501.1650323889668; Mon, 18 Apr 2022 16:18:09 -0700 (PDT) Received: from grundler-glapstation.lan ([70.134.62.80]) by smtp.gmail.com with ESMTPSA id a1-20020a05622a02c100b002f17cba4930sm8214048qtx.85.2022.04.18.16.18.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 16:18:09 -0700 (PDT) From: Grant Grundler To: Igor Russkikh Cc: Jakub Kicinski , Paolo Abeni , netdev , "David S . Miller" , LKML , Aashay Shringarpure , Yi Chou , Shervin Oloumi , Grant Grundler Subject: [PATCH 5/5] net: atlantic: verify hw_head_ is reasonable Date: Mon, 18 Apr 2022 16:17:46 -0700 Message-Id: <20220418231746.2464800-6-grundler@chromium.org> X-Mailer: git-send-email 2.36.0.rc0.470.gd361397f0d-goog In-Reply-To: <20220418231746.2464800-1-grundler@chromium.org> References: <20220418231746.2464800-1-grundler@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Bounds check hw_head index to verify it lies within the TX buffer ring. Unexpected values of hw_head may cause aq_ring_tx_clean to double dev_kfree_skb_any already cleaned parts of the ring. Reported-by: Aashay Shringarpure Reported-by: Yi Chou Reported-by: Shervin Oloumi Signed-off-by: Grant Grundler --- .../aquantia/atlantic/hw_atl/hw_atl_b0.c | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_b0.c b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_b0.c index e72b9d86f6ad..9b6b93bb3e86 100644 --- a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_b0.c +++ b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_b0.c @@ -889,6 +889,27 @@ int hw_atl_b0_hw_ring_tx_head_update(struct aq_hw_s *self, err = -ENXIO; goto err_exit; } + + /* Validate that the new hw_head_ is reasonable. */ + if (hw_head_ >= ring->size) { + err = -ENXIO; + goto err_exit; + } + + if (ring->sw_head >= ring->sw_tail) { + /* Head index hasn't wrapped around to below tail index. */ + if (hw_head_ < ring->sw_head && hw_head_ >= ring->sw_tail) { + err = -ENXIO; + goto err_exit; + } + } else { + /* Head index has wrapped around and is below tail index. */ + if (hw_head_ < ring->sw_head || hw_head_ >= ring->sw_tail) { + err = -ENXIO; + goto err_exit; + } + } + ring->hw_head = hw_head_; err = aq_hw_err_from_flags(self);