* [PATCH] octeon_ep_vf: add NULL check for napi_build_skb()
@ 2026-04-03 20:07 David Carlier
2026-04-08 17:02 ` Simon Horman
0 siblings, 1 reply; 3+ messages in thread
From: David Carlier @ 2026-04-03 20:07 UTC (permalink / raw)
To: Veerasenareddy Burru, Sathesh Edara, Shinas Rasheed,
Satananda Burla, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni
Cc: netdev, David Carlier, stable
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 <devnexen@gmail.com>
---
.../marvell/octeon_ep_vf/octep_vf_rx.c | 34 ++++++++++++++++++-
1 file changed, 33 insertions(+), 1 deletion(-)
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 b579d5b545c4..97b836c1f5d2 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,18 @@ 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++;
+ read_idx++;
+ desc_used++;
+ 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 +432,30 @@ 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++;
+ read_idx++;
+ desc_used++;
+ 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;
+ read_idx++;
+ desc_used++;
+ 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
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] octeon_ep_vf: add NULL check for napi_build_skb()
2026-04-03 20:07 [PATCH] octeon_ep_vf: add NULL check for napi_build_skb() David Carlier
@ 2026-04-08 17:02 ` Simon Horman
2026-04-08 17:35 ` David CARLIER
0 siblings, 1 reply; 3+ messages in thread
From: Simon Horman @ 2026-04-08 17:02 UTC (permalink / raw)
To: David Carlier
Cc: Veerasenareddy Burru, Sathesh Edara, Shinas Rasheed,
Satananda Burla, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, netdev, stable
On Fri, Apr 03, 2026 at 09:07:32PM +0100, David Carlier wrote:
> 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 <devnexen@gmail.com>
Hi David,
I appreciate that this is on the fast path, and thus I expect it
is performance critical. But this patch largely duplicates code
already present in the same function. Would it be possible
refactor things a bit - e.g. using helpers - to make the change
a bit cleaner while not hurting performance?
If so, I'd suggest splitting patch(es) that refactor the code
from the patch that fixes the bug.
...
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] octeon_ep_vf: add NULL check for napi_build_skb()
2026-04-08 17:02 ` Simon Horman
@ 2026-04-08 17:35 ` David CARLIER
0 siblings, 0 replies; 3+ messages in thread
From: David CARLIER @ 2026-04-08 17:35 UTC (permalink / raw)
To: Simon Horman
Cc: Veerasenareddy Burru, Sathesh Edara, Shinas Rasheed,
Satananda Burla, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, netdev, stable
Hi Simon,
On Wed, 8 Apr 2026 at 18:02, Simon Horman <horms@kernel.org> wrote:
>
> On Fri, Apr 03, 2026 at 09:07:32PM +0100, David Carlier wrote:
> > 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 <devnexen@gmail.com>
>
> Hi David,
>
> I appreciate that this is on the fast path, and thus I expect it
> is performance critical. But this patch largely duplicates code
> already present in the same function. Would it be possible
> refactor things a bit - e.g. using helpers - to make the change
> a bit cleaner while not hurting performance?
>
> If so, I'd suggest splitting patch(es) that refactor the code
> from the patch that fixes the bug.
>
> ...
Yes, valid points, I'll submit the v2 tomorrow. Cheers !
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-04-08 17:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-03 20:07 [PATCH] octeon_ep_vf: add NULL check for napi_build_skb() David Carlier
2026-04-08 17:02 ` Simon Horman
2026-04-08 17:35 ` David CARLIER
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox