Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3556293pxb; Mon, 24 Jan 2022 12:08:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJykxCg29rcTstJf/P3nB0urUhvH2eZKDR08pOMJ3i5bcX+a0BFAQQJSjqfZXYKesp59iLth X-Received: by 2002:a63:2d6:: with SMTP id 205mr6997104pgc.64.1643054912531; Mon, 24 Jan 2022 12:08:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643054912; cv=none; d=google.com; s=arc-20160816; b=gwWOBnzUapmbkG8IFirJZ+5zQ9fI0PwTp+vpYsYkmuQHDyQwr53hDyK4WlHkyb+GYl Oz2xtokgv1vwm8Hlp4XJ8Rl0n7wpk/KNITGaHZFp3em3pZ3y0WTmgkcS5ZVQ3E/i6EYx opGi0vQSI+L2E7jbYEuNkXWKNtmeaYKRrtJ8HK+3Ja0mYxOi56eEUNQw0Ds3j7k8mT7Q JXeNhQrNmiluWAg9AmiRcLU+QYuYlPcha8a6h+kqP7gRwR6eNCawEZF6FcohLdKXWMKN SHP098+We3qyNCD4Hez2SwPq8TXPIdDlc8Bo19uhlMIs3M7y/XK2jUPIaxGj7NjNZNLU c/1Q== 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=YtgF5Xe1jzvQTMbexmWT+U+ByVWS0BNQbG2OccPK4ec=; b=XZERt5/0A3kRcsJ3yMQGe2BQU7N0BKmSWpUkWkF6b4x4MxpKg97vGNGKRAn+OLfLRu 6E86wd6tpcfiAPgYeNWqu1cPba17lDIq+xngOBEC3ht9UEJBtWZTW+ypLukCOqrN/HRF fsjDQxy65rWUJ1tqKuTofNIK89rk2elvUqIJbxAboFGv93PeTnchnspof6NOWPGhVHsg 3uOkyOMBa2WpCLL3ORiP9HvFZSFI8hzmUOOvsLQ9+cjrdi3cNA//02MZcmCnUCPr5l7X Bs3BA0sKBd6eegz7mPzWo3BXcYjEbYjddYeQBqzpjBqdtA0cBKrwVOLBV2S118yL0wmi T6Xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sNqmBylp; 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 y12si13333078plp.111.2022.01.24.12.08.18; Mon, 24 Jan 2022 12:08:32 -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=sNqmBylp; 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 S1345109AbiAXTIf (ORCPT + 99 others); Mon, 24 Jan 2022 14:08:35 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:60844 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344517AbiAXTCP (ORCPT ); Mon, 24 Jan 2022 14:02:15 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9132B60BAD; Mon, 24 Jan 2022 19:02:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 468ACC340E5; Mon, 24 Jan 2022 19:02:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643050933; bh=iWOkdgPCQQjl1CePs+iFke75cLkjFCy3GlkrB5GhPvY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sNqmBylp0bo4jKIcD+k2r49JSTlyIFdNWTKK6lT99xalI1NuUnxKcgBANkY5ieUPR WUFDExrpAaS+QifRXqAqIi/JCtaG1QmQNv7o4zWNnxokfhWnlQgOQQfXr+Hj1nbLw8 RPmziA0DJkiaRptE5l1SYGOMSIpOeMuWpfAsvtAQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Braun , "David S. Miller" , Ben Hutchings Subject: [PATCH 4.9 150/157] gianfar: fix jumbo packets+napi+rx overrun crash Date: Mon, 24 Jan 2022 19:44:00 +0100 Message-Id: <20220124183937.520465560@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183932.787526760@linuxfoundation.org> References: <20220124183932.787526760@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: Michael Braun commit d8861bab48b6c1fc3cdbcab8ff9d1eaea43afe7f upstream. When using jumbo packets and overrunning rx queue with napi enabled, the following sequence is observed in gfar_add_rx_frag: | lstatus | | skb | t | lstatus, size, flags | first | len, data_len, *ptr | ---+--------------------------------------+-------+-----------------------+ 13 | 18002348, 9032, INTERRUPT LAST | 0 | 9600, 8000, f554c12e | 12 | 10000640, 1600, INTERRUPT | 0 | 8000, 6400, f554c12e | 11 | 10000640, 1600, INTERRUPT | 0 | 6400, 4800, f554c12e | 10 | 10000640, 1600, INTERRUPT | 0 | 4800, 3200, f554c12e | 09 | 10000640, 1600, INTERRUPT | 0 | 3200, 1600, f554c12e | 08 | 14000640, 1600, INTERRUPT FIRST | 0 | 1600, 0, f554c12e | 07 | 14000640, 1600, INTERRUPT FIRST | 1 | 0, 0, f554c12e | 06 | 1c000080, 128, INTERRUPT LAST FIRST | 1 | 0, 0, abf3bd6e | 05 | 18002348, 9032, INTERRUPT LAST | 0 | 8000, 6400, c5a57780 | 04 | 10000640, 1600, INTERRUPT | 0 | 6400, 4800, c5a57780 | 03 | 10000640, 1600, INTERRUPT | 0 | 4800, 3200, c5a57780 | 02 | 10000640, 1600, INTERRUPT | 0 | 3200, 1600, c5a57780 | 01 | 10000640, 1600, INTERRUPT | 0 | 1600, 0, c5a57780 | 00 | 14000640, 1600, INTERRUPT FIRST | 1 | 0, 0, c5a57780 | So at t=7 a new packets is started but not finished, probably due to rx overrun - but rx overrun is not indicated in the flags. Instead a new packets starts at t=8. This results in skb->len to exceed size for the LAST fragment at t=13 and thus a negative fragment size added to the skb. This then crashes: kernel BUG at include/linux/skbuff.h:2277! Oops: Exception in kernel mode, sig: 5 [#1] ... NIP [c04689f4] skb_pull+0x2c/0x48 LR [c03f62ac] gfar_clean_rx_ring+0x2e4/0x844 Call Trace: [ec4bfd38] [c06a84c4] _raw_spin_unlock_irqrestore+0x60/0x7c (unreliable) [ec4bfda8] [c03f6a44] gfar_poll_rx_sq+0x48/0xe4 [ec4bfdc8] [c048d504] __napi_poll+0x54/0x26c [ec4bfdf8] [c048d908] net_rx_action+0x138/0x2c0 [ec4bfe68] [c06a8f34] __do_softirq+0x3a4/0x4fc [ec4bfed8] [c0040150] run_ksoftirqd+0x58/0x70 [ec4bfee8] [c0066ecc] smpboot_thread_fn+0x184/0x1cc [ec4bff08] [c0062718] kthread+0x140/0x144 [ec4bff38] [c0012350] ret_from_kernel_thread+0x14/0x1c This patch fixes this by checking for computed LAST fragment size, so a negative sized fragment is never added. In order to prevent the newer rx frame from getting corrupted, the FIRST flag is checked to discard the incomplete older frame. Signed-off-by: Michael Braun Signed-off-by: David S. Miller Cc: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/freescale/gianfar.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) --- a/drivers/net/ethernet/freescale/gianfar.c +++ b/drivers/net/ethernet/freescale/gianfar.c @@ -2947,6 +2947,10 @@ static bool gfar_add_rx_frag(struct gfar if (lstatus & BD_LFLAG(RXBD_LAST)) size -= skb->len; + WARN(size < 0, "gianfar: rx fragment size underflow"); + if (size < 0) + return false; + skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page, rxb->page_offset + RXBUF_ALIGNMENT, size, GFAR_RXB_TRUESIZE); @@ -3108,6 +3112,17 @@ int gfar_clean_rx_ring(struct gfar_priv_ if (lstatus & BD_LFLAG(RXBD_EMPTY)) break; + /* lost RXBD_LAST descriptor due to overrun */ + if (skb && + (lstatus & BD_LFLAG(RXBD_FIRST))) { + /* discard faulty buffer */ + dev_kfree_skb(skb); + skb = NULL; + rx_queue->stats.rx_dropped++; + + /* can continue normally */ + } + /* order rx buffer descriptor reads */ rmb();