* [PATCH iwl-next v2] ixgbe: Fix possible skb NULL pointer dereference
@ 2025-01-17 15:49 Piotr Kwapulinski
2025-01-20 14:45 ` Maciej Fijalkowski
0 siblings, 1 reply; 4+ messages in thread
From: Piotr Kwapulinski @ 2025-01-17 15:49 UTC (permalink / raw)
To: intel-wired-lan
Cc: netdev, dan.carpenter, yuehaibing, maciej.fijalkowski,
przemyslaw.kitszel, Piotr Kwapulinski
The commit c824125cbb18 ("ixgbe: Fix passing 0 to ERR_PTR in
ixgbe_run_xdp()") stopped utilizing the ERR-like macros for xdp status
encoding. Propagate this logic to the ixgbe_put_rx_buffer().
The commit also relaxed the skb NULL pointer check - caught by Smatch.
Restore this check.
Fixes: c824125cbb18 ("ixgbe: Fix passing 0 to ERR_PTR in ixgbe_run_xdp()")
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Piotr Kwapulinski <piotr.kwapulinski@intel.com>
---
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
index 7236f20..c682c3d 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
@@ -2098,14 +2098,14 @@ static struct ixgbe_rx_buffer *ixgbe_get_rx_buffer(struct ixgbe_ring *rx_ring,
static void ixgbe_put_rx_buffer(struct ixgbe_ring *rx_ring,
struct ixgbe_rx_buffer *rx_buffer,
- struct sk_buff *skb,
- int rx_buffer_pgcnt)
+ struct sk_buff *skb, int rx_buffer_pgcnt,
+ int xdp_res)
{
if (ixgbe_can_reuse_rx_page(rx_buffer, rx_buffer_pgcnt)) {
/* hand second half of page back to the ring */
ixgbe_reuse_rx_page(rx_ring, rx_buffer);
} else {
- if (!IS_ERR(skb) && IXGBE_CB(skb)->dma == rx_buffer->dma) {
+ if (skb && !xdp_res && IXGBE_CB(skb)->dma == rx_buffer->dma) {
/* the page has been released from the ring */
IXGBE_CB(skb)->page_released = true;
} else {
@@ -2415,7 +2415,8 @@ static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
break;
}
- ixgbe_put_rx_buffer(rx_ring, rx_buffer, skb, rx_buffer_pgcnt);
+ ixgbe_put_rx_buffer(rx_ring, rx_buffer, skb, rx_buffer_pgcnt,
+ xdp_res);
cleaned_count++;
/* place incomplete frames back on ring for completion */
--
v1 -> v2
Provide extra details in commit message for motivation of this patch.
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH iwl-next v2] ixgbe: Fix possible skb NULL pointer dereference 2025-01-17 15:49 [PATCH iwl-next v2] ixgbe: Fix possible skb NULL pointer dereference Piotr Kwapulinski @ 2025-01-20 14:45 ` Maciej Fijalkowski 2025-01-23 8:19 ` Kwapulinski, Piotr 0 siblings, 1 reply; 4+ messages in thread From: Maciej Fijalkowski @ 2025-01-20 14:45 UTC (permalink / raw) To: Piotr Kwapulinski Cc: intel-wired-lan, netdev, dan.carpenter, yuehaibing, przemyslaw.kitszel On Fri, Jan 17, 2025 at 04:49:35PM +0100, Piotr Kwapulinski wrote: > The commit c824125cbb18 ("ixgbe: Fix passing 0 to ERR_PTR in > ixgbe_run_xdp()") stopped utilizing the ERR-like macros for xdp status > encoding. Propagate this logic to the ixgbe_put_rx_buffer(). > > The commit also relaxed the skb NULL pointer check - caught by Smatch. > Restore this check. > > Fixes: c824125cbb18 ("ixgbe: Fix passing 0 to ERR_PTR in ixgbe_run_xdp()") > Reported-by: Dan Carpenter <dan.carpenter@linaro.org> > Signed-off-by: Piotr Kwapulinski <piotr.kwapulinski@intel.com> > --- > drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) > > diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c > index 7236f20..c682c3d 100644 > --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c > +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c > @@ -2098,14 +2098,14 @@ static struct ixgbe_rx_buffer *ixgbe_get_rx_buffer(struct ixgbe_ring *rx_ring, > > static void ixgbe_put_rx_buffer(struct ixgbe_ring *rx_ring, > struct ixgbe_rx_buffer *rx_buffer, > - struct sk_buff *skb, > - int rx_buffer_pgcnt) > + struct sk_buff *skb, int rx_buffer_pgcnt, > + int xdp_res) > { > if (ixgbe_can_reuse_rx_page(rx_buffer, rx_buffer_pgcnt)) { > /* hand second half of page back to the ring */ > ixgbe_reuse_rx_page(rx_ring, rx_buffer); > } else { > - if (!IS_ERR(skb) && IXGBE_CB(skb)->dma == rx_buffer->dma) { > + if (skb && !xdp_res && IXGBE_CB(skb)->dma == rx_buffer->dma) { xdp_res check is redundant here. skb ptr will be non-null only for xdp_res == 0. so skb != NULL implies xdp_res == 0. If I am not mistaken:D or ixgbe has some code path I missed. Besides this, thanks for improving commit message! > /* the page has been released from the ring */ > IXGBE_CB(skb)->page_released = true; > } else { > @@ -2415,7 +2415,8 @@ static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector, > break; > } > > - ixgbe_put_rx_buffer(rx_ring, rx_buffer, skb, rx_buffer_pgcnt); > + ixgbe_put_rx_buffer(rx_ring, rx_buffer, skb, rx_buffer_pgcnt, > + xdp_res); > cleaned_count++; > > /* place incomplete frames back on ring for completion */ > -- > v1 -> v2 > Provide extra details in commit message for motivation of this patch. > > 2.43.0 > ^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [PATCH iwl-next v2] ixgbe: Fix possible skb NULL pointer dereference 2025-01-20 14:45 ` Maciej Fijalkowski @ 2025-01-23 8:19 ` Kwapulinski, Piotr 2025-01-23 12:27 ` Maciej Fijalkowski 0 siblings, 1 reply; 4+ messages in thread From: Kwapulinski, Piotr @ 2025-01-23 8:19 UTC (permalink / raw) To: Fijalkowski, Maciej Cc: intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org, dan.carpenter@linaro.org, yuehaibing@huawei.com, Kitszel, Przemyslaw >-----Original Message----- >From: Fijalkowski, Maciej <maciej.fijalkowski@intel.com> >Sent: Monday, January 20, 2025 3:45 PM >To: Kwapulinski, Piotr <piotr.kwapulinski@intel.com> >Cc: intel-wired-lan@lists.osuosl.org; netdev@vger.kernel.org; dan.carpenter@linaro.org; yuehaibing@huawei.com; Kitszel, Przemyslaw <przemyslaw.kitszel@intel.com> >Subject: Re: [PATCH iwl-next v2] ixgbe: Fix possible skb NULL pointer dereference > >On Fri, Jan 17, 2025 at 04:49:35PM +0100, Piotr Kwapulinski wrote: >> The commit c824125cbb18 ("ixgbe: Fix passing 0 to ERR_PTR in >> ixgbe_run_xdp()") stopped utilizing the ERR-like macros for xdp status >> encoding. Propagate this logic to the ixgbe_put_rx_buffer(). >> >> The commit also relaxed the skb NULL pointer check - caught by Smatch. >> Restore this check. >> >> Fixes: c824125cbb18 ("ixgbe: Fix passing 0 to ERR_PTR in >> ixgbe_run_xdp()") >> Reported-by: Dan Carpenter <dan.carpenter@linaro.org> >> Signed-off-by: Piotr Kwapulinski <piotr.kwapulinski@intel.com> >> --- >> drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 9 +++++---- >> 1 file changed, 5 insertions(+), 4 deletions(-) >> >> diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c >> b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c >> index 7236f20..c682c3d 100644 >> --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c >> +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c >> @@ -2098,14 +2098,14 @@ static struct ixgbe_rx_buffer >> *ixgbe_get_rx_buffer(struct ixgbe_ring *rx_ring, >> >> static void ixgbe_put_rx_buffer(struct ixgbe_ring *rx_ring, >> struct ixgbe_rx_buffer *rx_buffer, >> - struct sk_buff *skb, >> - int rx_buffer_pgcnt) >> + struct sk_buff *skb, int rx_buffer_pgcnt, >> + int xdp_res) >> { >> if (ixgbe_can_reuse_rx_page(rx_buffer, rx_buffer_pgcnt)) { >> /* hand second half of page back to the ring */ >> ixgbe_reuse_rx_page(rx_ring, rx_buffer); >> } else { >> - if (!IS_ERR(skb) && IXGBE_CB(skb)->dma == rx_buffer->dma) { >> + if (skb && !xdp_res && IXGBE_CB(skb)->dma == rx_buffer->dma) { > >xdp_res check is redundant here. skb ptr will be non-null only for xdp_res == 0. so skb != NULL implies xdp_res == 0. That was tempting but eventually the ixgbe_run_xdp() handles the error exclusively. I suggest to leave it as it is. Thanks, Piotr > >If I am not mistaken:D or ixgbe has some code path I missed. > >Besides this, thanks for improving commit message! > >> /* the page has been released from the ring */ >> IXGBE_CB(skb)->page_released = true; >> } else { >> @@ -2415,7 +2415,8 @@ static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector, >> break; >> } >> >> - ixgbe_put_rx_buffer(rx_ring, rx_buffer, skb, rx_buffer_pgcnt); >> + ixgbe_put_rx_buffer(rx_ring, rx_buffer, skb, rx_buffer_pgcnt, >> + xdp_res); >> cleaned_count++; >> >> /* place incomplete frames back on ring for completion */ >> -- >> v1 -> v2 >> Provide extra details in commit message for motivation of this patch. >> >> 2.43.0 >> ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH iwl-next v2] ixgbe: Fix possible skb NULL pointer dereference 2025-01-23 8:19 ` Kwapulinski, Piotr @ 2025-01-23 12:27 ` Maciej Fijalkowski 0 siblings, 0 replies; 4+ messages in thread From: Maciej Fijalkowski @ 2025-01-23 12:27 UTC (permalink / raw) To: Kwapulinski, Piotr Cc: intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org, dan.carpenter@linaro.org, yuehaibing@huawei.com, Kitszel, Przemyslaw On Thu, Jan 23, 2025 at 09:19:34AM +0100, Kwapulinski, Piotr wrote: > >-----Original Message----- > >From: Fijalkowski, Maciej <maciej.fijalkowski@intel.com> > >Sent: Monday, January 20, 2025 3:45 PM > >To: Kwapulinski, Piotr <piotr.kwapulinski@intel.com> > >Cc: intel-wired-lan@lists.osuosl.org; netdev@vger.kernel.org; dan.carpenter@linaro.org; yuehaibing@huawei.com; Kitszel, Przemyslaw <przemyslaw.kitszel@intel.com> > >Subject: Re: [PATCH iwl-next v2] ixgbe: Fix possible skb NULL pointer dereference > > > >On Fri, Jan 17, 2025 at 04:49:35PM +0100, Piotr Kwapulinski wrote: > >> The commit c824125cbb18 ("ixgbe: Fix passing 0 to ERR_PTR in > >> ixgbe_run_xdp()") stopped utilizing the ERR-like macros for xdp status > >> encoding. Propagate this logic to the ixgbe_put_rx_buffer(). > >> > >> The commit also relaxed the skb NULL pointer check - caught by Smatch. > >> Restore this check. > >> > >> Fixes: c824125cbb18 ("ixgbe: Fix passing 0 to ERR_PTR in > >> ixgbe_run_xdp()") > >> Reported-by: Dan Carpenter <dan.carpenter@linaro.org> > >> Signed-off-by: Piotr Kwapulinski <piotr.kwapulinski@intel.com> > >> --- > >> drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 9 +++++---- > >> 1 file changed, 5 insertions(+), 4 deletions(-) > >> > >> diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c > >> b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c > >> index 7236f20..c682c3d 100644 > >> --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c > >> +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c > >> @@ -2098,14 +2098,14 @@ static struct ixgbe_rx_buffer > >> *ixgbe_get_rx_buffer(struct ixgbe_ring *rx_ring, > >> > >> static void ixgbe_put_rx_buffer(struct ixgbe_ring *rx_ring, > >> struct ixgbe_rx_buffer *rx_buffer, > >> - struct sk_buff *skb, > >> - int rx_buffer_pgcnt) > >> + struct sk_buff *skb, int rx_buffer_pgcnt, > >> + int xdp_res) > >> { > >> if (ixgbe_can_reuse_rx_page(rx_buffer, rx_buffer_pgcnt)) { > >> /* hand second half of page back to the ring */ > >> ixgbe_reuse_rx_page(rx_ring, rx_buffer); > >> } else { > >> - if (!IS_ERR(skb) && IXGBE_CB(skb)->dma == rx_buffer->dma) { > >> + if (skb && !xdp_res && IXGBE_CB(skb)->dma == rx_buffer->dma) { > > > >xdp_res check is redundant here. skb ptr will be non-null only for xdp_res == 0. so skb != NULL implies xdp_res == 0. > That was tempting but eventually the ixgbe_run_xdp() handles the error exclusively. I suggest to leave it as it is. ixgbe_run_xdp() on error paths will still return one of our homegrown XDP statuses: #define IXGBE_XDP_PASS 0 #define IXGBE_XDP_CONSUMED BIT(0) #define IXGBE_XDP_TX BIT(1) #define IXGBE_XDP_REDIR BIT(2) #define IXGBE_XDP_EXIT BIT(3) Plus the case "!xdp_res && !skb" is explicitly checked before calling ixgbe_put_rx_buffer() and you're gonna break the rx loop altogether. This happens when you failed to alloc skb for IXGBE_XDP_PASS. > Thanks, > Piotr > > > > >If I am not mistaken:D or ixgbe has some code path I missed. > > > >Besides this, thanks for improving commit message! > > > >> /* the page has been released from the ring */ > >> IXGBE_CB(skb)->page_released = true; > >> } else { > >> @@ -2415,7 +2415,8 @@ static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector, > >> break; > >> } > >> > >> - ixgbe_put_rx_buffer(rx_ring, rx_buffer, skb, rx_buffer_pgcnt); > >> + ixgbe_put_rx_buffer(rx_ring, rx_buffer, skb, rx_buffer_pgcnt, > >> + xdp_res); > >> cleaned_count++; > >> > >> /* place incomplete frames back on ring for completion */ > >> -- > >> v1 -> v2 > >> Provide extra details in commit message for motivation of this patch. > >> > >> 2.43.0 > >> ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-01-23 12:28 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-01-17 15:49 [PATCH iwl-next v2] ixgbe: Fix possible skb NULL pointer dereference Piotr Kwapulinski 2025-01-20 14:45 ` Maciej Fijalkowski 2025-01-23 8:19 ` Kwapulinski, Piotr 2025-01-23 12:27 ` Maciej Fijalkowski
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).