PERFORCE change 122752 for review
Roman Divacky
rdivacky at FreeBSD.org
Tue Jul 3 08:06:01 UTC 2007
http://perforce.freebsd.org/chv.cgi?CH=122752
Change 122752 by rdivacky at 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);
More information about the p4-projects
mailing list