Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/compat Enforce good santity checks with Mach messages si...



details:   https://anonhg.NetBSD.org/src/rev/d4e2270cd079
branches:  trunk
changeset: 555291:d4e2270cd079
user:      manu <manu%NetBSD.org@localhost>
date:      Thu Nov 13 13:40:39 2003 +0000

description:
Enforce good santity checks with Mach messages sizes:
1) make sure Mach servers will not work on data beyond the end of the
   request message buffer.
2) make sure that on copying out the reply message buffer, we will not
   leak kernel data located after the buffer.
3) make sure that the server will not overwrite memory beyond the end
   of the reply message buffer. That check is the responsability of the
   server, there is just a DIAGNOSTIC test to check everything is in
   good shape. All currently implemented servers in NetBSD have been
   modified to check for this condition

While we are here, build the mach services table (formerly in mach_namemap.c)
and the services prototypes automatically from mach_services.master, just
as this is done for system calls.

The next step would be to fold the message formats in the mach_services.master
file, but this tends to be difficult, as some messages are quite long and
complex.

diffstat:

 sys/compat/darwin/darwin_ioframebuffer.c |   17 +--
 sys/compat/darwin/darwin_iohidsystem.c   |   12 +-
 sys/compat/mach/Makefile                 |   19 ++-
 sys/compat/mach/files.mach               |    4 +-
 sys/compat/mach/mach_bootstrap.c         |    7 +-
 sys/compat/mach/mach_bootstrap.h         |    4 +-
 sys/compat/mach/mach_clock.c             |    7 +-
 sys/compat/mach/mach_clock.h             |    6 +-
 sys/compat/mach/mach_host.c              |    5 +-
 sys/compat/mach/mach_host.h              |    7 +-
 sys/compat/mach/mach_iokit.c             |  211 +++++++++++++++++++++++++-----
 sys/compat/mach/mach_iokit.h             |   66 +++------
 sys/compat/mach/mach_message.c           |   74 ++++++++--
 sys/compat/mach/mach_message.h           |   19 +-
 sys/compat/mach/mach_namemap.c           |  153 ----------------------
 sys/compat/mach/mach_port.c              |   20 ++-
 sys/compat/mach/mach_port.h              |   17 +--
 sys/compat/mach/mach_semaphore.c         |    7 +-
 sys/compat/mach/mach_semaphore.h         |    6 +-
 sys/compat/mach/mach_services.c          |  105 +++++++++++++++
 sys/compat/mach/mach_services.h          |   84 ++++++++++++
 sys/compat/mach/mach_services.master     |   98 ++++++++++++++
 sys/compat/mach/mach_task.c              |   17 +-
 sys/compat/mach/mach_task.h              |   14 +-
 sys/compat/mach/mach_thread.c            |   31 ++++-
 sys/compat/mach/mach_thread.h            |   14 +-
 sys/compat/mach/mach_vm.c                |   19 ++-
 sys/compat/mach/mach_vm.h                |   15 +-
 sys/compat/mach/makemachservices.sh      |  102 ++++++++++++++
 29 files changed, 774 insertions(+), 386 deletions(-)

diffs (truncated from 2144 to 300 lines):

diff -r 7a3f34610645 -r d4e2270cd079 sys/compat/darwin/darwin_ioframebuffer.c
--- a/sys/compat/darwin/darwin_ioframebuffer.c  Thu Nov 13 13:18:56 2003 +0000
+++ b/sys/compat/darwin/darwin_ioframebuffer.c  Thu Nov 13 13:40:39 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: darwin_ioframebuffer.c,v 1.23 2003/11/01 18:41:25 manu Exp $ */
+/*     $NetBSD: darwin_ioframebuffer.c,v 1.24 2003/11/13 13:40:39 manu Exp $ */
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: darwin_ioframebuffer.c,v 1.23 2003/11/01 18:41:25 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: darwin_ioframebuffer.c,v 1.24 2003/11/13 13:40:39 manu Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -140,10 +140,6 @@
        rep->rep_msgh.msgh_id = req->req_msgh.msgh_id + 100;
        rep->rep_outcount = 0;
 
