34#include "opt_capsicum.h"
36#include "opt_ktrace.h"
40#include <sys/capsicum.h>
41#include <sys/kernel.h>
44#include <sys/sysproto.h>
45#include <sys/malloc.h>
46#include <sys/filedesc.h>
55#include <sys/protosw.h>
56#include <sys/sf_buf.h>
57#include <sys/sysent.h>
58#include <sys/socket.h>
59#include <sys/socketvar.h>
60#include <sys/signalvar.h>
61#include <sys/syscall.h>
62#include <sys/syscallsubr.h>
63#include <sys/sysctl.h>
67#include <sys/ktrace.h>
69#ifdef COMPAT_FREEBSD32
70#include <compat/freebsd32/freebsd32.h>
71#include <compat/freebsd32/freebsd32_syscall.h>
72#include <compat/freebsd32/freebsd32_util.h>
77#include <security/audit/audit.h>
78#include <security/mac/mac_framework.h>
86 SYSCALL_INIT_HELPER_F(sctp_generic_sendmsg, SYF_CAPENABLED),
87 SYSCALL_INIT_HELPER_F(sctp_generic_sendmsg_iov, SYF_CAPENABLED),
88 SYSCALL_INIT_HELPER_F(sctp_generic_recvmsg, SYF_CAPENABLED),
92#ifdef COMPAT_FREEBSD32
93static struct syscall_helper_data sctp32_syscalls[] = {
95 SYSCALL32_INIT_HELPER_COMPAT(sctp_generic_sendmsg),
96 SYSCALL32_INIT_HELPER_COMPAT(sctp_generic_sendmsg_iov),
97 SYSCALL32_INIT_HELPER_COMPAT(sctp_generic_recvmsg),
107 error = syscall_helper_register(
sctp_syscalls, SY_THR_STATIC_KLD);
110#ifdef COMPAT_FREEBSD32
111 error = syscall32_helper_register(sctp32_syscalls, SY_THR_STATIC_KLD);
127#ifdef COMPAT_FREEBSD32
128 error = syscall32_helper_unregister(sctp32_syscalls);
144 struct sctp_peeloff_args
149 struct file *headfp, *nfp = NULL;
150 struct socket *head, *so;
155 AUDIT_ARG_FD(uap->sd);
156 error = getsock_cap(td, uap->sd, cap_rights_init_one(&rights, CAP_PEELOFF),
157 &headfp, &fflag, NULL);
160 head = headfp->f_data;
174 error = falloc(td, &nfp, &fd, 0);
177 td->td_retval[0] = fd;
179 CURVNET_SET(head->so_vnet);
180 so = sopeeloff(head);
185 finit(nfp, fflag, DTYPE_SOCKET, so, &socketops);
189 if (head->so_sigio != NULL)
190 fsetown(fgetown(&head->so_sigio), &so->so_sigio);
198 fdclose(td, nfp, fd);
215 struct sctp_generic_sendmsg_args
227 struct file *fp = NULL;
228 struct sockaddr *to = NULL;
230 struct uio *ktruio = NULL;
237 if (uap->sinfo != NULL) {
238 error = copyin(uap->sinfo, &sinfo, sizeof (sinfo));
244 cap_rights_init_one(&rights, CAP_SEND);
245 if (uap->tolen != 0) {
246 error = getsockaddr(&to, uap->to, uap->tolen);
251 cap_rights_set_one(&rights, CAP_CONNECT);
254 AUDIT_ARG_FD(uap->sd);
255 error = getsock_cap(td, uap->sd, &rights, &fp, NULL, NULL);
259 if (to && (KTRPOINT(td, KTR_STRUCT)))
263 iov[0].iov_base = uap->msg;
264 iov[0].iov_len = uap->mlen;
266 so = (
struct socket *)fp->f_data;
272 error = mac_socket_check_send(td->td_ucred, so);
279 auio.uio_segflg = UIO_USERSPACE;
280 auio.uio_rw = UIO_WRITE;
285 if (KTRPOINT(td, KTR_GENIO))
286 ktruio = cloneuio(&auio);
288 len = auio.uio_resid = uap->mlen;
289 CURVNET_SET(so->so_vnet);
291 (
struct mbuf *)NULL, uap->flags, u_sinfo, td);
294 if (auio.uio_resid != len && (error == ERESTART ||
295 error == EINTR || error == EWOULDBLOCK))
298 if (error == EPIPE && !(so->so_options & SO_NOSIGPIPE) &&
299 !(uap->flags & MSG_NOSIGNAL)) {
300 PROC_LOCK(td->td_proc);
301 tdsignal(td, SIGPIPE);
302 PROC_UNLOCK(td->td_proc);
306 td->td_retval[0] = len - auio.uio_resid;
308 if (ktruio != NULL) {
309 ktruio->uio_resid = td->td_retval[0];
310 ktrgenio(uap->sd, UIO_WRITE, ktruio, error);
324 struct sctp_generic_sendmsg_iov_args
336 struct file *fp = NULL;
337 struct sockaddr *to = NULL;
339 struct uio *ktruio = NULL;
342 struct iovec *iov, *tiov;
347 if (uap->sinfo != NULL) {
348 error = copyin(uap->sinfo, &sinfo, sizeof (sinfo));
353 cap_rights_init_one(&rights, CAP_SEND);
354 if (uap->tolen != 0) {
355 error = getsockaddr(&to, uap->to, uap->tolen);
360 cap_rights_set_one(&rights, CAP_CONNECT);
363 AUDIT_ARG_FD(uap->sd);
364 error = getsock_cap(td, uap->sd, &rights, &fp, NULL, NULL);
368#ifdef COMPAT_FREEBSD32
369 if (SV_CURPROC_FLAG(SV_ILP32))
370 error = freebsd32_copyiniov((
struct iovec32 *)uap->iov,
371 uap->iovlen, &iov, EMSGSIZE);
374 error = copyiniov(uap->iov, uap->iovlen, &iov, EMSGSIZE);
378 if (to && (KTRPOINT(td, KTR_STRUCT)))
382 so = (
struct socket *)fp->f_data;
388 error = mac_socket_check_send(td->td_ucred, so);
394 auio.uio_iovcnt = uap->iovlen;
395 auio.uio_segflg = UIO_USERSPACE;
396 auio.uio_rw = UIO_WRITE;
401 for (i = 0; i <uap->iovlen; i++, tiov++) {
402 if ((auio.uio_resid += tiov->iov_len) < 0) {
408 if (KTRPOINT(td, KTR_GENIO))
409 ktruio = cloneuio(&auio);
411 len = auio.uio_resid;
412 CURVNET_SET(so->so_vnet);
414 (
struct mbuf *)NULL, (
struct mbuf *)NULL,
415 uap->flags, u_sinfo, td);
418 if (auio.uio_resid != len && (error == ERESTART ||
419 error == EINTR || error == EWOULDBLOCK))
422 if (error == EPIPE && !(so->so_options & SO_NOSIGPIPE) &&
423 !(uap->flags & MSG_NOSIGNAL)) {
424 PROC_LOCK(td->td_proc);
425 tdsignal(td, SIGPIPE);
426 PROC_UNLOCK(td->td_proc);
430 td->td_retval[0] = len - auio.uio_resid;
432 if (ktruio != NULL) {
433 ktruio->uio_resid = td->td_retval[0];
434 ktrgenio(uap->sd, UIO_WRITE, ktruio, error);
450 struct sctp_generic_recvmsg_args
462 struct iovec *iov, *tiov;
465 struct file *fp = NULL;
466 struct sockaddr *fromsa;
469 struct uio *ktruio = NULL;
472 int error, fromlen, i, msg_flags;
474 AUDIT_ARG_FD(uap->sd);
475 error = getsock_cap(td, uap->sd, cap_rights_init_one(&rights, CAP_RECV),
479#ifdef COMPAT_FREEBSD32
480 if (SV_CURPROC_FLAG(SV_ILP32))
481 error = freebsd32_copyiniov((
struct iovec32 *)uap->iov,
482 uap->iovlen, &iov, EMSGSIZE);
485 error = copyiniov(uap->iov, uap->iovlen, &iov, EMSGSIZE);
495 error = mac_socket_check_receive(td->td_ucred, so);
500 if (uap->fromlenaddr != NULL) {
501 error = copyin(uap->fromlenaddr, &fromlen, sizeof (fromlen));
507 if (uap->msg_flags) {
508 error = copyin(uap->msg_flags, &msg_flags, sizeof (
int));
515 auio.uio_iovcnt = uap->iovlen;
516 auio.uio_segflg = UIO_USERSPACE;
517 auio.uio_rw = UIO_READ;
522 for (i = 0; i <uap->iovlen; i++, tiov++) {
523 if ((auio.uio_resid += tiov->iov_len) < 0) {
528 len = auio.uio_resid;
529 fromsa = (
struct sockaddr *)sockbufstore;
532 if (KTRPOINT(td, KTR_GENIO))
533 ktruio = cloneuio(&auio);
536 CURVNET_SET(so->so_vnet);
538 fromsa, fromlen, &msg_flags,
542 if (auio.uio_resid != len && (error == ERESTART ||
543 error == EINTR || error == EWOULDBLOCK))
547 error = copyout(&sinfo, uap->sinfo, sizeof (sinfo));
550 if (ktruio != NULL) {
551 ktruio->uio_resid = len - auio.uio_resid;
552 ktrgenio(uap->sd, UIO_READ, ktruio, error);
557 td->td_retval[0] = len - auio.uio_resid;
559 if (fromlen && uap->from) {
561 if (len <= 0 || fromsa == NULL)
564 len = MIN(len, fromsa->sa_len);
565 error = copyout(fromsa, uap->from, (
size_t)len);
569 error = copyout(&len, uap->fromlenaddr, sizeof (
socklen_t));
574 if (KTRPOINT(td, KTR_STRUCT))
577 if (uap->msg_flags) {
578 error = copyout(&msg_flags, uap->msg_flags, sizeof (
int));
SYSINIT(cc, SI_SUB_PROTO_IFATTACHDOMAIN, SI_ORDER_FIRST, cc_init, NULL)
int sctp_lower_sosend(struct socket *so, struct sockaddr *addr, struct uio *uio, struct mbuf *i_pak, struct mbuf *control, int flags, struct sctp_sndrcvinfo *srcv, struct thread *p)
int sctp_do_peeloff(struct socket *head, struct socket *so, sctp_assoc_t assoc_id)
int sctp_can_peel_off(struct socket *head, sctp_assoc_t assoc_id)
static struct syscall_helper_data sctp_syscalls[]
int sys_sctp_generic_recvmsg(struct thread *td, struct sctp_generic_recvmsg_args *uap)
int sys_sctp_generic_sendmsg_iov(struct thread *td, struct sctp_generic_sendmsg_iov_args *uap)
int sys_sctp_generic_sendmsg(struct thread *td, struct sctp_generic_sendmsg_args *uap)
int sctp_syscalls_init(void)
int sys_sctp_peeloff(struct thread *td, struct sctp_peeloff_args *uap)
int sctp_syscalls_uninit(void)
int sctp_sorecvmsg(struct socket *so, struct uio *uio, struct mbuf **mp, struct sockaddr *from, int fromlen, int *msg_flags, struct sctp_sndrcvinfo *sinfo, int filling_sinfo)
int sctp_peeloff(struct socket *, struct socket *, int, caddr_t, int *)