From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A62FA41D11B for ; Wed, 22 Jul 2026 15:51:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784735520; cv=none; b=PXdtio4zMANmV8zkQ9oNvhpXf1xl9hCqg5QF2dimv0iFp5z8wZTSd3mPo4CljXoStNetEK4PSsvsvYtmfggZgWjLCtmvx1tH+mMiHy0DkZSANEUh75kAKC+qdvZY96V0CRU6Ll5STSZwUlhvvJIWPDymh/7kNm/j8dTAyh+QAcI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784735520; c=relaxed/simple; bh=YiOZsq6Y1IbB4b4lwLMmIwOT04xVy4fzjYkWQ7AnOlQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=B6zpM2txXCmifpEvIttcQcSa5khj09LgF07o8dGaH3zghdfz9IP6DJfFoOehWbLgczVZX8DXUIWSnCVJvkRZVFBX/r7+kqOHj05gT1HoL8+Pl41nda4j/YocnVZC6rKPIkBla3M1P1/i7qWVDPW2xYYKZK/A/3d5NDY7cqBGH90= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=DcmVj7pd; arc=none smtp.client-ip=209.85.215.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DcmVj7pd" Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-ca80d708489so4320309a12.1 for ; Wed, 22 Jul 2026 08:51:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784735515; x=1785340315; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=onDvN0sOyUsUE/lLtZeTVoz1SOZ06K7HZFi9ZupIfc4=; b=DcmVj7pdpmc0Sy9cG4sfn7+gn27889loPRUjR0rap+s8HiuKu2/VzVnv2x/TrVIlfY 7jZvcHXl601q4xpPufmOPZ8loeDmemCGXNQ8ackeXfCvy8CeNr2r8i8F0r+62fk8OZ8N +yybKsEKD7ptFQ1/aoBpWvKabJvYUIoqLSgokDP99/HSnWwteKMqcAJnQ5zLl0C/seCq 42/3wbP0wywHcEFX92VZNquUsblME1MXplYJz2GgIHdo4Ap4NRjJpr+qrfI99r79oUvt qDXlIX6+AbyY+XxwgQTgqi+7NbS1g5djFf/L4AWhNcl3FxqJQkmlHv/ga94uM2qM/zP2 eY7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784735515; x=1785340315; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=onDvN0sOyUsUE/lLtZeTVoz1SOZ06K7HZFi9ZupIfc4=; b=g5db8RkqeNKPmEm5xt/NLlX5bwnDs6/UptuEcQ2OfKqT6VyuFjAl3haOcxD9yZZHUd CKfLcuwPVUv9krYUfUcXG3M8ecuoqIBGlMqHBHSNlw+pU23jVwtDIcTJgPFQlNEWbiwg oArMGmEGvL8dnFbiLdkOk7/nS4iaPBpjecc/fPzBQvJktTY+kfaoa7rZq7kydvgroxUo 015463Rn5DoFHCaesHMEzCUZ4WD/rXlldmLf6N3Caq54csM2dEovMV933A655A9iIY7H sUjvAXq1c5opcySaam38A8g8WMI2F6+GS33fhQhs/NdOg/jAdGBMrbWFVrDUGfRgrZNp hlcg== X-Forwarded-Encrypted: i=1; AHgh+Rq6QE3vvtStbh7HaPDfyQyfXR7HqLlce+oY6vciDhncK8rq8unwWSmkM6tHfMG5kffRk4C0igHMsQdUkm4=@vger.kernel.org X-Gm-Message-State: AOJu0Ywm+TCcacT/aWdjrYHORpbwr0kvbdMAR/Jnf+RUpTnoiYF1kEfi 8k9zQ7cVG/0tgKGKSlLqytY/SJDlNLsH5LYDPZthMrlsKeCo4c8MSJu/NiDvkxDfXbE= X-Gm-Gg: AR+sD12eY07Y5mJhAKmNwVdjnjWuvaGxvlT6cLI672widUnSgiTeCL53GPsoGbyXUxE 2B7ON64n4XErwsP+tC1xpQ4kQoA226LLhabE2iSmvob2YYpg2QdMF7fm/kMJd7V2b1vwVOI5WPt Pc6c/+EX1T0DvBXd3v5IK6OtJEtFIr0rpBjvbNJ7PQIOLWdvvm2tAQ5tHK16XmxPjyW5DI3M6/E MdtBzGuuR4wrzqaIybcH7RNZg+LzOV8Zyyxc2rf/JMECrkRODDN4A57BPsvUmnF9ZfZkTQkiuf7 nM6L8vmcoa2X2f4raOkOGEpj4oO7K3+wJjLKml5mVKoueQ8SDO94ORV8yMb0AxOaugFHCtNrcpU UWqbu0F+6y4xcGEpCC3cDAXqwckDT8uo1Ne4domifCUF4QRE1yIct19EzTpOBN8hG5Hq2FicbDz 0h9rLmOK8WelmOlNRoS3mGEt+Sv7RA4ZoHNQ2xXA== X-Received: by 2002:a05:6a20:2d21:b0:3bf:aa54:4cbc with SMTP id adf61e73a8af0-3c4294a6909mr5228486637.26.1784735515492; Wed, 22 Jul 2026 08:51:55 -0700 (PDT) Received: from csl-conti-dell7858.ntu.edu.sg ([155.69.195.57]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3147df097e0sm11123125eec.17.2026.07.22.08.51.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2026 08:51:54 -0700 (PDT) From: Maoyi Xie To: Veerasenareddy Burru , Sathesh Edara , Satananda Burla , Shinas Rasheed Cc: Andrew Lunn , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maciej Fijalkowski , Simon Horman , Guangshuo Li , David Carlier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net v6 4/4] octeon_ep_vf: fix skb frags overflow in the RX path Date: Wed, 22 Jul 2026 23:51:31 +0800 Message-Id: <20260722155131.2017597-5-maoyixie.tju@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260722155131.2017597-1-maoyixie.tju@gmail.com> References: <20260722155131.2017597-1-maoyixie.tju@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit __octep_vf_oq_process_rx() has the same unbounded fragment loop as the PF driver. buff_info->len comes from the device response header. The loop adds one fragment per buffer_size chunk with no check against MAX_SKB_FRAGS. A long packet yields about 18 fragments. That is one past the default MAX_SKB_FRAGS of 17. skb_add_rx_frag() then writes past shinfo->frags[]. The fragment count is now checked before napi_build_skb(). A packet that needs more fragments than the skb can hold is dropped. octep_vf_oq_drop_rx() drains those descriptors. It also frees the head page and every fragment page. The drain stops after MAX_SKB_FRAGS fragments. A bad device length cannot run it past the ring. The previous patch added those frees to the inline drop path. The napi_build_skb() failure path now uses the same helper. Fixes: 1cd3b407977c ("octeon_ep_vf: add Tx/Rx processing and interrupt support") Co-developed-by: Kaixuan Li Signed-off-by: Kaixuan Li Signed-off-by: Maoyi Xie --- .../marvell/octeon_ep_vf/octep_vf_rx.c | 53 ++++++++++++------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_rx.c b/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_rx.c index 302559b16b..9d71937074 100644 --- a/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_rx.c +++ b/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_rx.c @@ -357,6 +357,32 @@ static inline u32 octep_vf_oq_next_idx(struct octep_vf_oq *oq, u32 idx) return (idx + 1 == oq->max_count) ? 0 : idx + 1; } +static void octep_vf_oq_drop_rx(struct octep_vf_oq *oq, + struct octep_vf_rx_buffer *buff_info, + void *resp_hw, u32 *read_idx, u32 *desc_used) +{ + u32 data_len = buff_info->len - oq->max_single_buffer_size; + int i; + + put_page(virt_to_page(resp_hw)); + (*desc_used)++; + *read_idx = octep_vf_oq_next_idx(oq, *read_idx); + for (i = 0; i < MAX_SKB_FRAGS && data_len; i++) { + dma_unmap_page(oq->dev, oq->desc_ring[*read_idx].buffer_ptr, + PAGE_SIZE, DMA_FROM_DEVICE); + buff_info = (struct octep_vf_rx_buffer *) + &oq->buff_info[*read_idx]; + put_page(buff_info->page); + buff_info->page = NULL; + if (data_len < oq->buffer_size) + data_len = 0; + else + data_len -= oq->buffer_size; + (*desc_used)++; + *read_idx = octep_vf_oq_next_idx(oq, *read_idx); + } +} + /** * __octep_vf_oq_process_rx() - Process hardware Rx queue and push to stack. * @@ -430,29 +456,18 @@ static int __octep_vf_oq_process_rx(struct octep_vf_device *oct, read_idx = octep_vf_oq_next_idx(oq, read_idx); } else { struct skb_shared_info *shinfo; - u16 data_len; + u32 data_len; + + data_len = buff_info->len - oq->max_single_buffer_size; + if (DIV_ROUND_UP(data_len, oq->buffer_size) > MAX_SKB_FRAGS) { + octep_vf_oq_drop_rx(oq, buff_info, resp_hw, &read_idx, &desc_used); + continue; + } skb = napi_build_skb((void *)resp_hw, PAGE_SIZE); if (!skb) { oq->stats->alloc_failures++; - put_page(virt_to_page(resp_hw)); - desc_used++; - read_idx = octep_vf_oq_next_idx(oq, read_idx); - data_len = buff_info->len - oq->max_single_buffer_size; - while (data_len) { - dma_unmap_page(oq->dev, oq->desc_ring[read_idx].buffer_ptr, - PAGE_SIZE, DMA_FROM_DEVICE); - buff_info = (struct octep_vf_rx_buffer *) - &oq->buff_info[read_idx]; - put_page(buff_info->page); - buff_info->page = NULL; - if (data_len < oq->buffer_size) - data_len = 0; - else - data_len -= oq->buffer_size; - desc_used++; - read_idx = octep_vf_oq_next_idx(oq, read_idx); - } + octep_vf_oq_drop_rx(oq, buff_info, resp_hw, &read_idx, &desc_used); continue; } rx_bytes += buff_info->len; -- 2.34.1