From owner-p4-projects@FreeBSD.ORG Sat Jan 24 22:35:05 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 2B66110656CF; Sat, 24 Jan 2009 22:35:05 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D455910656CC for ; Sat, 24 Jan 2009 22:35:04 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id A48A48FC16 for ; Sat, 24 Jan 2009 22:35:04 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n0OMZ4dk087986 for ; Sat, 24 Jan 2009 22:35:04 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n0OMZ4nv087984 for perforce@freebsd.org; Sat, 24 Jan 2009 22:35:04 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Sat, 24 Jan 2009 22:35:04 GMT Message-Id: <200901242235.n0OMZ4nv087984@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to bb+lists.freebsd.perforce@cyrus.watson.org using -f From: Robert Watson To: Perforce Change Reviews Cc: Subject: PERFORCE change 156625 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: Sat, 24 Jan 2009 22:35:07 -0000 http://perforce.freebsd.org/chv.cgi?CH=156625 Change 156625 by rwatson@rwatson_freebsd_capabilities on 2009/01/24 22:34:21 The capability-mode rtld-elf behaves a bit differently: we pass the binary to execute as file descriptor 3, which rtld will map and then execute. Do this by mocking up an AT_EXECFD ELF auxiliary argument -- let's see if this long-unused code in rtld works. Affected files ... .. //depot/projects/trustedbsd/capabilities/src/libexec/rtld-elf/rtld.c#5 edit Differences ... ==== //depot/projects/trustedbsd/capabilities/src/libexec/rtld-elf/rtld.c#5 (text+ko) ==== @@ -304,6 +304,10 @@ func_ptr_type _rtld(Elf_Addr *sp, func_ptr_type *exit_proc, Obj_Entry **objp) { +#ifdef IN_RTLD_CAP + struct stat sb; + Elf_Auxinfo aux_execfd; +#endif Elf_Auxinfo *aux_info[AT_COUNT]; int i; int argc; @@ -342,10 +346,32 @@ aux_info[auxp->a_type] = auxp; } +#ifdef IN_RTLD_CAP + /* + * In capability mode, the kernel has executed ld-elf-cap.so directly, + * and the parent has passed the executable it wants us to run as a file + * descriptor. The kernel doesn't know this, so rewrite our auxilary + * arguments so the remainder of rtld thinks the kernel passed the file + * descriptor using AT_EXECFD. + */ + if (aux_info[AT_EXECFD] == NULL) { + bzero(&aux_execfd, sizeof(aux_execfd)); + aux_execfd.a_type = AT_EXECFD; + aux_execfd.a_un.a_val = 3; + aux_info[AT_EXECFD] = &aux_execfd; + if (fstat(3, &sb) < 0) { + __progname = "ld-elf-cap.so"; + _rtld_error("executable file descriptor unusable"); + die(); + } + } +#endif + /* Initialize and relocate ourselves. */ assert(aux_info[AT_BASE] != NULL); init_rtld((caddr_t) aux_info[AT_BASE]->a_un.a_ptr); + /* XXXRW: Need to do something about program names in capability mode. */ __progname = obj_rtld.path; argv0 = argv[0] != NULL ? argv[0] : "(null)"; environ = env; @@ -527,23 +553,6 @@ return (func_ptr_type) obj_main->entry; } -#ifdef IN_RTLD_CAP -/* - * If we are ld-elf-cap.so, then we are directly executed using fexecve(2) - * and will need to behave a bit differently: - * - * (1) The ELF auxilary arguments are for our own binary. - * (2) The main binary we want to execute will be passed as a file descriptor - * so we'll mock up AT_COUNT. - */ -int -_rtld_cap_start(int argc, char *argv[]) -{ - - _exit(0); -} -#endif - Elf_Addr _rtld_bind(Obj_Entry *obj, Elf_Size reloff) {