linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net v1] netmem: fix skb_frag_address_safe with unreadable skbs
@ 2025-06-17 21:09 Mina Almasry
  2025-06-17 21:15 ` Mina Almasry
  2025-06-18 21:53 ` Jakub Kicinski
  0 siblings, 2 replies; 7+ messages in thread
From: Mina Almasry @ 2025-06-17 21:09 UTC (permalink / raw)
  To: netdev, linux-kernel
  Cc: Mina Almasry, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Simon Horman, ap420073

skb_frag_address_safe() needs a check that the
skb_frag_page exists check similar to skb_frag_address().

Cc: ap420073@gmail.com

Signed-off-by: Mina Almasry <almasrymina@google.com>
---
 include/linux/skbuff.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 5520524c93bf..9d551845e517 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -3665,7 +3665,12 @@ static inline void *skb_frag_address(const skb_frag_t *frag)
  */
 static inline void *skb_frag_address_safe(const skb_frag_t *frag)
 {
-	void *ptr = page_address(skb_frag_page(frag));
+	void *ptr;
+
+	if (!skb_frag_page(frag))
+		return NULL;
+
+	ptr = page_address(skb_frag_page(frag));
 	if (unlikely(!ptr))
 		return NULL;
 

base-commit: 7b4ac12cc929e281cf7edc22203e0533790ebc2b
-- 
2.50.0.rc2.696.g1fc2a0284f-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH net v1] netmem: fix skb_frag_address_safe with unreadable skbs
  2025-06-17 21:09 [PATCH net v1] netmem: fix skb_frag_address_safe with unreadable skbs Mina Almasry
@ 2025-06-17 21:15 ` Mina Almasry
  2025-06-17 21:30   ` Stanislav Fomichev
  2025-06-18 21:53 ` Jakub Kicinski
  1 sibling, 1 reply; 7+ messages in thread
From: Mina Almasry @ 2025-06-17 21:15 UTC (permalink / raw)
  To: netdev, linux-kernel
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Simon Horman, ap420073

On Tue, Jun 17, 2025 at 2:09 PM Mina Almasry <almasrymina@google.com> wrote:
>
> skb_frag_address_safe() needs a check that the
> skb_frag_page exists check similar to skb_frag_address().
>
> Cc: ap420073@gmail.com
>

Sorry, I realized right after hitting send, I'm missing:

Fixes: 9f6b619edf2e ("net: support non paged skb frags")

I can respin after the 24hr cooldown.

-- 
Thanks,
Mina

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net v1] netmem: fix skb_frag_address_safe with unreadable skbs
  2025-06-17 21:15 ` Mina Almasry
@ 2025-06-17 21:30   ` Stanislav Fomichev
  2025-06-17 21:52     ` Mina Almasry
  0 siblings, 1 reply; 7+ messages in thread
From: Stanislav Fomichev @ 2025-06-17 21:30 UTC (permalink / raw)
  To: Mina Almasry
  Cc: netdev, linux-kernel, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, ap420073

On 06/17, Mina Almasry wrote:
> On Tue, Jun 17, 2025 at 2:09 PM Mina Almasry <almasrymina@google.com> wrote:
> >
> > skb_frag_address_safe() needs a check that the
> > skb_frag_page exists check similar to skb_frag_address().
> >
> > Cc: ap420073@gmail.com
> >
> 
> Sorry, I realized right after hitting send, I'm missing:
> 
> Fixes: 9f6b619edf2e ("net: support non paged skb frags")
> 
> I can respin after the 24hr cooldown.

The function is used in five drivers, none of which support devmem tx,
does not look like there is a reason to route it via net.

The change it self looks good, but not really sure it's needed.
skb_frag_address_safe is used in some pass-data-via-descriptor-ring mode,
I don't see 'modern' drivers (besides bnxt which added this support in 2015)
use it.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net v1] netmem: fix skb_frag_address_safe with unreadable skbs
  2025-06-17 21:30   ` Stanislav Fomichev
@ 2025-06-17 21:52     ` Mina Almasry
  2025-06-18 21:27       ` Jakub Kicinski
  0 siblings, 1 reply; 7+ messages in thread
From: Mina Almasry @ 2025-06-17 21:52 UTC (permalink / raw)
  To: Stanislav Fomichev
  Cc: netdev, linux-kernel, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, ap420073

On Tue, Jun 17, 2025 at 2:30 PM Stanislav Fomichev <stfomichev@gmail.com> wrote:
>
> On 06/17, Mina Almasry wrote:
> > On Tue, Jun 17, 2025 at 2:09 PM Mina Almasry <almasrymina@google.com> wrote:
> > >
> > > skb_frag_address_safe() needs a check that the
> > > skb_frag_page exists check similar to skb_frag_address().
> > >
> > > Cc: ap420073@gmail.com
> > >
> >
> > Sorry, I realized right after hitting send, I'm missing:
> >
> > Fixes: 9f6b619edf2e ("net: support non paged skb frags")
> >
> > I can respin after the 24hr cooldown.
>
> The function is used in five drivers, none of which support devmem tx,
> does not look like there is a reason to route it via net.
>
> The change it self looks good, but not really sure it's needed.
> skb_frag_address_safe is used in some pass-data-via-descriptor-ring mode,
> I don't see 'modern' drivers (besides bnxt which added this support in 2015)
> use it.

Meh, a judgement call could be made here.  I've generally tried to
make sure skb helpers are (unreadable) netmem compatible without a
thorough analysis of all the callers to make sure they do or will one
day use (unreadable) netmem. Seems better to me to fix this before
some code path that plumbs unreadable memory to the helper is actually
merged and that code starts crashing.

Similarly I put this in net because it's a fix and not a feature. I
can send to net-next if preferred.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net v1] netmem: fix skb_frag_address_safe with unreadable skbs
  2025-06-17 21:52     ` Mina Almasry
