Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Fix COMPAT_NETBSD32 cmsg handling:
details: https://anonhg.NetBSD.org/src/rev/0af0987ef9a8
branches: trunk
changeset: 318721:0af0987ef9a8
user: christos <christos%NetBSD.org@localhost>
date: Thu May 03 21:43:33 2018 +0000
description:
Fix COMPAT_NETBSD32 cmsg handling:
1. alignment was wrong for > 1 message
2. macros were doing incorrect pointer comparisons, fortunately ending
the iteration early after the fists cmsg instead of crashing.
3. don't output 32 bit ktrace records for cmsg. 32 bit programs running
under emulation on 64 bit systems should produce 64 bit ktrace records
so that the native ktrace can handle the records; remove extra arguments
that are now not needed (the 32 bit msghdr).
4. output the correct type for cmsg trace records.
5. output all the cmsg records in traces instead of just the first one.
Welcome to 8.99.15 because of the argument removal.
XXX: Really all the code should be changed to use the CMSG_{FIRST,NXT}HDR
macros...
diffstat:
sys/compat/common/uipc_syscalls_43.c | 8 +-
sys/compat/linux/common/linux_socket.c | 17 ++----
sys/compat/netbsd32/netbsd32_compat_43.c | 8 +-
sys/compat/netbsd32/netbsd32_socket.c | 79 +++++++++++++++++--------------
sys/kern/uipc_syscalls.c | 79 +++++++++++++++----------------
sys/sys/param.h | 4 +-
6 files changed, 98 insertions(+), 97 deletions(-)
diffs (truncated from 602 to 300 lines):
diff -r fc0884b9d056 -r 0af0987ef9a8 sys/compat/common/uipc_syscalls_43.c
--- a/sys/compat/common/uipc_syscalls_43.c Thu May 03 21:37:29 2018 +0000
+++ b/sys/compat/common/uipc_syscalls_43.c Thu May 03 21:43:33 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: uipc_syscalls_43.c,v 1.48 2018/03/16 17:25:04 christos Exp $ */
+/* $NetBSD: uipc_syscalls_43.c,v 1.49 2018/05/03 21:43:33 christos Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1990, 1993
@@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls_43.c,v 1.48 2018/03/16 17:25:04 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls_43.c,v 1.49 2018/05/03 21:43:33 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -216,7 +216,7 @@
msg.msg_iov = omsg.msg_iov;
msg.msg_flags = (SCARG(uap, flags) & MSG_USERFLAGS) | MSG_IOVUSRSPACE;
- error = do_sys_recvmsg(l, SCARG(uap, s), &msg, NULL, 0, &from,
+ error = do_sys_recvmsg(l, SCARG(uap, s), &msg, &from,
omsg.msg_accrights != NULL ? &control : NULL, retval);
if (error != 0)
return error;
@@ -363,7 +363,7 @@
goto bad;
return do_sys_sendmsg(l, SCARG(uap, s), &msg, SCARG(uap, flags),
- NULL, 0, retval);
+ retval);
bad:
if (nam != NULL)
diff -r fc0884b9d056 -r 0af0987ef9a8 sys/compat/linux/common/linux_socket.c
--- a/sys/compat/linux/common/linux_socket.c Thu May 03 21:37:29 2018 +0000
+++ b/sys/compat/linux/common/linux_socket.c Thu May 03 21:43:33 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: linux_socket.c,v 1.140 2018/03/16 17:25:04 christos Exp $ */
+/* $NetBSD: linux_socket.c,v 1.141 2018/05/03 21:43:33 christos Exp $ */
/*-
* Copyright (c) 1995, 1998, 2008 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.140 2018/03/16 17:25:04 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.141 2018/05/03 21:43:33 christos Exp $");
#if defined(_KERNEL_OPT)
#include "opt_inet.h"
@@ -434,8 +434,7 @@
aiov.iov_base = __UNCONST(SCARG(uap, msg));
aiov.iov_len = SCARG(uap, len);
- return do_sys_sendmsg(l, SCARG(uap, s), &msg, bflags,
- NULL, 0, retval);
+ return do_sys_sendmsg(l, SCARG(uap, s), &msg, bflags, retval);
}
static void
@@ -624,8 +623,7 @@
}
skipcmsg:
- error = do_sys_sendmsg(l, SCARG(uap, s), &msg, bflags,
- NULL, 0, retval);
+ error = do_sys_sendmsg(l, SCARG(uap, s), &msg, bflags, retval);
/* Freed internally */
ctl_mbuf = NULL;
@@ -787,7 +785,7 @@
}
msg.msg_flags |= MSG_IOVUSRSPACE;
- error = do_sys_recvmsg(l, SCARG(uap, s), &msg, NULL, 0, &from,
+ error = do_sys_recvmsg(l, SCARG(uap, s), &msg, &from,
msg.msg_control != NULL ? &control : NULL, retval);
if (error != 0)
return error;
@@ -1789,8 +1787,7 @@
msg->msg_flags = flags;
- error = do_sys_sendmsg_so(l, s, so, fp, msg, flags,
- &msg, sizeof(msg), retval);
+ error = do_sys_sendmsg_so(l, s, so, fp, msg, flags, retval);
if (error)
break;
@@ -1871,7 +1868,7 @@
from = NULL;
}
- error = do_sys_recvmsg_so(l, s, so, msg, NULL, 0, &from,
+ error = do_sys_recvmsg_so(l, s, so, msg, &from,
msg->msg_control != NULL ? &control : NULL, retval);
if (error) {
if (error == EAGAIN && dg > 0)
diff -r fc0884b9d056 -r 0af0987ef9a8 sys/compat/netbsd32/netbsd32_compat_43.c
--- a/sys/compat/netbsd32/netbsd32_compat_43.c Thu May 03 21:37:29 2018 +0000
+++ b/sys/compat/netbsd32/netbsd32_compat_43.c Thu May 03 21:43:33 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: netbsd32_compat_43.c,v 1.55 2018/03/16 17:25:04 christos Exp $ */
+/* $NetBSD: netbsd32_compat_43.c,v 1.56 2018/05/03 21:43:33 christos Exp $ */
/*
* Copyright (c) 1998, 2001 Matthew R. Green
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_43.c,v 1.55 2018/03/16 17:25:04 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_43.c,v 1.56 2018/05/03 21:43:33 christos Exp $");
#if defined(_KERNEL_OPT)
#include "opt_compat_43.h"
@@ -451,7 +451,7 @@
msg.msg_iov = iov;
msg.msg_flags = SCARG(uap, flags) & MSG_USERFLAGS;
- error = do_sys_recvmsg(l, SCARG(uap, s), &msg, NULL, 0, &from,
+ error = do_sys_recvmsg(l, SCARG(uap, s), &msg, &from,
NETBSD32PTR64(omsg.msg_accrights) != NULL ? &control : NULL,
retval);
if (error != 0)
@@ -548,7 +548,7 @@
}
error = do_sys_sendmsg(l, SCARG(uap, s), &msg, SCARG(uap, flags),
- &omsg, sizeof(omsg), retval);
+ retval);
out:
if (iov != aiov)
diff -r fc0884b9d056 -r 0af0987ef9a8 sys/compat/netbsd32/netbsd32_socket.c
--- a/sys/compat/netbsd32/netbsd32_socket.c Thu May 03 21:37:29 2018 +0000
+++ b/sys/compat/netbsd32/netbsd32_socket.c Thu May 03 21:43:33 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: netbsd32_socket.c,v 1.44 2016/09/13 07:01:07 martin Exp $ */
+/* $NetBSD: netbsd32_socket.c,v 1.45 2018/05/03 21:43:33 christos Exp $ */
/*
* Copyright (c) 1998, 2001 Matthew R. Green
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_socket.c,v 1.44 2016/09/13 07:01:07 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_socket.c,v 1.45 2018/05/03 21:43:33 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -53,26 +53,29 @@
*/
#define CMSG32_ALIGN(n) (((n) + ALIGNBYTES32) & ~ALIGNBYTES32)
-#define CMSG32_DATA(cmsg) \
- ((u_char *)(void *)(cmsg) + CMSG32_ALIGN(sizeof(struct cmsghdr)))
+#define CMSG32_ASIZE CMSG32_ALIGN(sizeof(struct cmsghdr))
+#define CMSG32_DATA(cmsg) (__CASTV(u_char *, cmsg) + CMSG32_ASIZE)
+#define CMSG32_MSGNEXT(ucmsg, kcmsg) \
+ (__CASTV(char *, kcmsg) + CMSG32_ALIGN((ucmsg)->cmsg_len))
+#define CMSG32_MSGEND(mhdr) \
+ (__CASTV(char *, (mhdr)->msg_control) + (mhdr)->msg_controllen)
-#define CMSG32_NXTHDR(mhdr, cmsg) \
- (((char *)(cmsg) + CMSG32_ALIGN((cmsg)->cmsg_len) + \
- CMSG32_ALIGN(sizeof(struct cmsghdr)) > \
- (((char *)(mhdr)->msg_control) + (mhdr)->msg_controllen)) ? \
- (struct cmsghdr *)0 : \
- (struct cmsghdr *)((char *)(cmsg) + \
- CMSG32_ALIGN((cmsg)->cmsg_len)))
+#define CMSG32_NXTHDR(mhdr, ucmsg, kcmsg) \
+ __CASTV(struct cmsghdr *, \
+ CMSG32_MSGNEXT(ucmsg, kcmsg) + \
+ CMSG32_ASIZE > CMSG32_MSGEND(mhdr) ? 0 : \
+ CMSG32_MSGNEXT(ucmsg, kcmsg))
#define CMSG32_FIRSTHDR(mhdr) \
- ((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
- (struct cmsghdr *)(mhdr)->msg_control : \
- (struct cmsghdr *)0)
+ __CASTV(struct cmsghdr *, \
+ (mhdr)->msg_controllen < sizeof(struct cmsghdr) ? 0 : \
+ (mhdr)->msg_control)
#define CMSG32_SPACE(l) (CMSG32_ALIGN(sizeof(struct cmsghdr)) + CMSG32_ALIGN(l))
#define CMSG32_LEN(l) (CMSG32_ALIGN(sizeof(struct cmsghdr)) + (l))
static int
-copyout32_msg_control_mbuf(struct lwp *l, struct msghdr *mp, int *len, struct mbuf *m, char **q, bool *truncated)
+copyout32_msg_control_mbuf(struct lwp *l, struct msghdr *mp, int *len,
+ struct mbuf *m, char **q, bool *truncated)
{
struct cmsghdr *cmsg, cmsg32;
int i, j, error;
@@ -98,12 +101,13 @@
i = *len;
}
- ktrkuser("msgcontrol", cmsg, cmsg->cmsg_len);
+ ktrkuser(mbuftypes[MT_CONTROL], cmsg, cmsg->cmsg_len);
error = copyout(&cmsg32, *q, MAX(i, sizeof(cmsg32)));
if (error)
return (error);
if (i > CMSG32_LEN(0)) {
- error = copyout(CMSG_DATA(cmsg), *q + CMSG32_LEN(0), i - CMSG32_LEN(0));
+ error = copyout(CMSG_DATA(cmsg), *q + CMSG32_LEN(0),
+ i - CMSG32_LEN(0));
if (error)
return (error);
}
@@ -139,7 +143,8 @@
q = (char *)mp->msg_control;
for (m = control; len > 0 && m != NULL; m = m->m_next) {
- error = copyout32_msg_control_mbuf(l, mp, &len, m, &q, &truncated);
+ error = copyout32_msg_control_mbuf(l, mp, &len, m, &q,
+ &truncated);
if (truncated) {
m = control;
break;
@@ -155,7 +160,8 @@
}
int
-netbsd32_recvmsg(struct lwp *l, const struct netbsd32_recvmsg_args *uap, register_t *retval)
+netbsd32_recvmsg(struct lwp *l, const struct netbsd32_recvmsg_args *uap,
+ register_t *retval)
{
/* {
syscallarg(int) s;
@@ -193,7 +199,7 @@
msg.msg_iov = iov;
msg.msg_iovlen = msg32.msg_iovlen;
- error = do_sys_recvmsg(l, SCARG(uap, s), &msg, &msg32, sizeof(msg32),
+ error = do_sys_recvmsg(l, SCARG(uap, s), &msg,
&from, msg.msg_control != NULL ? &control : NULL, retval);
if (error != 0)
goto done;
@@ -210,7 +216,7 @@
msg32.msg_namelen = msg.msg_namelen;
msg32.msg_controllen = msg.msg_controllen;
msg32.msg_flags = msg.msg_flags;
- ktrkuser("msghdr", &msg32, sizeof msg32);
+ ktrkuser("msghdr", &msg, sizeof msg);
error = copyout(&msg32, SCARG_P32(uap, msg), sizeof(msg32));
}
@@ -238,8 +244,8 @@
control = mtod(ctl_mbuf, void *);
memset(control, 0, clen);
- cc = CMSG32_FIRSTHDR(mp);
- do {
+ for (cc = CMSG32_FIRSTHDR(mp); cc; cc = CMSG32_NXTHDR(mp, &cmsg32, cc))
+ {
error = copyin(cc, &cmsg32, sizeof(cmsg32));
if (error)
goto failure;
@@ -293,10 +299,11 @@
cmsg32.cmsg_len - CMSG32_LEN(0));
if (error)
goto failure;
+ ktrkuser(mbuftypes[MT_CONTROL], cmsg, cmsg->cmsg_len);
resid -= CMSG32_ALIGN(cmsg32.cmsg_len);
- cidx += cmsg->cmsg_len;
- } while (resid > 0 && (cc = CMSG32_NXTHDR(mp, &cmsg32)));
+ cidx += CMSG_ALIGN(cmsg->cmsg_len);
+ }
/* If we allocated a buffer, attach to mbuf */
if (cidx > MLEN) {
@@ -309,8 +316,6 @@
mp->msg_control = ctl_mbuf;
mp->msg_flags |= MSG_CONTROLMBUF;
- ktrkuser("msgcontrol", mtod(ctl_mbuf, void *),
- mp->msg_controllen);
return 0;
@@ -322,7 +327,8 @@
}
int
-netbsd32_sendmsg(struct lwp *l, const struct netbsd32_sendmsg_args *uap, register_t *retval)
+netbsd32_sendmsg(struct lwp *l, const struct netbsd32_sendmsg_args *uap,
+ register_t *retval)
{
/* {
syscallarg(int) s;
@@ -368,7 +374,7 @@
msg.msg_iov = iov;
Home |
Main Index |
Thread Index |
Old Index