Skip to content

sockptr: Change sockptr_t to be a struct

David Laight netdev 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest4 patches 1 replyIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4net: Use sockptr_is_kernel() instead of testing is_kernelnet/ipv4/ip_sockglue.c net/ipv6/ipv6_sockglue.c net/socket.c+3 -30 replies
2/4bpf: Use bpfptr_is_kernel() instead of checking the is_kernel member.kernel/bpf/bpf_iter.c kernel/bpf/btf.c kernel/bpf/syscall.c +1 more+13 -130 replies
3/4bpf: Use the sockptr_t helpersinclude/linux/bpfptr.h+4 -60 replies
4/4sockptr: Change sockptr_t to be a struct of a kernel and user pointer.include/linux/sockptr.h+5 -100 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH net-next 0/4] sockptr: Change sockptr_t to be a struct

The original commit for sockptr_t tried to use the pointer value to determine whether a pointer was user or kernel.
This can't work on some architectures and was buggy on x86. So the is_kernel discriminator was added after the union of pointers.

However this is still open to misuse and accidents.
Replace the union with a struct and remove the is_kernel member. The user and kernel values are now in different places.
The structure size doesn't change - it was always padded out to 'two pointers'.

The only functional difference is that NULL pointers are always 'user'. So dereferencing will (usually) fault in copy_from_user() rather than panic if supplied as a kernel address.

Simple driver code that uses kernel sockets still works. I've not tested bpf - but that should work unless it is breaking the rules.

The first three patches just change the code to use the helpers from sockptr.h.
The functional change is in the fourth patch.

David Laight (4):
Use sockptr_is_kernel() instead of testing is_kernel. Use bpfptr_is_kernel() instead of checking the is_kernel member. Use the sockptr_t helpers.
Change sockptr_t to be a struct of a kernel and user pointer.

 include/linux/bpfptr.h   | 10 ++++------
 include/linux/sockptr.h  | 15 +++++----------
 kernel/bpf/bpf_iter.c    |  2 +-
 kernel/bpf/btf.c         |  2 +-
 kernel/bpf/syscall.c     | 12 ++++++------
 kernel/bpf/verifier.c    | 10 +++++-----
 net/ipv4/ip_sockglue.c   |  2 +-
 net/ipv6/ipv6_sockglue.c |  2 +-
 net/socket.c             |  2 +-
 9 files changed, 25 insertions(+), 32 deletions(-)
Signature · 5 lines
2.17.1

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)