From asaddi@shell2.ba.best.com Fri Jun 11 21:34:18 1999
Return-Path: <asaddi@shell2.ba.best.com>
Received: from shell2.ba.best.com (shell2.ba.best.com [206.184.139.133])
	by hub.freebsd.org (Postfix) with ESMTP id 9EBC91507D
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 11 Jun 1999 21:34:17 -0700 (PDT)
	(envelope-from asaddi@shell2.ba.best.com)
Received: (from asaddi@localhost)
	by shell2.ba.best.com (8.9.3/8.9.2/best.sh) id VAA02996;
	Fri, 11 Jun 1999 21:33:34 -0700 (PDT)
Message-Id: <199906120433.VAA02996@shell2.ba.best.com>
Date: Fri, 11 Jun 1999 21:33:34 -0700 (PDT)
From: asaddi@philosophysw.com
Sender: asaddi@shell2.ba.best.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: Linux emulator fcntl ignores args (patch included)

>Number:         12147
>Category:       i386
>Synopsis:       Linux emulator fcntl ignores args
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    sos
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jun 11 21:40:00 PDT 1999
>Closed-Date:    Sun Aug 15 07:30:16 PDT 1999
>Last-Modified:  Sun Aug 15 07:30:48 PDT 1999
>Originator:     Allan Saddi
>Release:        FreeBSD 3.2-STABLE i386
>Organization:
Philosophy SoftWorks
>Environment:

FreeBSD 3.2-STABLE #43: Wed May 19 21:50:31 PDT 1999

>Description:

The Linux emulator's fcntl syscall ignores args for commands that
shouldn't have them ignored: F_DUPFD and F_SETFD. As a result, whenever
fcntl w/ the command of F_DUPFD is called, the descriptor copied is always
descriptor 0. Also, fcntl w/ F_SETFD can't ever set a descriptor's
close-on-exec flag.

The bug was found while installing/running Scriptics' TclPro. Because
descriptors failed to actually close-on-exec (i.e. pipe descriptors),
closing a dup'ed copy of the descriptor did not actually close the file/
pipe. Thus, an EOF cannot be sent between the parent/child through the pipe,
causing both to hang. (The child closes the pipe, thinking it's actually
closed, while the parent waits, read'ing from a pipe that the child will
never write to again.)

>How-To-Repeat:

Attempt to install Scriptics' TclPro (www.scriptics.com). Installation will
hang while unzipping.

>Fix:
	
--- sys/i386/linux/linux_file.c.orig	Sun Jan 10 15:15:35 1999
+++ sys/i386/linux/linux_file.c	Fri Jun 11 19:19:17 1999
@@ -219,6 +219,7 @@
     switch (args->cmd) {
     case LINUX_F_DUPFD:
 	fcntl_args.cmd = F_DUPFD;
+	fcntl_args.arg = args->arg;
 	return fcntl(p, &fcntl_args);
 
     case LINUX_F_GETFD:
@@ -227,6 +228,7 @@
 
     case LINUX_F_SETFD:
 	fcntl_args.cmd = F_SETFD;
+	fcntl_args.arg = args->arg;
 	return fcntl(p, &fcntl_args);
 
     case LINUX_F_GETFL:

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->sos 
Responsible-Changed-By: sos 
Responsible-Changed-When: Sat Jun 12 02:57:08 PDT 1999 
Responsible-Changed-Why:  
I'm the linuxulator guy.. 
State-Changed-From-To: open->closed 
State-Changed-By: marcel 
State-Changed-When: Sun Aug 15 07:30:16 PDT 1999 
State-Changed-Why:  
Patch applied. Thanks! 
>Unformatted:
