Bug #1719

patch: fix apache-ant in linux emulation

Added by Johannes.Hofmann over 4 years ago. Updated over 4 years ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:-
Target version:-

Description

ant does not compile any .java files when run under linux emulation.
The reason is missing support for the O_DIRECTORY flag in open(2).
The patch below adds this and makes ant work.
However it would probabely better - though more invasive to add
O_DIRECTORY to native open(2) and simply pass the flag.

Cheers,
Johannes

diff --git a/sys/emulation/linux/i386/linux.h b/sys/emulation/linux/i386/linux.h
index 2e9a238..a0ba8ef 100644
--- a/sys/emulation/linux/i386/linux.h
+++ b/sys/emulation/linux/i386/linux.h
@@ -494,6 +494,7 @@ extern struct ioctl_map linux_ioctl_map;
#define LINUX_O_NDELAY LINUX_O_NONBLOCK
#define LINUX_O_SYNC 010000
#define LINUX_FASYNC 020000
+#define LINUX_O_DIRECTORY 00200000

#define LINUX_F_DUPFD 0
#define LINUX_F_GETFD 1
diff --git a/sys/emulation/linux/linux_file.c b/sys/emulation/linux/linux_file.c
index bb0ba0a..3d6f39e 100644
--- a/sys/emulation/linux/linux_file.c
+++ b/sys/emulation/linux/linux_file.c
@@ -160,6 +160,20 @@ sys_linux_open(struct linux_open_args *args)
fdrop(fp);
}
}
+
+ if (error == 0 && args->flags & LINUX_O_DIRECTORY) {
+ struct file *fp;
+ struct vnode *vp;
+
+ fp = holdfp(p->p_fd, args->sysmsg_iresult, -1);
+ if (fp) {
+ vp = (struct vnode *) fp->f_data;
+ if (vp->v_type != VDIR)
+ error = ENOTDIR;
+ fdrop(fp);
+ }
+ }
+
rel_mplock();
#ifdef DEBUG
if (ldebug(open))

History

#1 Updated by jontro over 4 years ago

On Thu, Apr 8, 2010 at 10:56 PM, Johannes Hofmann
<> wrote:
> However it would probabely better - though more invasive to add
> O_DIRECTORY to native open(2) and simply pass the flag.

As far as I can tell only opendir should be using the O_DIRECTORY flag in open.

From the man page: "If pathname is not a directory, cause the open to
fail. This flag is Linux-specific,
and was added in kernel version 2.1.126, to avoid denial-of-service
problems if opendir(3) is called on
a FIFO or tape device, but should not be used outside of the
implementation of opendir."

Does this race exist in BSD opendir?

If ant is using this, is it through opendir?

Only reason I can see to introduce this in the base is if this problem
also exists on dragonflybsd.

Regards,
Jonas Trollvik

#2 Updated by alexh over 4 years ago

Thanks Johannes!
Commited with a minor fix (using kern_close if it's not a directory but supposed
to be) in 9ea7e8bc214c6e4b865b9b70b34fb1f9e14ceae4.

Cheers,
Alex Hornung

#3 Updated by Johannes.Hofmann over 4 years ago

Jonas Trollvik <> wrote:
> On Thu, Apr 8, 2010 at 10:56 PM, Johannes Hofmann
> <> wrote:
>> However it would probabely better - though more invasive to add
>> O_DIRECTORY to native open(2) and simply pass the flag.
>
> As far as I can tell only opendir should be using the O_DIRECTORY flag in open.
>
> From the man page: "If pathname is not a directory, cause the open to
> fail. This flag is Linux-specific,
> and was added in kernel version 2.1.126, to avoid denial-of-service
> problems if opendir(3) is called on
> a FIFO or tape device, but should not be used outside of the
> implementation of opendir."
>
> Does this race exist in BSD opendir?
>
> If ant is using this, is it through opendir?
>
> Only reason I can see to introduce this in the base is if this problem
> also exists on dragonflybsd.

I have to admit that I don't fully understand the details of the race
in opendir that is supposed to be fixed by using O_DIRECTORY, however
the flag seems to be in some standard:
http://www.opengroup.org/onlinepubs/9699919799/basedefs/fcntl.h.html#tag_13_10
and FreeBSD also introduced the flag recently.

Regards,
Johannes

Also available in: Atom PDF