/*
- * Copyright (c) 2000-2001 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
#include <sys/ktrace.h>
#endif
#include <sys/kernel.h>
+#include <sys/kern_audit.h>
#include <sys/kdebug.h>
#endif
struct getsockname_args {
- int fdes;
+ int fdes;
caddr_t asa;
- int *alen;
+ socklen_t *alen;
};
struct getsockopt_args {
- int s;
- int level;
- int name;
+ int s;
+ int level;
+ int name;
caddr_t val;
- int *avalsize;
+ socklen_t *avalsize;
} ;
struct accept_args {
- int s;
- caddr_t name;
- int *anamelen;
+ int s;
+ caddr_t name;
+ socklen_t *anamelen;
};
struct getpeername_args {
- int fdes;
- caddr_t asa;
- int *alen;
+ int fdes;
+ caddr_t asa;
+ socklen_t *alen;
};
struct file *fp;
int fd, error;
+ AUDIT_ARG(socket, uap->domain, uap->type, uap->protocol);
thread_funnel_switch(NETWORK_FUNNEL, KERNEL_FUNNEL);
error = falloc(p, &fp, &fd);
thread_funnel_switch(KERNEL_FUNNEL, NETWORK_FUNNEL);
}
struct bind_args {
- int s;
- caddr_t name;
- int namelen;
+ int s;
+ caddr_t name;
+ socklen_t namelen;
};
/* ARGSUSED */
struct sockaddr *sa;
int error;
+ AUDIT_ARG(fd, uap->s);
error = getsock(p->p_fd, uap->s, &fp);
if (error)
return (error);
error = getsockaddr(&sa, uap->name, uap->namelen);
if (error)
return (error);
- error = sobind((struct socket *)fp->f_data, sa);
+ AUDIT_ARG(sockaddr, p, sa);
+ if (fp->f_data != NULL)
+ error = sobind((struct socket *)fp->f_data, sa);
+ else
+ error = EBADF;
FREE(sa, M_SONAME);
return (error);
}
struct file *fp;
int error;
+ AUDIT_ARG(fd, uap->s);
error = getsock(p->p_fd, uap->s, &fp);
if (error)
return (error);
- return (solisten((struct socket *)fp->f_data, uap->backlog));
+ if (fp->f_data != NULL)
+ return (solisten((struct socket *)fp->f_data, uap->backlog));
+ else
+ return (EBADF);
}
#ifndef COMPAT_OLDSOCK
short fflag; /* type must match fp->f_flag */
int tmpfd;
+ AUDIT_ARG(fd, uap->s);
if (uap->name) {
error = copyin((caddr_t)uap->anamelen, (caddr_t)&namelen,
sizeof (namelen));
return (error);
s = splnet();
head = (struct socket *)fp->f_data;
+ if (head == NULL) {
+ splx(s);
+ return (EBADF);
+ }
if ((head->so_options & SO_ACCEPTCONN) == 0) {
splx(s);
return (EINVAL);
goto gotnoname;
return 0;
}
+ AUDIT_ARG(sockaddr, p, sa);
if (uap->name) {
/* check sa_len before it is destroyed */
if (namelen > sa->sa_len)
#endif /* COMPAT_OLDSOCK */
struct connect_args {
- int s;
- caddr_t name;
- int namelen;
+ int s;
+ caddr_t name;
+ socklen_t namelen;
};
/* ARGSUSED */
int
struct sockaddr *sa;
int error, s;
+ AUDIT_ARG(fd, uap->s);
error = getsock(p->p_fd, uap->s, &fp);
if (error)
return (error);
so = (struct socket *)fp->f_data;
+ if (so == NULL)
+ return (EBADF);
if ((so->so_state & SS_NBIO) && (so->so_state & SS_ISCONNECTING))
return (EALREADY);
error = getsockaddr(&sa, uap->name, uap->namelen);
if (error)
return (error);
+ AUDIT_ARG(sockaddr, p, sa);
error = soconnect(so, sa);
if (error)
goto bad;
struct socket *so1, *so2;
int fd, error, sv[2];
+ AUDIT_ARG(socket, uap->domain, uap->type, uap->protocol);
error = socreate(uap->domain, &so1, uap->type, uap->protocol);
if (error)
return (error);
KERNEL_DEBUG(DBG_FNC_SENDIT | DBG_FUNC_END, error,0,0,0,0);
return (error);
}
+ AUDIT_ARG(sockaddr, p, to);
} else
to = 0;
if (mp->msg_control) {
#endif
len = auio.uio_resid;
so = (struct socket *)fp->f_data;
- error = so->so_proto->pr_usrreqs->pru_sosend(so, to, &auio, 0, control,
- flags);
+ if (so == NULL)
+ error = EBADF;
+ else
+ error = so->so_proto->pr_usrreqs->pru_sosend(so, to, &auio, 0, control,
+ flags);
if (error) {
if (auio.uio_resid != len && (error == ERESTART ||
error == EINTR || error == EWOULDBLOCK))
int stat;
KERNEL_DEBUG(DBG_FNC_SENDTO | DBG_FUNC_START, 0,0,0,0,0);
+ AUDIT_ARG(fd, uap->s);
msg.msg_name = uap->to;
msg.msg_namelen = uap->tolen;
int error;
KERNEL_DEBUG(DBG_FNC_SENDMSG | DBG_FUNC_START, 0,0,0,0,0);
+ AUDIT_ARG(fd, uap->s);
if (error = copyin(uap->msg, (caddr_t)&msg, sizeof (msg)))
{
KERNEL_DEBUG(DBG_FNC_SENDMSG | DBG_FUNC_END, error,0,0,0,0);
#endif
len = auio.uio_resid;
so = (struct socket *)fp->f_data;
- error = so->so_proto->pr_usrreqs->pru_soreceive(so, &fromsa, &auio,
- (struct mbuf **)0, mp->msg_control ? &control : (struct mbuf **)0,
- &mp->msg_flags);
+ if (so == NULL)
+ error = EBADF;
+ else
+ error = so->so_proto->pr_usrreqs->pru_soreceive(so, &fromsa, &auio,
+ (struct mbuf **)0, mp->msg_control ? &control : (struct mbuf **)0,
+ &mp->msg_flags);
+ AUDIT_ARG(sockaddr, p, fromsa);
if (error) {
if (auio.uio_resid != len && (error == ERESTART ||
error == EINTR || error == EWOULDBLOCK))
int error;
KERNEL_DEBUG(DBG_FNC_RECVFROM | DBG_FUNC_START, 0,0,0,0,0);
+ AUDIT_ARG(fd, uap->s);
if (uap->fromlenaddr) {
error = copyin((caddr_t)uap->fromlenaddr,
{
uap->flags |= MSG_COMPAT;
- return (recvfrom(p, uap));
+ return (recvfrom(p, uap, retval));
}
#endif
register int error;
KERNEL_DEBUG(DBG_FNC_RECVMSG | DBG_FUNC_START, 0,0,0,0,0);
+ AUDIT_ARG(fd, uap->s);
if (error = copyin((caddr_t)uap->msg, (caddr_t)&msg,
sizeof (msg)))
{
struct file *fp;
int error;
+ AUDIT_ARG(fd, uap->s);
error = getsock(p->p_fd, uap->s, &fp);
if (error)
return (error);
+ if (fp->f_data == NULL)
+ return (EBADF);
return (soshutdown((struct socket *)fp->f_data, uap->how));
}
/* ARGSUSED */
struct setsockopt_args {
- int s;
- int level;
- int name;
- caddr_t val;
- int valsize;
+ int s;
+ int level;
+ int name;
+ caddr_t val;
+ socklen_t valsize;
};
int
struct sockopt sopt;
int error;
+ AUDIT_ARG(fd, uap->s);
if (uap->val == 0 && uap->valsize != 0)
return (EFAULT);
if (uap->valsize < 0)
sopt.sopt_valsize = uap->valsize;
sopt.sopt_p = p;
+ if (fp->f_data == NULL)
+ return (EBADF);
return (sosetopt((struct socket *)fp->f_data, &sopt));
}
sopt.sopt_valsize = (size_t)valsize; /* checked non-negative above */
sopt.sopt_p = p;
+ if (fp->f_data == NULL)
+ return (EBADF);
error = sogetopt((struct socket *)fp->f_data, &sopt);
if (error == 0) {
valsize = sopt.sopt_valsize;
if (error)
return (error);
so = (struct socket *)fp->f_data;
+ if (so == NULL)
+ return (EBADF);
sa = 0;
error = (*so->so_proto->pr_usrreqs->pru_sockaddr)(so, &sa);
if (error)
if (error)
return (error);
so = (struct socket *)fp->f_data;
+ if (so == NULL)
+ return (EBADF);
if ((so->so_state & (SS_ISCONNECTED|SS_ISCONFIRMING)) == 0)
return (ENOTCONN);
error = copyin((caddr_t)uap->alen, (caddr_t)&len, sizeof (len));
if (error)
goto done;
so = (struct socket *)fp->f_data;
+ if (so == NULL) {
+ error = EBADF;
+ goto done;
+ }
if (so->so_type != SOCK_STREAM) {
error = EINVAL;
goto done;