Subject: Re: COPYIN/COPYOUT macro problems Re: IOCTL implementation and kernel/userland addresses
To: Jason Thorpe <thorpej@shagadelic.org>
From: Reinoud Zandijk <reinoud@netbsd.org>
List: tech-kern
Date: 08/25/2005 22:14:00
--a+b56+3nqLzpiR9O
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Dear folks,

On Thu, Aug 25, 2005 at 12:44:52PM -0700, Jason Thorpe wrote:
> No, kcopy() is NOT aliased to memcpy().  It performs similar error  
> checking to copyin()/copyout().

*sigh* where was my mind.

> >We could opt for a more generic kcopyin() function :
> >
> >int kucopyin(int kernelspace, void *uaddr, void *kaddr, int len) {
> 
> void *from, void *to, size_t len
> 
> >int retval;
> >
> >if (!kernelspace) {
> >return copyin(uaddr, kaddr, len);
> >};
> >
> >/*
> >* returning anything other than 0 is meaningless for it would have
> >* panicked the kernel allready if the address was not valid.
> >*/
> >kcopy(uaddr, kaddr, len);
> >return 0;
> 
> No, return the error here.  kcopy() is defined to return an error  
> code, and will.  UBC relies on this.

ok.

> >where the flag `kernelspace' being non-zero means use in-kernel  
> >transfers.
> >This way checking for the FKIOCTL flag and/or using uio's uio_seg {
> >UIO_USERSPACE, UIO_SYSSPACE } would be consistent.
> 
> I would prefer to see the UIO_*SPACE enums to be used, rather than  
> just a boolean.

but then you loose the advantage of just calling
	kucopyin(flags & KFIOCTL, from, to, len);
	kucopyin(uio.uio_segflg == UIO_SYSSPACE, from, to, len);
	kucopyin(ISSET(flags, ...), from, to, len);
or even 
	kucopyin(uio.uio_segflg, from, to, len);
when its allowed to make the assumption that UIO_SYSSPACE != 0.

or go for `aliases' that check specific values in
	ioctl_copyin(flag, ...)
	uio_copyin(flag, ...)
functions.

thoughts?
Reinoud

--a+b56+3nqLzpiR9O
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (NetBSD)

iQEVAwUBQw4mgIKcNwBDyKpoAQI3Dgf/Zcf3t/43C6lhetZULuLfJBy5WX/4w1IG
V2qGf25oqjZvfVO8ZZ8/4mNwzl/E+/nAVY5YW0TmxgRG7DqIIOPOor2VbbfxWbeV
FZ3yH8i8w9iTEnRt+yj0/VOtGfB/Qkm+9TABtFYvyqmYAdPLsdKC5Cy7aW1Y5gPf
XPwV9Ps/l4MwVKRaLAbteFvx5FHmZASeqD43IKT+9rn9rK8EG8BU+/nV6UmSkHqD
c+wTa+cbvsTRbJPvFLARjo4ka5ipVs+FZgxJlEjOIoWt80/g4e6S4PCAo3pFJtlh
Cs8dtsUu4G7aL7vfOy1C5pA9zPtHeviykWZ9Ixkh/MEYgTrnFmGipw==
=metW
-----END PGP SIGNATURE-----

--a+b56+3nqLzpiR9O--