Subject: alignment bug in sys_ioctl ?
To: None <tech-kern@netbsd.org>
From: Darren Reed <darrenr@reed.wattle.id.au>
List: tech-kern
Date: 03/14/2000 06:20:03
Is the below patch something we should do for safety reasons ?
My concern is someone assuming that the data pointer passed to
the ioctl handler is actually 32 or 64bit aligned (given we don't
know what was actually passed up)...whilst this may work for us
now, it would seem to me that counting on it not breaking would
be compiler-dependant ...

Darren

*** /sys/kern/sys_generic.c.orig	Wed Mar 15 01:10:11 2000
--- /sys/kern/sys_generic.c	Wed Mar 15 01:11:36 2000
***************
*** 491,497 ****
  	caddr_t data, memp;
  	int tmp;
  #define STK_PARAMS	128
! 	char stkbuf[STK_PARAMS];
  
  	fdp = p->p_fd;
  	if ((u_int)SCARG(uap, fd) >= fdp->fd_nfiles ||
--- 491,497 ----
  	caddr_t data, memp;
  	int tmp;
  #define STK_PARAMS	128
! 	void *stkbuf[STK_PARAMS/sizeof(void *)];
  
  	fdp = p->p_fd;
  	if ((u_int)SCARG(uap, fd) >= fdp->fd_nfiles ||
***************
*** 522,528 ****
  		memp = (caddr_t)malloc((u_long)size, M_IOCTLOPS, M_WAITOK);
  		data = memp;
  	} else
! 		data = stkbuf;
  	if (com&IOC_IN) {
  		if (size) {
  			error = copyin(SCARG(uap, data), data, size);
--- 522,528 ----
  		memp = (caddr_t)malloc((u_long)size, M_IOCTLOPS, M_WAITOK);
  		data = memp;
  	} else
! 		data = (caddr_t)stkbuf;
  	if (com&IOC_IN) {
  		if (size) {
  			error = copyin(SCARG(uap, data), data, size);