From patchwork Wed Aug 24 21:54:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksander Jan Bajkowski X-Patchwork-Id: 12953991 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 59509C6498F for ; Wed, 24 Aug 2022 21:54:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240266AbiHXVyF (ORCPT ); Wed, 24 Aug 2022 17:54:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240183AbiHXVyA (ORCPT ); Wed, 24 Aug 2022 17:54:00 -0400 Received: from mx3.wp.pl (mx3.wp.pl [212.77.101.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F09A754B0 for ; Wed, 24 Aug 2022 14:53:58 -0700 (PDT) Received: (wp-smtpd smtp.wp.pl 4295 invoked from network); 24 Aug 2022 23:53:56 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wp.pl; s=1024a; t=1661378036; bh=4OTa75RLpe/v25mpI3TRXaOPqo4ZLnCOlukrrv8iGHU=; h=From:To:Subject; b=GqGggbVUHNjlcjWKR7lEtgdzHPAFUG1gqPzjjI2dC2GnpV+z/B6D9HnqA76cpmuIt BjF1/G17qF0oTv9EWhMrY/5bxSS+X1pYAhaHab+j2a7Gbv51cBAB9/KcfyHhUJN5CJ +c9GYhuxoJS6fMtWgBXaLnIH2f/4cAbJ5e044yjo= Received: from ip-137-21.ds.pw.edu.pl (HELO LAPTOP-OLEK.lan) (olek2@wp.pl@[194.29.137.21]) (envelope-sender ) by smtp.wp.pl (WP-SMTPD) with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP for ; 24 Aug 2022 23:53:56 +0200 From: Aleksander Jan Bajkowski To: hauke@hauke-m.de, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, olek2@wp.pl, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net v3 1/3] net: lantiq_xrx200: confirm skb is allocated before using Date: Wed, 24 Aug 2022 23:54:06 +0200 Message-Id: <20220824215408.4695-2-olek2@wp.pl> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220824215408.4695-1-olek2@wp.pl> References: <20220824215408.4695-1-olek2@wp.pl> MIME-Version: 1.0 X-WP-MailID: da954f5736fb02daf8954bf4042baf0e X-WP-AV: skaner antywirusowy Poczty Wirtualnej Polski X-WP-SPAM: NO 0000000 [oVMU] Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org xrx200_hw_receive() assumes build_skb() always works and goes straight to skb_reserve(). However, build_skb() can fail under memory pressure. Add a check in case build_skb() failed to allocate and return NULL. Fixes: e015593573b3 ("net: lantiq_xrx200: convert to build_skb") Reported-by: Eric Dumazet Signed-off-by: Aleksander Jan Bajkowski --- drivers/net/ethernet/lantiq_xrx200.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/net/ethernet/lantiq_xrx200.c b/drivers/net/ethernet/lantiq_xrx200.c index 5edb68a8aab1..89314b645c82 100644 --- a/drivers/net/ethernet/lantiq_xrx200.c +++ b/drivers/net/ethernet/lantiq_xrx200.c @@ -239,6 +239,12 @@ static int xrx200_hw_receive(struct xrx200_chan *ch) } skb = build_skb(buf, priv->rx_skb_size); + if (!skb) { + skb_free_frag(buf); + net_dev->stats.rx_dropped++; + return -ENOMEM; + } + skb_reserve(skb, NET_SKB_PAD); skb_put(skb, len); From patchwork Wed Aug 24 21:54:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksander Jan Bajkowski X-Patchwork-Id: 12953992 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 19D60C04AA5 for ; Wed, 24 Aug 2022 21:54:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240377AbiHXVyG (ORCPT ); Wed, 24 Aug 2022 17:54:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240290AbiHXVyC (ORCPT ); Wed, 24 Aug 2022 17:54:02 -0400 Received: from mx3.wp.pl (mx3.wp.pl [212.77.101.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFA5F75CD9 for ; Wed, 24 Aug 2022 14:54:00 -0700 (PDT) Received: (wp-smtpd smtp.wp.pl 4906 invoked from network); 24 Aug 2022 23:53:57 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wp.pl; s=1024a; t=1661378037; bh=2D/VRsx5QG7w7GvRQKNXTqivBFxrBuMatT0dd4mF/Bc=; h=From:To:Subject; b=QskSarllpHRI4LkXPCDscix1ftm9o4Anr4aAkTIiaGFgNNHkaFtBWuiy12E8re/Cp KseD9dhIQPH3WecmOIhxAU7k4il5mVrb6ZVeKTTi1D1FOyYUVv32KdYe2tUSWxJwTM tJy6pr90IJTt16WEaQTNOt9mA7MJF8Ded1lgOCFo= Received: from ip-137-21.ds.pw.edu.pl (HELO LAPTOP-OLEK.lan) (olek2@wp.pl@[194.29.137.21]) (envelope-sender ) by smtp.wp.pl (WP-SMTPD) with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP for ; 24 Aug 2022 23:53:57 +0200 From: Aleksander Jan Bajkowski To: hauke@hauke-m.de, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, olek2@wp.pl, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net v3 2/3] net: lantiq_xrx200: fix lock under memory pressure Date: Wed, 24 Aug 2022 23:54:07 +0200 Message-Id: <20220824215408.4695-3-olek2@wp.pl> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220824215408.4695-1-olek2@wp.pl> References: <20220824215408.4695-1-olek2@wp.pl> MIME-Version: 1.0 X-WP-MailID: 945f79291369001f6d8ed7e1d73329ec X-WP-AV: skaner antywirusowy Poczty Wirtualnej Polski X-WP-SPAM: NO 0000000 [8aM0] Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org When the xrx200_hw_receive() function returns -ENOMEM, the NAPI poll function immediately returns an error. This is incorrect for two reasons: * the function terminates without enabling interrupts or scheduling NAPI, * the error code (-ENOMEM) is returned instead of the number of received packets. After the first memory allocation failure occurs, packet reception is locked due to disabled interrupts from DMA.. Fixes: fe1a56420cf2 ("net: lantiq: Add Lantiq / Intel VRX200 Ethernet driver") Signed-off-by: Aleksander Jan Bajkowski --- drivers/net/ethernet/lantiq_xrx200.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/lantiq_xrx200.c b/drivers/net/ethernet/lantiq_xrx200.c index 89314b645c82..25adce7f0c7c 100644 --- a/drivers/net/ethernet/lantiq_xrx200.c +++ b/drivers/net/ethernet/lantiq_xrx200.c @@ -294,7 +294,7 @@ static int xrx200_poll_rx(struct napi_struct *napi, int budget) if (ret == XRX200_DMA_PACKET_IN_PROGRESS) continue; if (ret != XRX200_DMA_PACKET_COMPLETE) - return ret; + break; rx++; } else { break; From patchwork Wed Aug 24 21:54:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksander Jan Bajkowski X-Patchwork-Id: 12953993 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 4595CC04AA5 for ; Wed, 24 Aug 2022 21:54:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240413AbiHXVyI (ORCPT ); Wed, 24 Aug 2022 17:54:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240343AbiHXVyD (ORCPT ); Wed, 24 Aug 2022 17:54:03 -0400 Received: from mx3.wp.pl (mx3.wp.pl [212.77.101.9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 093B175CCF for ; Wed, 24 Aug 2022 14:54:01 -0700 (PDT) Received: (wp-smtpd smtp.wp.pl 5393 invoked from network); 24 Aug 2022 23:53:59 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wp.pl; s=1024a; t=1661378039; bh=jwWpS/IEJkDxPHdX0InnvrmEPux1NMA8vD9SgE2jV9I=; h=From:To:Subject; b=T7R/VZW8P/HHLnTPdHCIuaAqb1fvr7cFnz2Zw0EtkWQu24o1hf+BAgpdk9siXnqtn Rb+qtdDfOU1i/SKAy4XfPkjApYUu1mDms8fmjW3lMlmm+LszSNNvhkg0+CNcXe0zuV XXO1DvbPT9qqUY/Z0zjQNofbYWzg9eFY/ukiMRFU= Received: from ip-137-21.ds.pw.edu.pl (HELO LAPTOP-OLEK.lan) (olek2@wp.pl@[194.29.137.21]) (envelope-sender ) by smtp.wp.pl (WP-SMTPD) with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP for ; 24 Aug 2022 23:53:59 +0200 From: Aleksander Jan Bajkowski To: hauke@hauke-m.de, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, olek2@wp.pl, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net v3 3/3] net: lantiq_xrx200: restore buffer if memory allocation failed Date: Wed, 24 Aug 2022 23:54:08 +0200 Message-Id: <20220824215408.4695-4-olek2@wp.pl> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220824215408.4695-1-olek2@wp.pl> References: <20220824215408.4695-1-olek2@wp.pl> MIME-Version: 1.0 X-WP-MailID: 76d42ead0a5cd8b21ce83a0f3eabf283 X-WP-AV: skaner antywirusowy Poczty Wirtualnej Polski X-WP-SPAM: NO 0000000 [YdNB] Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org In a situation where memory allocation fails, an invalid buffer address is stored. When this descriptor is used again, the system panics in the build_skb() function when accessing memory. Fixes: 7ea6cd16f159 ("lantiq: net: fix duplicated skb in rx descriptor ring") Signed-off-by: Aleksander Jan Bajkowski --- drivers/net/ethernet/lantiq_xrx200.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/ethernet/lantiq_xrx200.c b/drivers/net/ethernet/lantiq_xrx200.c index 25adce7f0c7c..57f27cc7724e 100644 --- a/drivers/net/ethernet/lantiq_xrx200.c +++ b/drivers/net/ethernet/lantiq_xrx200.c @@ -193,6 +193,7 @@ static int xrx200_alloc_buf(struct xrx200_chan *ch, void *(*alloc)(unsigned int ch->rx_buff[ch->dma.desc] = alloc(priv->rx_skb_size); if (!ch->rx_buff[ch->dma.desc]) { + ch->rx_buff[ch->dma.desc] = buf; ret = -ENOMEM; goto skip; }