Replace some calls to fuword() by fueword() with proper error checking.

Sponsored by:	The FreeBSD Foundation
Tested by:	pho
MFC after:	3 weeks
This commit is contained in:
Konstantin Belousov 2014-10-28 15:28:20 +00:00
parent 4f3dc90023
commit 0a2c94b86e
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=273784
6 changed files with 51 additions and 20 deletions

View File

@ -110,7 +110,7 @@ ia32_fetch_syscall_args(struct thread *td, struct syscall_args *sa)
struct proc *p;
struct trapframe *frame;
caddr_t params;
u_int32_t args[8];
u_int32_t args[8], tmp;
int error, i;
p = td->td_proc;
@ -126,7 +126,10 @@ ia32_fetch_syscall_args(struct thread *td, struct syscall_args *sa)
/*
* Code is first argument, followed by actual args.
*/
sa->code = fuword32(params);
error = fueword32(params, &tmp);
if (error == -1)
return (EFAULT);
sa->code = tmp;
params += sizeof(int);
} else if (sa->code == SYS___syscall) {
/*
@ -135,7 +138,10 @@ ia32_fetch_syscall_args(struct thread *td, struct syscall_args *sa)
* We use a 32-bit fetch in case params is not
* aligned.
*/
sa->code = fuword32(params);
error = fueword32(params, &tmp);
if (error == -1)
return (EFAULT);
sa->code = tmp;
params += sizeof(quad_t);
}
if (p->p_sysent->sv_mask)

View File

@ -1832,16 +1832,21 @@ freebsd32_sysctl(struct thread *td, struct freebsd32_sysctl_args *uap)
{
int error, name[CTL_MAXNAME];
size_t j, oldlen;
uint32_t tmp;
if (uap->namelen > CTL_MAXNAME || uap->namelen < 2)
return (EINVAL);
error = copyin(uap->name, name, uap->namelen * sizeof(int));
if (error)
return (error);
if (uap->oldlenp)
oldlen = fuword32(uap->oldlenp);
else
if (uap->oldlenp) {
error = fueword32(uap->oldlenp, &tmp);
oldlen = tmp;
} else {
oldlen = 0;
}
if (error != 0)
return (EFAULT);
error = userland_sysctl(td, name, uap->namelen,
uap->old, &oldlen, 1,
uap->new, uap->newlen, &j, SCTL_MASK32);

View File

@ -1059,6 +1059,7 @@ cpu_fetch_syscall_args(struct thread *td, struct syscall_args *sa)
struct proc *p;
struct trapframe *frame;
caddr_t params;
long tmp;
int error;
p = td->td_proc;
@ -1074,14 +1075,20 @@ cpu_fetch_syscall_args(struct thread *td, struct syscall_args *sa)
/*
* Code is first argument, followed by actual args.
*/
sa->code = fuword(params);
error = fueword(params, &tmp);
if (error == -1)
return (EFAULT);
sa->code = tmp;
params += sizeof(int);
} else if (sa->code == SYS___syscall) {
/*
* Like syscall, but code is a quad, so as to maintain
* quad alignment for the rest of the arguments.
*/
sa->code = fuword(params);
error = fueword(params, &tmp);
if (error == -1)
return (EFAULT);
sa->code = tmp;
params += sizeof(quad_t);
}

View File

@ -1091,7 +1091,7 @@ int
exec_copyin_args(struct image_args *args, char *fname,
enum uio_seg segflg, char **argv, char **envv)
{
char *argp, *envp;
u_long argp, envp;
int error;
size_t length;
@ -1127,13 +1127,17 @@ exec_copyin_args(struct image_args *args, char *fname,
/*
* extract arguments first
*/
while ((argp = (caddr_t) (intptr_t) fuword(argv++))) {
if (argp == (caddr_t) -1) {
for (;;) {
error = fueword(argv++, &argp);
if (error == -1) {
error = EFAULT;
goto err_exit;
}
if ((error = copyinstr(argp, args->endp,
args->stringspace, &length))) {
if (argp == 0)
break;
error = copyinstr((void *)(uintptr_t)argp, args->endp,
args->stringspace, &length);
if (error != 0) {
if (error == ENAMETOOLONG)
error = E2BIG;
goto err_exit;
@ -1149,13 +1153,17 @@ exec_copyin_args(struct image_args *args, char *fname,
* extract environment strings
*/
if (envv) {
while ((envp = (caddr_t)(intptr_t)fuword(envv++))) {
if (envp == (caddr_t)-1) {
for (;;) {
error = fueword(envv++, &envp);
if (error == -1) {
error = EFAULT;
goto err_exit;
}
if ((error = copyinstr(envp, args->endp,
args->stringspace, &length))) {
if (envp == 0)
break;
error = copyinstr((void *)(uintptr_t)envp,
args->endp, args->stringspace, &length);
if (error != 0) {
if (error == ENAMETOOLONG)
error = E2BIG;
goto err_exit;

View File

@ -148,6 +148,7 @@ acl_copyin(void *user_acl, struct acl *kernel_acl, acl_type_t type)
static int
acl_copyout(struct acl *kernel_acl, void *user_acl, acl_type_t type)
{
uint32_t am;
int error;
struct oldacl old;
@ -162,8 +163,11 @@ acl_copyout(struct acl *kernel_acl, void *user_acl, acl_type_t type)
break;
default:
if (fuword32((char *)user_acl +
offsetof(struct acl, acl_maxcnt)) != ACL_MAX_ENTRIES)
error = fueword32((char *)user_acl +
offsetof(struct acl, acl_maxcnt), &am);
if (error == -1)
return (EFAULT);
if (am != ACL_MAX_ENTRIES)
return (EINVAL);
error = copyout(kernel_acl, user_acl, sizeof(*kernel_acl));

View File

@ -5060,7 +5060,8 @@ sppp_params(struct sppp *sp, u_long cmd, void *data)
* Check the cmd word first before attempting to fetch all the
* data.
*/
if ((subcmd = fuword(ifr->ifr_data)) == -1) {
rv = fueword(ifr->ifr_data, &subcmd);
if (rv == -1) {
rv = EFAULT;
goto quit;
}