Skip to contentSkip to conversation

bpf: Fix bpf_xdp_pointer return pointer

PATCH Applied Joanne Koong 5 participants 6 messages Jul 22, 2022 – Jul 26, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpf: Fix bpf_xdp_pointer return pointer

For the case where offset + len == size, bpf_xdp_pointer should return a valid pointer to the addr because that access is permitted. We should only return NULL in the case where offset + len exceeds size.

Fixes 3f364222d032 ("net: xdp: introduce bpf_xdp_pointer utility routine")
---
 net/core/filter.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/filter.c +1 -1
index 289614887ed5..4307a75eeb4c 100644
@@ -3918,7 +3918,7 @@ static void *bpf_xdp_pointer(struct xdp_buff *xdp, u32 offset, u32 len)
 		offset -= frag_size;
 	}
 out:
-	return offset + len < size ? addr + offset : NULL;
+	return offset + len <= size ? addr + offset : NULL;
 }
 
 BPF_CALL_4(bpf_xdp_load_bytes, struct xdp_buff *, xdp, u32, offset,
Signature · 1 line
2.30.2
Acked-by on v1 1/1
#1 lore raw
Quoted 15 lines · Joanne Koong

For the case where offset + len == size, bpf_xdp_pointer should return a valid pointer to the addr because that access is permitted. We should only return NULL in the case where offset + len exceeds size.

Fixes 3f364222d032 ("net: xdp: introduce bpf_xdp_pointer utility routine")
---
 net/core/filter.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/filter.c +0 -0
index 289614887ed5..4307a75eeb4c 100644

net/core/filter.c static void *bpf_xdp_pointer(struct xdp_buff *xdp, u32 offset, u32 len) · line 3921

Quoted 5 lines
net/core/filter.c +1 -1
@@ -3918,7 +3918,7 @@ static void *bpf_xdp_pointer(struct xdp_buff *xdp, u32 offset, u32 len)
 		offset -= frag_size;
 	}
 out:
-	return offset + len < size ? addr + offset : NULL;
+	return offset + len <= size ? addr + offset : NULL;

This fix should be for the bpf tree.

#2 lore raw
Quoted 12 lines · Martin KaFai Lau
Quoted 10 lines · Joanne Koong

For the case where offset + len == size, bpf_xdp_pointer should return a valid pointer to the addr because that access is permitted. We should only return NULL in the case where offset + len exceeds size.

Fixes 3f364222d032 ("net: xdp: introduce bpf_xdp_pointer utility routine")
---
 net/core/filter.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 11 lines

net/core/filter.c static void *bpf_xdp_pointer(struct xdp_buff *xdp, u32 offset, u32 len) · line 3921

Quoted 10 lines
net/core/filter.c +1 -1
index 289614887ed5..4307a75eeb4c 100644
@@ -3918,7 +3918,7 @@ static void *bpf_xdp_pointer(struct xdp_buff *xdp, u32 offset, u32 len)
              offset -= frag_size;
      }
 out:
-     return offset + len < size ? addr + offset : NULL;
+     return offset + len <= size ? addr + offset : NULL;

This fix should be for the bpf tree.

Ah I see. To confirm my understanding, fixes should always go to the bpf tree (unless it's fixing a patch that only resides in the bpf-next tree), correct?

Quoted 2 lines
maintainer
#3 lore raw
Quoted 24 lines · Joanne Koong
Quoted 12 lines · Martin KaFai Lau
Quoted 10 lines · Joanne Koong

For the case where offset + len == size, bpf_xdp_pointer should return a valid pointer to the addr because that access is permitted. We should only return NULL in the case where offset + len exceeds size.

Fixes 3f364222d032 ("net: xdp: introduce bpf_xdp_pointer utility routine")
---
  net/core/filter.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 11 lines

net/core/filter.c static void *bpf_xdp_pointer(struct xdp_buff *xdp, u32 offset, u32 len) · line 3921

Quoted 10 lines
net/core/filter.c +1 -1
index 289614887ed5..4307a75eeb4c 100644
@@ -3918,7 +3918,7 @@ static void *bpf_xdp_pointer(struct xdp_buff *xdp, u32 offset, u32 len)
               offset -= frag_size;
       }
  out:
-     return offset + len < size ? addr + offset : NULL;
+     return offset + len <= size ? addr + offset : NULL;

This fix should be for the bpf tree.

Quoted 3 lines

Ah I see. To confirm my understanding, fixes should always go to the bpf tree (unless it's fixing a patch that only resides in the bpf-next tree), correct?

Yes, correct. Given we're really late in the cycle with rc8 my preference is to only queue really urgent fixes to bpf tree at this point. This one I just took to bpf-next given merge window is opening this Sun, thus this will go to Linus' tree with just few days offset anyway.

Thanks,
Daniel

Acked-by on v1 1/1
#4 lore raw
In reply to Joanne Koong
Quoted 26 lines

For the case where offset + len == size, bpf_xdp_pointer should return a valid pointer to the addr because that access is permitted. We should only return NULL in the case where offset + len exceeds size.

Fixes 3f364222d032 ("net: xdp: introduce bpf_xdp_pointer utility routine")
---
 net/core/filter.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/filter.c +1 -1
index 289614887ed5..4307a75eeb4c 100644
@@ -3918,7 +3918,7 @@ static void *bpf_xdp_pointer(struct xdp_buff *xdp, u32 offset, u32 len)
 		offset -= frag_size;
 	}
 out:
-	return offset + len < size ? addr + offset : NULL;
+	return offset + len <= size ? addr + offset : NULL;
 }
 
 BPF_CALL_4(bpf_xdp_load_bytes, struct xdp_buff *, xdp, u32, offset,
Signature · 1 line
2.30.2
#5 lore raw
In reply to Joanne Koong
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:

Quoted 8 lines · On Fri, 22 Jul 2022 15:01:05 -0700 you wrote:

For the case where offset + len == size, bpf_xdp_pointer should return a valid pointer to the addr because that access is permitted. We should only return NULL in the case where offset + len exceeds size.

Fixes 3f364222d032 ("net: xdp: introduce bpf_xdp_pointer utility routine")

[...]

Here is the summary with links:
- [bpf-next,v1,1/1] bpf: Fix bpf_xdp_pointer return pointer

    https://git.kernel.org/bpf/bpf-next/c/bbd52178e249

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html