1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
/*
* iovec manipulation routines.
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* Fixes:
* Andrew Lunn : Errors in iovec copying.
*/
#include <linux/errno.h>
#include <linux/sched.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/net.h>
#include <asm/segment.h>
extern inline int min(int x, int y)
{
return x>y?y:x;
}
int verify_iovec(struct msghdr *m, struct iovec *iov, char *address, int mode)
{
int err=0;
int len=0;
int ct;
if(m->msg_name!=NULL)
{
if(mode==VERIFY_READ) {
err=move_addr_to_kernel(m->msg_name, m->msg_namelen, address);
} else
err=verify_area(mode, m->msg_name, m->msg_namelen);
if(err<0)
return err;
m->msg_name = address;
}
if(m->msg_control!=NULL)
{
err=verify_area(mode, m->msg_control, m->msg_controllen);
if(err)
return err;
}
for(ct=0;ct<m->msg_iovlen;ct++)
{
err=verify_area(VERIFY_READ, &m->msg_iov[ct], sizeof(struct iovec));
if(err)
return err;
memcpy_fromfs(&iov[ct], &m->msg_iov[ct], sizeof(struct iovec));
err=verify_area(mode, iov[ct].iov_base, iov[ct].iov_len);
if(err)
return err;
len+=iov[ct].iov_len;
}
m->msg_iov=&iov[0];
return len;
}
/*
* Copy kernel to iovec.
*/
void memcpy_toiovec(struct iovec *iov, unsigned char *kdata, int len)
{
while(len>0)
{
if(iov->iov_len)
{
int copy = min(iov->iov_len,len);
memcpy_tofs(iov->iov_base,kdata,copy);
kdata+=copy;
len-=copy;
iov->iov_len-=copy;
iov->iov_base+=copy;
}
iov++;
}
}
/*
* Copy iovec to kernel.
*/
void memcpy_fromiovec(unsigned char *kdata, struct iovec *iov, int len)
{
while(len>0)
{
if(iov->iov_len)
{
int copy=min(len,iov->iov_len);
memcpy_fromfs(kdata, iov->iov_base, copy);
len-=copy;
kdata+=copy;
iov->iov_base+=copy;
iov->iov_len-=copy;
}
iov++;
}
}
|