From patchwork Mon Aug 15 14:57:38 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: 12943658 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 A5148C28B2B for ; Mon, 15 Aug 2022 14:58:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242690AbiHOO6U (ORCPT ); Mon, 15 Aug 2022 10:58:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242617AbiHOO5u (ORCPT ); Mon, 15 Aug 2022 10:57:50 -0400 Received: from mx3.wp.pl (mx3.wp.pl [212.77.101.9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A551B20F7B for ; Mon, 15 Aug 2022 07:57:46 -0700 (PDT) Received: (wp-smtpd smtp.wp.pl 17361 invoked from network); 15 Aug 2022 16:57:44 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wp.pl; s=1024a; t=1660575464; bh=nI++WfODD/yYiC7hRLpfGQNbFWOWckb7AI78JuFGSFU=; h=From:To:Subject; b=OJhdmCql7gYzw+6xEOpJY65Lc7Y7EPEtH8fSPkWTjO63SnxB/76S9/o+ZliX8TnVd 9yZbPgggOaQep48xPzP6lg+aHdc7oiUx95h6mJDh7tPaPvD/G/iz5bhcAyrp9IBsym w0HVm3P4K2d2dWsXYtOr/EDGpJyavFOyh00+AKn8= 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 ; 15 Aug 2022 16:57:44 +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 v2 1/3] net: lantiq_xrx200: confirm skb is allocated before using Date: Mon, 15 Aug 2022 16:57:38 +0200 Message-Id: <20220815145740.12075-2-olek2@wp.pl> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220815145740.12075-1-olek2@wp.pl> References: <20220815145740.12075-1-olek2@wp.pl> MIME-Version: 1.0 X-WP-MailID: f46c6734638bb11ccfcfeb7ea0101ceb X-WP-AV: skaner antywirusowy Poczty Wirtualnej Polski X-WP-SPAM: NO 0000000 [EZNE] 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 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/net/ethernet/lantiq_xrx200.c b/drivers/net/ethernet/lantiq_xrx200.c index 5edb68a8aab1..6a83a6c19484 100644 --- a/drivers/net/ethernet/lantiq_xrx200.c +++ b/drivers/net/ethernet/lantiq_xrx200.c @@ -239,6 +239,13 @@ 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++; + netdev_err(net_dev, "failed to build skb\n"); + return -ENOMEM; + } + skb_reserve(skb, NET_SKB_PAD); skb_put(skb, len); From patchwork Mon Aug 15 14:57:39 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: 12943656 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 1C225C25B06 for ; Mon, 15 Aug 2022 14:58:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242565AbiHOO6R (ORCPT ); Mon, 15 Aug 2022 10:58:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242734AbiHOO5v (ORCPT ); Mon, 15 Aug 2022 10:57:51 -0400 Received: from mx3.wp.pl (mx3.wp.pl [212.77.101.9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72D6B220D0 for ; Mon, 15 Aug 2022 07:57:50 -0700 (PDT) Received: (wp-smtpd smtp.wp.pl 21178 invoked from network); 15 Aug 2022 16:57:47 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wp.pl; s=1024a; t=1660575467; bh=6UBfrDuAKAfCBcQ5WvVckMBl91GC0tVFQSnvsPx4Kjw=; h=From:To:Subject; b=fxAhDGmeRrbqX7AyzEl8vw5nNyV9mJ2isZrjts8xAvdtOZNct1mvlQDPxMnQ7WHur tY9guY8G1tubpc/qDFU/aHBrfjp6eN/niFaXr8xxZpCK/dGllj7ctiHkPlDN+U7fzn xPzpfS3D5Heknj0ljlOL8rC+h80Xi8Ueb41oIT84= 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 ; 15 Aug 2022 16:57:47 +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 v2 2/3] net: lantiq_xrx200: fix lock under memory pressure Date: Mon, 15 Aug 2022 16:57:39 +0200 Message-Id: <20220815145740.12075-3-olek2@wp.pl> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220815145740.12075-1-olek2@wp.pl> References: <20220815145740.12075-1-olek2@wp.pl> MIME-Version: 1.0 X-WP-MailID: fc583946f3f5ae290f869c3fa1f60c3c X-WP-AV: skaner antywirusowy Poczty Wirtualnej Polski X-WP-SPAM: NO 0000000 [QVPk] 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 6a83a6c19484..8f9155eacdb3 100644 --- a/drivers/net/ethernet/lantiq_xrx200.c +++ b/drivers/net/ethernet/lantiq_xrx200.c @@ -295,7 +295,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 Mon Aug 15 14:57:40 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: 12943655 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 305D1C00140 for ; Mon, 15 Aug 2022 14:58:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241760AbiHOO6N (ORCPT ); Mon, 15 Aug 2022 10:58:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243015AbiHOO6H (ORCPT ); Mon, 15 Aug 2022 10:58:07 -0400 Received: from mx4.wp.pl (mx4.wp.pl [212.77.101.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A08BE20F77 for ; Mon, 15 Aug 2022 07:57:52 -0700 (PDT) Received: (wp-smtpd smtp.wp.pl 24348 invoked from network); 15 Aug 2022 16:57:50 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wp.pl; s=1024a; t=1660575470; bh=bbx1VwhcpzU6gGqpU29j/UW9BkypCjsV6XkTw13EfUc=; h=From:To:Subject; b=tMLPK3C5RDAgm/+KbVTQBfyk8LkBVyRXI+L9vNmj2Q2bG423iz8wSejwzXwr1lhd8 dZBUHgpmdq7sJf8FUjGXvt7uqTOa0Bw19vpTnMswT5lSC/VxhJCBKGXTFim/HpYwKA UdcD29Bw+Aa56r3QL4k7KLrvMXe4dXzX5GzTa9xg= 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 ; 15 Aug 2022 16:57:50 +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 v2 3/3] net: lantiq_xrx200: restore buffer if memory allocation failed Date: Mon, 15 Aug 2022 16:57:40 +0200 Message-Id: <20220815145740.12075-4-olek2@wp.pl> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220815145740.12075-1-olek2@wp.pl> References: <20220815145740.12075-1-olek2@wp.pl> MIME-Version: 1.0 X-WP-MailID: 1bd63f0328598b10214596221eb3464f X-WP-AV: skaner antywirusowy Poczty Wirtualnej Polski X-WP-SPAM: NO 0000000 [cXOx] 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 8f9155eacdb3..e817bc545d81 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; }