From: Ben Gras Date: Tue, 20 Jun 2006 09:46:57 +0000 (+0000) Subject: safe conversion X-Git-Tag: v3.1.3~326 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/jhe061.png?a=commitdiff_plain;h=b80626c878525b2485dbab61693dffeba51c6a2e;p=minix.git safe conversion --- diff --git a/drivers/random/Makefile b/drivers/random/Makefile index 59838480f..11e630d0e 100644 --- a/drivers/random/Makefile +++ b/drivers/random/Makefile @@ -14,7 +14,7 @@ MAKE = exec make CC = exec cc CFLAGS = -I$i LDFLAGS = -i -LIBS = -lsys -lsysutil +LIBS = -lsysutil -lsys OBJ = main.o random.o sha2.o aes/rijndael_api.o aes/rijndael_alg.o LIBDRIVER = $d/libdriver/driver.o diff --git a/drivers/random/main.c b/drivers/random/main.c index eca3990de..5d79dc1f2 100644 --- a/drivers/random/main.c +++ b/drivers/random/main.c @@ -26,10 +26,10 @@ extern int errno; /* error number for PM calls */ FORWARD _PROTOTYPE( char *r_name, (void) ); FORWARD _PROTOTYPE( struct device *r_prepare, (int device) ); FORWARD _PROTOTYPE( int r_transfer, (int proc_nr, int opcode, off_t position, - iovec_t *iov, unsigned nr_req) ); + iovec_t *iov, unsigned nr_req, int safe) ); FORWARD _PROTOTYPE( int r_do_open, (struct driver *dp, message *m_ptr) ); FORWARD _PROTOTYPE( void r_init, (void) ); -FORWARD _PROTOTYPE( int r_ioctl, (struct driver *dp, message *m_ptr) ); +FORWARD _PROTOTYPE( int r_ioctl, (struct driver *dp, message *m_ptr, int safe) ); FORWARD _PROTOTYPE( void r_geometry, (struct partition *entry) ); FORWARD _PROTOTYPE( void r_random, (struct driver *dp, message *m_ptr) ); @@ -92,18 +92,20 @@ int device; /*===========================================================================* * r_transfer * *===========================================================================*/ -PRIVATE int r_transfer(proc_nr, opcode, position, iov, nr_req) +PRIVATE int r_transfer(proc_nr, opcode, position, iov, nr_req, safe) int proc_nr; /* process doing the request */ int opcode; /* DEV_GATHER or DEV_SCATTER */ off_t position; /* offset on device to read or write */ iovec_t *iov; /* pointer to read or write request vector */ unsigned nr_req; /* length of request vector */ +int safe; /* safe copies? */ { /* Read or write one the driver's minor devices. */ unsigned count, left, chunk; vir_bytes user_vir; struct device *dv; unsigned long dv_size; + size_t vir_offset = 0; /* Get minor device number and check for /dev/null. */ dv = &m_geom[m_device]; @@ -126,14 +128,24 @@ unsigned nr_req; /* length of request vector */ chunk = (left > RANDOM_BUF_SIZE) ? RANDOM_BUF_SIZE : left; if (opcode == DEV_GATHER) { random_getbytes(random_buf, chunk); - sys_vircopy(SELF, D, (vir_bytes) random_buf, - proc_nr, D, user_vir, chunk); + if(safe) { + sys_safecopyto(proc_nr, user_vir, vir_offset, + (vir_bytes) random_buf, chunk, D); + } else { + sys_vircopy(SELF, D, (vir_bytes) random_buf, + proc_nr, D, user_vir + vir_offset, chunk); + } } else if (opcode == DEV_SCATTER) { - sys_vircopy(proc_nr, D, user_vir, + if(safe) { + sys_safecopyfrom(proc_nr, user_vir, vir_offset, + (vir_bytes) random_buf, chunk, D); + } else { + sys_vircopy(proc_nr, D, user_vir + vir_offset, SELF, D, (vir_bytes) random_buf, chunk); - random_putbytes(random_buf, chunk); + } + random_putbytes(random_buf, chunk); } - user_vir += chunk; + vir_offset += chunk; left -= chunk; } break; @@ -145,8 +157,7 @@ unsigned nr_req; /* length of request vector */ /* Book the number of bytes transferred. */ position += count; - iov->iov_addr += count; - if ((iov->iov_size -= count) == 0) { iov++; nr_req--; } + if ((iov->iov_size -= count) == 0) { iov++; nr_req--; vir_offset = 0; } } return(OK); @@ -179,9 +190,10 @@ PRIVATE void r_init() /*===========================================================================* * r_ioctl * *===========================================================================*/ -PRIVATE int r_ioctl(dp, m_ptr) +PRIVATE int r_ioctl(dp, m_ptr, safe) struct driver *dp; /* pointer to driver structure */ message *m_ptr; /* pointer to control message */ +int safe; /* safe i/o? */ { struct device *dv; if ((dv = r_prepare(m_ptr->DEVICE)) == NIL_DEV) return(ENXIO); @@ -189,7 +201,7 @@ message *m_ptr; /* pointer to control message */ switch (m_ptr->REQUEST) { default: - return(do_diocntl(&r_dtab, m_ptr)); + return(do_diocntl(&r_dtab, m_ptr, safe)); } return(OK); }