From owner-p4-projects@FreeBSD.ORG Tue Jul 3 08:06:01 2007 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 3F75016A421; Tue, 3 Jul 2007 08:06:01 +0000 (UTC) X-Original-To: perforce@FreeBSD.org Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 1051B16A46C for ; Tue, 3 Jul 2007 08:06:01 +0000 (UTC) (envelope-from rdivacky@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [69.147.83.41]) by mx1.freebsd.org (Postfix) with ESMTP id 0022613C4BA for ; Tue, 3 Jul 2007 08:06:00 +0000 (UTC) (envelope-from rdivacky@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.8/8.13.8) with ESMTP id l638607p000478 for ; Tue, 3 Jul 2007 08:06:00 GMT (envelope-from rdivacky@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.8/8.13.8/Submit) id l63860H7000475 for perforce@freebsd.org; Tue, 3 Jul 2007 08:06:00 GMT (envelope-from rdivacky@FreeBSD.org) Date: Tue, 3 Jul 2007 08:06:00 GMT Message-Id: <200707030806.l63860H7000475@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to rdivacky@FreeBSD.org using -f From: Roman Divacky To: Perforce Change Reviews Cc: Subject: PERFORCE change 122752 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: Tue, 03 Jul 2007 08:06:01 -0000 http://perforce.freebsd.org/chv.cgi?CH=122752 Change 122752 by rdivacky@rdivacky_witten on 2007/07/03 08:05:17 O_EXEC support. it is able to fexecve "/bin/date" when opened with O_RDONLY or O_EXEC. I am a little suspicious about this patch because audacious (mp3 player) acts really weird now. Needs some more investigation. Affected files ... .. //depot/projects/soc2007/rdivacky/linux_at/sys/kern/imgact_elf.c#3 edit .. //depot/projects/soc2007/rdivacky/linux_at/sys/kern/kern_exec.c#10 edit .. //depot/projects/soc2007/rdivacky/linux_at/sys/sys/fcntl.h#8 edit .. //depot/projects/soc2007/rdivacky/linux_at/sys/sys/imgact.h#3 edit Differences ... ==== //depot/projects/soc2007/rdivacky/linux_at/sys/kern/imgact_elf.c#3 (text+ko) ==== @@ -512,7 +512,7 @@ /* * Check permissions, modes, uid, etc on the file, and "open" it. */ - error = exec_check_permissions(imgp); + error = exec_check_permissions(imgp, 0, 0); if (error) goto fail; ==== //depot/projects/soc2007/rdivacky/linux_at/sys/kern/kern_exec.c#10 (text+ko) ==== @@ -402,7 +402,7 @@ /* * Check file permissions (also 'opens' file) */ - error = exec_check_permissions(imgp); + error = exec_check_permissions(imgp, args->fname == NULL, args->fd); if (error) goto exec_fail_dealloc; @@ -1226,8 +1226,10 @@ * Return 0 for success or error code on failure. */ int -exec_check_permissions(imgp) +exec_check_permissions(imgp, fexecve, fd) struct image_params *imgp; + int fexecve; + int fd; { struct vnode *vp = imgp->vp; struct vattr *attr = imgp->attr; @@ -1281,6 +1283,27 @@ return (ETXTBSY); /* + * Check for the mode the file was opened with + */ + if (fexecve) { + struct file f; + struct file *fp = &f; + + FILEDESC_SLOCK(td->td_proc->p_fd); + fp = fget_locked(td->td_proc->p_fd, fd); + if (fp == NULL || fp->f_ops == &badfileops) { + FILEDESC_SUNLOCK(td->td_proc->p_fd); + return (EBADF); + } + fhold(fp); + FILEDESC_SUNLOCK(td->td_proc->p_fd); + if (!(fp->f_flag & FREAD) && !(fp->f_flag & O_EXEC)) { + fdrop(fp, td); + return (EACCES); + } + fdrop(fp, td); + } + /* * Call filesystem specific open routine (which does nothing in the * general case). */ ==== //depot/projects/soc2007/rdivacky/linux_at/sys/sys/fcntl.h#8 (text+ko) ==== @@ -74,10 +74,6 @@ #define O_WRONLY 0x0001 /* open for writing only */ #define O_RDWR 0x0002 /* open for reading and writing */ #define O_ACCMODE 0x0003 /* mask for above modes */ -#if 0 -#define O_EXEC 0x0004 /* open for execute only */ -#define O_ACCMODE 0x0007 /* mask for above modes */ -#endif /* * Kernel encoding of open mode; separate read and write bits that are @@ -107,6 +103,7 @@ #ifdef _KERNEL #define FHASLOCK 0x4000 /* descriptor holds advisory lock */ #endif +#define O_EXEC 0x8000 /* open for execute only */ /* Defined by POSIX Extended API ... TODO: number of the spec */ #define AT_FDCWD -100 /* Use the current working directory to determine the target of relative @@ -138,7 +135,7 @@ #define OFLAGS(fflags) ((fflags) - 1) /* bits to save after open */ -#define FMASK (FREAD|FWRITE|FAPPEND|FASYNC|FFSYNC|FNONBLOCK|O_DIRECT) +#define FMASK (FREAD|FWRITE|FAPPEND|FASYNC|FFSYNC|FNONBLOCK|O_DIRECT|O_EXEC) /* bits settable by fcntl(F_SETFL, ...) */ #define FCNTLFLAGS (FAPPEND|FASYNC|FFSYNC|FNONBLOCK|FPOSIXSHM|O_DIRECT) #endif ==== //depot/projects/soc2007/rdivacky/linux_at/sys/sys/imgact.h#3 (text+ko) ==== @@ -71,7 +71,7 @@ struct sysentvec; struct thread; -int exec_check_permissions(struct image_params *); +int exec_check_permissions(struct image_params *, int fexecve, int fd); register_t *exec_copyout_strings(struct image_params *); int exec_new_vmspace(struct image_params *, struct sysentvec *); void exec_setregs(struct thread *, u_long, u_long, u_long);