RE: [PATCH 1/1] net: ioctl: Use kernel memory on protocol ioctl callbacks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Willem de Bruijn
> Sent: 19 May 2023 18:05
...
> > Should I stack allocate all the 4 structures sock_skprot_ioctl and pass
> > them to sock_skproto_ioctl_inout() together with the size? (using the
> > original name to avoid confusion - will rename in V2)
> >
> > I mean, writing something as:
> >
> > int sock_skprot_ioctl(struct sock *sk, unsigned int cmd
> >                      void __user *arg`
> > {
> >         struct sioc_vif_req sioc_vif_req_arg;
> >         struct sioc_sg_req sioc_sg_req_arg;
> >         struct sioc_mif_req6 sioc_mif_req6_arg;
> >         struct sioc_sg_req6 sioc_sg_req6_arg;
> >
> >         ..
> >
> >         if (!strcmp(sk->sk_prot->name, "RAW6")) {
> >         switch (cmd) {
> >                case SIOCGETMIFCNT_IN6:
> >                        return sock_skproto_ioctl_inout(sk, cmd,
> >                                arg, &sioc_mif_req6_arg, sizeof(sioc_mif_req6_arg);
> >                case SIOCGETSGCNT_IN6:
> >                        return sock_skproto_ioctl_inout(sk, cmd,
> >                                arg, &sioc_sg_req6_arg, sizeof(sioc_sg_req6_arg));
> >                }
> >        }
> >        ...
> > }
> 
> Slight preference for using braces in the individual case statements
> and defining the variables in that block scope. See for instance
> do_tcp_setsockopt.

Beware of stack bloat especially under KASAN (etc).
It might be better to use a union.
Then the switch statement only need determine the required length.

	David

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




[Index of Archives]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux