From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A4D9A33C502 for ; Tue, 5 May 2026 09:54:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777974895; cv=none; b=UPzHXQNW+iMYewXlzUboLYk/EgvsyKsStri+fC4Oka4a1869jtEE8UfFUWzhT0twm7J7egjY+36+5RSljuBa75qGEaE2CU/95QhnBrI+sjd960973DctAY7EsIP0HU6wyrYBTYQSBaMiZ4pld0arMvMdMj95dGhSmET8tmVamrM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777974895; c=relaxed/simple; bh=93QLUM1Z2mFgOUBbpdOj6M1lXWvnwwPsxVzykmxIC0g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fHdbrQZH2hl/6KSQg0fc8al0umDRRVOnoLPE7+lISqSTNawbA4cRBwAVgTjvOTxI7yUrSG544nUpKG1MDdYbGlb/Y0gv9SPxzh1PXkYUH169bRgR2HiC3oGKHkcxb4wKn8+7nt9ljSLljqIdn99GRfLSSUpI5UUVK+Lnh56a7yA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YcSYIowY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YcSYIowY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 41C9FC2BCB4; Tue, 5 May 2026 09:54:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777974895; bh=93QLUM1Z2mFgOUBbpdOj6M1lXWvnwwPsxVzykmxIC0g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YcSYIowYW0jmgKg2Oc8A5n+OGTMouROj+aJC5m7QbCh1eM/xzfCgJ6Sjz7qUp7psl 4t3geLLm7AS4PsrtDMnuLpyHcYE3cFmse6ZIHtb8njLxzLa5uQRm8sSWzIlRk0Q7w3 gADI5+HCsqs5pEjdAgdwyDhgcUI3YLud00/HVC091ZJFdSzvYkbPg1vZV41Rhhk6iV zDVJ0X+FYslc2iWBvdwBn4dhQQA/kPgShElUxAqSfPxiM+QH3rYdXBlyHSH9E920E6 NnISSM7tjHiS/M2ECXOt4G+/7ff7+I5e4KTv2uWxosbj5iI3fTdtJPANpocBbiRIU1 LB0SfB1vOCdAw== From: Sasha Levin To: stable@vger.kernel.org Cc: David Carlier , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.12.y] octeon_ep_vf: add NULL check for napi_build_skb() Date: Tue, 5 May 2026 05:54:50 -0400 Message-ID: <20260505095450.517892-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026050149-quench-blouse-851f@gregkh> References: <2026050149-quench-blouse-851f@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: David Carlier [ Upstream commit dd66b42854705e4e4ee7f14d260f86c578bed3e3 ] napi_build_skb() can return NULL on allocation failure. In __octep_vf_oq_process_rx(), the result is used directly without a NULL check in both the single-buffer and multi-fragment paths, leading to a NULL pointer dereference. Add NULL checks after both napi_build_skb() calls, properly advancing descriptors and consuming remaining fragments on failure. Fixes: 1cd3b407977c ("octeon_ep_vf: add Tx/Rx processing and interrupt support") Cc: stable@vger.kernel.org Signed-off-by: David Carlier Link: https://patch.msgid.link/20260409184009.930359-3-devnexen@gmail.com Signed-off-by: Jakub Kicinski [ inlined missing octep_vf_oq_next_idx() helper as read_idx++ with wraparound ] Signed-off-by: Sasha Levin --- .../marvell/octeon_ep_vf/octep_vf_rx.c | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 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 b579d5b545c46..8347e696937cd 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 @@ -409,10 +409,17 @@ static int __octep_vf_oq_process_rx(struct octep_vf_device *oct, data_offset = OCTEP_VF_OQ_RESP_HW_SIZE; rx_ol_flags = 0; } - rx_bytes += buff_info->len; - if (buff_info->len <= oq->max_single_buffer_size) { skb = napi_build_skb((void *)resp_hw, PAGE_SIZE); + if (!skb) { + oq->stats->alloc_failures++; + desc_used++; + read_idx++; + if (read_idx == oq->max_count) + read_idx = 0; + continue; + } + rx_bytes += buff_info->len; skb_reserve(skb, data_offset); skb_put(skb, buff_info->len); read_idx++; @@ -424,6 +431,31 @@ static int __octep_vf_oq_process_rx(struct octep_vf_device *oct, u16 data_len; skb = napi_build_skb((void *)resp_hw, PAGE_SIZE); + if (!skb) { + oq->stats->alloc_failures++; + desc_used++; + read_idx++; + if (read_idx == oq->max_count) + read_idx = 0; + 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]; + buff_info->page = NULL; + if (data_len < oq->buffer_size) + data_len = 0; + else + data_len -= oq->buffer_size; + desc_used++; + read_idx++; + if (read_idx == oq->max_count) + read_idx = 0; + } + continue; + } + rx_bytes += buff_info->len; skb_reserve(skb, data_offset); /* Head fragment includes response header(s); * subsequent fragments contains only data. -- 2.53.0