On 17-11-2022 13:13, Zachary Leaf wrote:
On 16/11/2022 15:01, Tudor Cretu wrote:
On 15-11-2022 09:08, Zachary Leaf wrote:
In PCuABI, when copying a block of memory from userspace containing capabilities/pointers, the copy_from_user_with_ptr variant needs to be used to ensure pointers are preserved in full.
Introduce copy_from_x_with_ptr methods for bpfptr_t and sockptr_t to support this.
Is there a reason on why this is not done to copy_to_x functions as well?
Only because I didn't come across anywhere it's required yet, and as a general principle I'd usually try avoid adding any code that "might" be needed, just because of the added maintenance/testing burden etc.
Since this is just the RFC looking at BPF_PROG_LOAD, if it comes up when adding the other options we can add it to this commit then.
Ack.
Signed-off-by: Zachary Leaf zachary.leaf@arm.com
include/linux/bpfptr.h | 11 +++++++++++ include/linux/sockptr.h | 9 +++++++++ 2 files changed, 20 insertions(+)
diff --git a/include/linux/bpfptr.h b/include/linux/bpfptr.h index 46e1757d06a3..abb5b3641f5d 100644 --- a/include/linux/bpfptr.h +++ b/include/linux/bpfptr.h @@ -52,11 +52,22 @@ static inline int copy_from_bpfptr_offset(void *dst, bpfptr_t src, return copy_from_sockptr_offset(dst, (sockptr_t) src, offset, size); } +static inline int copy_from_bpfptr_offset_with_ptr(void *dst,
^ here
bpfptr_t src, + size_t offset, size_t size) +{ + return copy_from_sockptr_offset_with_ptr(dst, (sockptr_t) src, offset, size); +}
static inline int copy_from_bpfptr(void *dst, bpfptr_t src, size_t size) { return copy_from_bpfptr_offset(dst, src, 0, size); } +static inline int copy_from_bpfptr_with_ptr(void *dst, bpfptr_t src, size_t size) +{ + return copy_from_bpfptr_offset_with_ptr(dst, src, 0, size);
copy_from_bpfptr_offset_with_ptr is missing from this patch I think...
Is it not above?
Indeed, might've been tired, sorry about that!
Thanks, Tudor
Thanks, Zach
+}
static inline int copy_to_bpfptr_offset(bpfptr_t dst, size_t offset, const void *src, size_t size) { diff --git a/include/linux/sockptr.h b/include/linux/sockptr.h index ea193414298b..e07da559327f 100644 --- a/include/linux/sockptr.h +++ b/include/linux/sockptr.h @@ -50,6 +50,15 @@ static inline int copy_from_sockptr_offset(void *dst, sockptr_t src, return 0; } +static inline int copy_from_sockptr_offset_with_ptr(void *dst, sockptr_t src, + size_t offset, size_t size) +{ + if (!sockptr_is_kernel(src)) + return copy_from_user_with_ptr(dst, src.user + offset, size); + memcpy(dst, src.kernel + offset, size); + return 0; +}
static inline int copy_from_sockptr(void *dst, sockptr_t src, size_t size) { return copy_from_sockptr_offset(dst, src, 0, size);
linux-morello mailing list -- linux-morello@op-lists.linaro.org To unsubscribe send an email to linux-morello-leave@op-lists.linaro.org