On Thu, May 25, 2023 at 2:55 PM Breno Leitao <leitao@xxxxxxxxxx> wrote: > > Most of the ioctls to net protocols operates directly on userspace > argument (arg). Usually doing get_user()/put_user() directly in the > ioctl callback. This is not flexible, because it is hard to reuse these > functions without passing userspace buffers. > > Change the "struct proto" ioctls to avoid touching userspace memory and > operate on kernel buffers, i.e., all protocol's ioctl callbacks is > adapted to operate on a kernel memory other than on userspace (so, no > more {put,get}_user() and friends being called in the ioctl callback). > diff --git a/include/net/phonet/phonet.h b/include/net/phonet/phonet.h > index 862f1719b523..93705d99f862 100644 > --- a/include/net/phonet/phonet.h > +++ b/include/net/phonet/phonet.h > @@ -109,4 +109,23 @@ void phonet_sysctl_exit(void); > int isi_register(void); > void isi_unregister(void); > > +#ifdef CONFIG_PHONET > +int phonet_sk_ioctl(struct sock *sk, unsigned int cmd, void __user *arg); > + > +static inline bool phonet_is_sk(struct sock *sk) > +{ > + return sk->sk_family == PF_PHONET && sk->sk_protocol == PN_PROTO_PHONET; > +} > +#else > +static inline bool phonet_is_sk(struct sock *sk) > +{ > + return 0; > +} > + > +static inline int phonet_sk_ioctl(struct sock *sk, unsigned int cmd, void __user *arg) > +{ > + return 1; > +} > +#endif > + > PHONET can be built as a module, so I guess the compiler would complain if "CONFIG_PHONET=m" ???