@ 2025-06-18 21:27       ` Jakub Kicinski
  2025-06-18 21:38         ` Stanislav Fomichev
  0 siblings, 1 reply; 7+ messages in thread
From: Jakub Kicinski @ 2025-06-18 21:27 UTC (permalink / raw)
  To: Mina Almasry, Stanislav Fomichev
  Cc: netdev, linux-kernel, David S. Miller, Eric Dumazet, Paolo Abeni,
	Simon Horman, ap420073

On Tue, 17 Jun 2025 14:52:17 -0700 Mina Almasry wrote:
> > > Sorry, I realized right after hitting send, I'm missing:
> > >
> > > Fixes: 9f6b619edf2e ("net: support non paged skb frags")
> > >
> > > I can respin after the 24hr cooldown.  
> >
> > The function is used in five drivers, none of which support devmem tx,
> > does not look like there is a reason to route it via net.
> >
> > The change it self looks good, but not really sure it's needed.
> > skb_frag_address_safe is used in some pass-data-via-descriptor-ring mode,
> > I don't see 'modern' drivers (besides bnxt which added this support in 2015)
> > use it.  
> 
> Meh, a judgement call could be made here.  I've generally tried to
> make sure skb helpers are (unreadable) netmem compatible without a
> thorough analysis of all the callers to make sure they do or will one
> day use (unreadable) netmem. Seems better to me to fix this before
> some code path that plumbs unreadable memory to the helper is actually
> merged and that code starts crashing.

Fair points, tho I prefer the simple heuristic of "can it trigger on
net", otherwise it's really easy to waste time pondering each single
patch. I'll apply to net-next as is. Stanislav, do you want to ack?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net v1] netmem: fix skb_frag_address_safe with unreadable skbs
  2025-06-18 21:27       ` Jakub Kicinski
@ 2025-06-18 21:38         ` Stanislav Fomichev
  0 siblings, 0 replies; 7+ messages in thread
From: Stanislav Fomichev @ 2025-06-18 21:38 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Mina Almasry, netdev, linux-kernel, David S. Miller, Eric Dumazet,
	Paolo Abeni, Simon Horman, ap420073

On 06/18, Jakub Kicinski wrote:
> On Tue, 17 Jun 2025 14:52:17 -0700 Mina Almasry wrote:
> > > > Sorry, I realized right after hitting send, I'm missing:
> > > >
> > > > Fixes: 9f6b619edf2e ("net: support non paged skb frags")
> > > >
> > > > I can respin after the 24hr cooldown.  
> > >
> > > The function is used in five drivers, none of which support devmem tx,
> > > does not look like there is a reason to route it via net.
> > >
> > > The change it self looks good, but not really sure it's needed.
> > > skb_frag_address_safe is used in some pass-data-via-descriptor-ring mode,
> > > I don't see 'modern' drivers (besides bnxt which added this support in 2015)
> > > use it.  
> > 
> > Meh, a judgement call could be made here.  I've generally tried to
> > make sure skb helpers are (unreadable) netmem compatible without a
> > thorough analysis of all the callers to make sure they do or will one
> > day use (unreadable) netmem. Seems better to me to fix this before
> > some code path that plumbs unreadable memory to the helper is actually
> > merged and that code starts crashing.
> 
> Fair points, tho I prefer the simple heuristic of "can it trigger on
> net", otherwise it's really easy to waste time pondering each single
> patch. I'll apply to net-next as is. Stanislav, do you want to ack?

Sure, SG!

Acked-by: Stanislav Fomichev <sdf@fomichev.me>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net v1] netmem: fix skb_frag_address_safe with unreadable skbs
  2025-06-17 21:09 [PATCH net v1] netmem: fix skb_frag_address_safe with unreadable skbs Mina Almasry
  2025-06-17 21:15 ` Mina Almasry
@ 2025-06-18 21:53 ` Jakub Kicinski
  1 sibling, 0 replies; 7+ messages in thread
From: Jakub Kicinski @ 2025-06-18 21:53 UTC (permalink / raw)
  To: Mina Almasry
  Cc: netdev, linux-kernel, David S. Miller, Eric Dumazet, Paolo Abeni,
	Simon Horman, ap420073

On Tue, 17 Jun 2025 21:09:50 +0000 Mina Almasry wrote:
> +	void *ptr;
> +
> +	if (!skb_frag_page(frag))
> +		return NULL;
> +
> +	ptr = page_address(skb_frag_page(frag));

Sorry, noticed mid-push that we're calling skb_frag_page() twice.
Let's save the return value and pass it to page_address?
-- 
pw-bot: cr

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-06-18 21:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-17 21:09 [PATCH net v1] netmem: fix skb_frag_address_safe with unreadable skbs Mina Almasry
2025-06-17 21:15 ` Mina Almasry
2025-06-17 21:30   ` Stanislav Fomichev
2025-06-17 21:52     ` Mina Almasry
2025-06-18 21:27       ` Jakub Kicinski
2025-06-18 21:38         ` Stanislav Fomichev
2025-06-18 21:53 ` Jakub Kicinski

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).