From owner-p4-projects@FreeBSD.ORG Wed Jan 11 22:41:50 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 367B316A423; Wed, 11 Jan 2006 22:41:50 +0000 (GMT) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9F4D916A41F for ; Wed, 11 Jan 2006 22:41:49 +0000 (GMT) (envelope-from millert@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id C524443D5C for ; Wed, 11 Jan 2006 22:41:48 +0000 (GMT) (envelope-from millert@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id k0BMfm8f030927 for ; Wed, 11 Jan 2006 22:41:48 GMT (envelope-from millert@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id k0BMfmvD030924 for perforce@freebsd.org; Wed, 11 Jan 2006 22:41:48 GMT (envelope-from millert@freebsd.org) Date: Wed, 11 Jan 2006 22:41:48 GMT Message-Id: <200601112241.k0BMfmvD030924@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to millert@freebsd.org using -f From: Todd Miller To: Perforce Change Reviews Cc: Subject: PERFORCE change 89531 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Jan 2006 22:41:51 -0000 http://perforce.freebsd.org/chv.cgi?CH=89531 Change 89531 by millert@millert_ibook on 2006/01/11 22:40:55 Fix the order of the message checks; we need to do the port check before the rights check (it was the other way around). To do this we must move mac_check_port_send() out of ipc_kmsg_send() and into ipc_kmsg_copyin_header(). It is too late to deny in ipc_kmsg_send() since the rights have already have been copied into the kmsg at that point. Affected files ... .. //depot/projects/trustedbsd/sedarwin7/src/darwin/xnu/osfmk/ipc/ipc_kmsg.c#6 edit Differences ... ==== //depot/projects/trustedbsd/sedarwin7/src/darwin/xnu/osfmk/ipc/ipc_kmsg.c#6 (text+ko) ==== @@ -848,20 +848,11 @@ port = (ipc_port_t) kmsg->ikm_header.msgh_remote_port; assert(IP_VALID(port)); + if ((option & ~(MACH_SEND_TIMEOUT|MACH_SEND_ALWAYS)) != 0) + printf("ipc_kmsg_send: bad option 0x%x\n", option); + ip_lock(port); -#ifdef MAC - task_t self = current_task(); - tasklabel_lock(self); - - int rc = mac_check_port_send(&self->maclabel, &port->ip_label); - tasklabel_unlock(self); - if (rc) { - ip_unlock (port); - return KERN_NO_ACCESS; - } -#endif - if (port->ip_receiver == ipc_space_kernel) { /* @@ -1727,7 +1718,46 @@ mach_port_name_t notify) { mach_msg_return_t mr; - +#ifdef MAC + mach_port_name_t dest_name; + ipc_entry_t entry; + ipc_port_t port; + task_t self; + int error = 0; + + /* + * We do the port send check here instead of in ipc_kmsg_send() + * because copying the header involves copying the port rights too + * and we need to do the send check before anything is actually copied. + * We don't currently try to mediate kernel-resident servers. + */ + self = current_task(); + if (self != kernel_task) { + is_read_lock(space); + if (space->is_active) { + dest_name = (mach_port_name_t) kmsg->ikm_header.msgh_remote_port; + if (MACH_PORT_VALID(dest_name)) { + entry = ipc_entry_lookup(space, dest_name); + if (entry != IE_NULL) { + port = (ipc_port_t) entry->ie_object; + assert(port != IP_NULL); + ip_lock(port); + if (ip_active(port)) { + tasklabel_lock(self); + error = mac_check_port_send(&self->maclabel, + &port->ip_label); + tasklabel_unlock(self); + } + ip_unlock(port); + } + } + } + is_read_unlock(space); + if (error != 0) + return MACH_SEND_INVALID_DEST; + } +#endif + mr = ipc_kmsg_copyin_header(&kmsg->ikm_header, space, notify); if (mr != MACH_MSG_SUCCESS) return mr;