-       /* Sanity check req->req_incount */
-       if (MACH_REQMSG_OVERFLOW(args, req->req_in[req->req_incount]))
-               return mach_msg_error(args, EINVAL);
-
        maxoutcount = req->req_in[req->req_incount];
 
        switch (req->req_selector) {
@@ -314,10 +310,6 @@
        rep->rep_msgh.msgh_id = req->req_msgh.msgh_id + 100;
        rep->rep_outcount = 0;
 
-       /* Sanity check req->req_incount */
-       if (MACH_REQMSG_OVERFLOW(args, req->req_in[req->req_incount]))
-               return mach_msg_error(args, EINVAL);
-
        maxoutcount = req->req_in[req->req_incount];
 
        switch(req->req_selector) {
@@ -623,13 +615,8 @@
        printf("darwin_ioframebuffer_connect_method_scalari_structi()\n");
 #endif
        scalar_len = req->req_incount; 
-       if (MACH_REQMSG_OVERFLOW(args, req->req_in[scalar_len]))
-               return mach_msg_error(args, EINVAL);
        struct_len = req->req_in[scalar_len];
-
        struct_data = (char *)&req->req_in[scalar_len + 1];     
-       if (MACH_REQMSG_OVERFLOW(args, struct_data[struct_len - 1]))
-               return mach_msg_error(args, EINVAL);
 
        switch (req->req_selector) {
        case DARWIN_IOFBSETCOLORCONVERTTABLE: {
diff -r 7a3f34610645 -r d4e2270cd079 sys/compat/darwin/darwin_iohidsystem.c
--- a/sys/compat/darwin/darwin_iohidsystem.c    Thu Nov 13 13:18:56 2003 +0000
+++ b/sys/compat/darwin/darwin_iohidsystem.c    Thu Nov 13 13:40:39 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: darwin_iohidsystem.c,v 1.22 2003/11/02 00:44:19 manu Exp $ */
+/*     $NetBSD: darwin_iohidsystem.c,v 1.23 2003/11/13 13:40:39 manu Exp $ */
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: darwin_iohidsystem.c,v 1.22 2003/11/02 00:44:19 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: darwin_iohidsystem.c,v 1.23 2003/11/13 13:40:39 manu Exp $");
 
 #include "ioconf.h"
 #include "wsmux.h"
@@ -178,10 +178,6 @@
        rep->rep_msgh.msgh_id = req->req_msgh.msgh_id + 100;
        rep->rep_outcount = 0;
 
-       /* Sanity check req->req_incount */
-       if (MACH_REQMSG_OVERFLOW(args, req->req_in[req->req_incount]))
-               return mach_msg_error(args, EINVAL);
-
        maxoutcount = req->req_in[req->req_incount]; 
 
        switch (req->req_selector) {
@@ -315,10 +311,6 @@
        rep->rep_msgh.msgh_id = req->req_msgh.msgh_id + 100;
        rep->rep_outcount = 0;
 
-       /* Sanity check req->req_incount */
-       if (MACH_REQMSG_OVERFLOW(args, req->req_in[req->req_incount]))
-               return mach_msg_error(args, EINVAL);
-
        maxoutcount = req->req_in[req->req_incount]; 
 
        switch (req->req_selector) {
diff -r 7a3f34610645 -r d4e2270cd079 sys/compat/mach/Makefile
--- a/sys/compat/mach/Makefile  Thu Nov 13 13:18:56 2003 +0000
+++ b/sys/compat/mach/Makefile  Thu Nov 13 13:40:39 2003 +0000
@@ -1,13 +1,22 @@
-#      $NetBSD: Makefile,v 1.2 2003/10/26 07:25:37 lukem Exp $
+#      $NetBSD: Makefile,v 1.3 2003/11/13 13:40:39 manu Exp $
+
+SYSCALL_DEP=   syscalls.conf syscalls.master ../../kern/makesyscalls.sh 
+SYSCALL_OBJS=  mach_sysent.c mach_syscalls.c mach_syscall.h mach_syscallargs.h 
+MACH_DEP=      mach_services.master makemachservices.sh
+MACH_OBJ=      mach_services.c mach_services.h
+
+all:   ${SYSCALL_OBJS} ${MACH_OBJ}
 
 .include <bsd.sys.mk>          # for HOST_SH
 
-DEP=   syscalls.conf syscalls.master ../../kern/makesyscalls.sh
-OBJS=  mach_sysent.c mach_syscalls.c mach_syscall.h mach_syscallargs.h
-
-${OBJS}: ${DEP}
+${SYSCALL_OBJS}: ${SYSCALL_DEP}
        -mv -f mach_sysent.c mach_sysent.c.bak
        -mv -f mach_syscalls.c mach_syscalls.c.bak
        -mv -f mach_syscall.h mach_syscall.h.bak
        -mv -f mach_syscallargs.h mach_syscallargs.h.bak
        ${HOST_SH} ../../kern/makesyscalls.sh syscalls.conf syscalls.master
+
+${MACH_OBJ}: ${MACH_DEP}
+       -mv -f mach_services.c mach_services.c.bak
+       -mv -f mach_services.h mach_services.h.bak
+       ${HOSH_SH} ./makemachservices.sh
diff -r 7a3f34610645 -r d4e2270cd079 sys/compat/mach/files.mach
--- a/sys/compat/mach/files.mach        Thu Nov 13 13:18:56 2003 +0000
+++ b/sys/compat/mach/files.mach        Thu Nov 13 13:40:39 2003 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.mach,v 1.12 2003/03/29 11:04:08 manu Exp $
+#      $NetBSD: files.mach,v 1.13 2003/11/13 13:40:39 manu Exp $
 #
 # Config file description for machine-independent Mach compat code.
 # Included by ports that need it.
@@ -14,10 +14,10 @@
 file   compat/mach/mach_iokit.c        compat_mach | compat_darwin
 file   compat/mach/mach_misc.c         compat_mach | compat_darwin
 file   compat/mach/mach_message.c      compat_mach | compat_darwin
-file   compat/mach/mach_namemap.c      compat_mach | compat_darwin
 file   compat/mach/mach_notify.c       compat_mach | compat_darwin
 file   compat/mach/mach_port.c         compat_mach | compat_darwin
 file   compat/mach/mach_semaphore.c    compat_mach | compat_darwin
+file   compat/mach/mach_services.c     compat_mach | compat_darwin
 file   compat/mach/mach_syscalls.c     compat_mach | compat_darwin
 file   compat/mach/mach_sysent.c       compat_mach | compat_darwin
 file   compat/mach/mach_task.c         compat_mach | compat_darwin
diff -r 7a3f34610645 -r d4e2270cd079 sys/compat/mach/mach_bootstrap.c
--- a/sys/compat/mach/mach_bootstrap.c  Thu Nov 13 13:18:56 2003 +0000
+++ b/sys/compat/mach/mach_bootstrap.c  Thu Nov 13 13:40:39 2003 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: mach_bootstrap.c,v 1.8 2003/08/26 21:52:18 manu Exp $ */
+/*     $NetBSD: mach_bootstrap.c,v 1.9 2003/11/13 13:40:39 manu Exp $ */
 
 /*-
- * Copyright (c) 2002 The NetBSD Foundation, Inc.
+ * Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_bootstrap.c,v 1.8 2003/08/26 21:52:18 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mach_bootstrap.c,v 1.9 2003/11/13 13:40:39 manu Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -50,6 +50,7 @@
 #include <compat/mach/mach_port.h>
 #include <compat/mach/mach_bootstrap.h>
 #include <compat/mach/mach_errno.h>
+#include <compat/mach/mach_services.h>
 
 int 
 mach_bootstrap_look_up(args)
diff -r 7a3f34610645 -r d4e2270cd079 sys/compat/mach/mach_bootstrap.h
--- a/sys/compat/mach/mach_bootstrap.h  Thu Nov 13 13:18:56 2003 +0000
+++ b/sys/compat/mach/mach_bootstrap.h  Thu Nov 13 13:40:39 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mach_bootstrap.h,v 1.2 2002/12/17 18:42:56 manu Exp $ */
+/*     $NetBSD: mach_bootstrap.h,v 1.3 2003/11/13 13:40:39 manu Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -56,6 +56,4 @@
        mach_msg_trailer_t rep_trailer;
 } mach_bootstrap_look_up_reply_t;
 
-int mach_bootstrap_look_up(struct mach_trap_args *);
-
 #endif /* _MACH_BOOTSTRAP_H_ */
diff -r 7a3f34610645 -r d4e2270cd079 sys/compat/mach/mach_clock.c
--- a/sys/compat/mach/mach_clock.c      Thu Nov 13 13:18:56 2003 +0000
+++ b/sys/compat/mach/mach_clock.c      Thu Nov 13 13:40:39 2003 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: mach_clock.c,v 1.8 2003/01/21 04:06:07 matt Exp $ */
+/*     $NetBSD: mach_clock.c,v 1.9 2003/11/13 13:40:39 manu Exp $ */
 
 /*-
- * Copyright (c) 2002 The NetBSD Foundation, Inc.
+ * Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_clock.c,v 1.8 2003/01/21 04:06:07 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mach_clock.c,v 1.9 2003/11/13 13:40:39 manu Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -51,6 +51,7 @@
 #include <compat/mach/mach_message.h>
 #include <compat/mach/mach_port.h>
 #include <compat/mach/mach_clock.h>
+#include <compat/mach/mach_services.h>
 #include <compat/mach/mach_syscallargs.h>
 
 int
diff -r 7a3f34610645 -r d4e2270cd079 sys/compat/mach/mach_clock.h
--- a/sys/compat/mach/mach_clock.h      Thu Nov 13 13:18:56 2003 +0000
+++ b/sys/compat/mach/mach_clock.h      Thu Nov 13 13:40:39 2003 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: mach_clock.h,v 1.5 2002/12/27 19:57:47 manu Exp $ */
+/*     $NetBSD: mach_clock.h,v 1.6 2003/11/13 13:40:39 manu Exp $ */
 
 /*-
- * Copyright (c) 2002 The NetBSD Foundation, Inc.
+ * Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -68,6 +68,4 @@
        mach_msg_trailer_t rep_trailer;
 } mach_clock_get_time_reply_t;
 
-int mach_clock_get_time(struct mach_trap_args *);
-
 #endif /* _MACH_CLOCK_H_ */
diff -r 7a3f34610645 -r d4e2270cd079 sys/compat/mach/mach_host.c
--- a/sys/compat/mach/mach_host.c       Thu Nov 13 13:18:56 2003 +0000
+++ b/sys/compat/mach/mach_host.c       Thu Nov 13 13:40:39 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mach_host.c,v 1.22 2003/02/02 19:07:17 manu Exp $ */
+/*     $NetBSD: mach_host.c,v 1.23 2003/11/13 13:40:39 manu Exp $ */
 
 /*-
  * Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_host.c,v 1.22 2003/02/02 19:07:17 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mach_host.c,v 1.23 2003/11/13 13:40:39 manu Exp $");
 
 #include <sys/types.h>
 #include <sys/malloc.h>
@@ -54,6 +54,7 @@
 #include <compat/mach/mach_port.h>
 #include <compat/mach/mach_clock.h>
 #include <compat/mach/mach_errno.h>
+#include <compat/mach/mach_services.h>
 
 int 
 mach_host_info(args)
diff -r 7a3f34610645 -r d4e2270cd079 sys/compat/mach/mach_host.h
--- a/sys/compat/mach/mach_host.h       Thu Nov 13 13:18:56 2003 +0000
+++ b/sys/compat/mach/mach_host.h       Thu Nov 13 13:40:39 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mach_host.h,v 1.11 2003/11/11 17:31:59 manu Exp $ */
+/*     $NetBSD: mach_host.h,v 1.12 2003/11/13 13:40:39 manu Exp $ */
 
 /*-
  * Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
@@ -156,11 +156,6 @@
        mach_msg_trailer_t rep_trailer;
 } mach_host_get_io_master_reply_t;
 
-int mach_host_info(struct mach_trap_args *);
-int mach_host_page_size(struct mach_trap_args *);
-int mach_host_get_clock_service(struct mach_trap_args *);
-int mach_host_get_io_master(struct mach_trap_args *);
-
 /* Theses are machine dependent functions */
 void mach_host_basic_info(struct mach_host_basic_info *);
 void mach_host_priority_info(struct mach_host_priority_info *);
diff -r 7a3f34610645 -r d4e2270cd079 sys/compat/mach/mach_iokit.c
--- a/sys/compat/mach/mach_iokit.c      Thu Nov 13 13:18:56 2003 +0000
+++ b/sys/compat/mach/mach_iokit.c      Thu Nov 13 13:40:39 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mach_iokit.c,v 1.24 2003/11/01 18:41:25 manu Exp $ */
+/*     $NetBSD: mach_iokit.c,v 1.25 2003/11/13 13:40:39 manu Exp $ */
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 



Home | Main Index | Thread Index | Old Index