GNU bug report logs - #38396
internal fds leak across exec

Previous Next

Package: guile;

Reported by: Zefram <zefram <at> fysh.org>

Date: Wed, 27 Nov 2019 05:36:01 UTC

Severity: normal

To reply to this bug, email your comments to 38396 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-guile <at> gnu.org:
bug#38396; Package guile. (Wed, 27 Nov 2019 05:36:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Zefram <zefram <at> fysh.org>:
New bug report received and forwarded. Copy sent to bug-guile <at> gnu.org. (Wed, 27 Nov 2019 05:36:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Zefram <zefram <at> fysh.org>
To: bug-guile <at> gnu.org
Subject: internal fds leak across exec
Date: Wed, 27 Nov 2019 05:34:38 +0000
Where Guile opens a file in order to read code from it, that file
descriptor ought to be private to Guile, in the sense that it should
not be passed on to another program across exec.  But it is so leaked,
as can be seen especially clearly using Linux's /proc/*/fd feature:

$ cat /tmp/t0
(system
  (string-append "ls -l /proc/" (number->string (getpid))
    "/fd; ls -l /proc/self/fd"))
$ guile-2.2.6 --no-auto-compile -s /tmp/t0
total 0
lrwx------ 1 zefram zefram 64 Nov 27 05:21 0 -> /dev/pts/4
lrwx------ 1 zefram zefram 64 Nov 27 05:21 1 -> /dev/pts/4
lrwx------ 1 zefram zefram 64 Nov 27 05:21 2 -> /dev/pts/4
lr-x------ 1 zefram zefram 64 Nov 27 05:21 3 -> pipe:[59357425]
l-wx------ 1 zefram zefram 64 Nov 27 05:21 4 -> pipe:[59357425]
lr-x------ 1 zefram zefram 64 Nov 27 05:21 5 -> pipe:[59357426]
l-wx------ 1 zefram zefram 64 Nov 27 05:21 6 -> pipe:[59357426]
lr-x------ 1 zefram zefram 64 Nov 27 05:21 7 -> /tmp/t0
total 0
lrwx------ 1 zefram zefram 64 Nov 27 05:21 0 -> /dev/pts/4
lrwx------ 1 zefram zefram 64 Nov 27 05:21 1 -> /dev/pts/4
lrwx------ 1 zefram zefram 64 Nov 27 05:21 2 -> /dev/pts/4
lr-x------ 1 zefram zefram 64 Nov 27 05:21 3 -> /proc/3649/fd
lr-x------ 1 zefram zefram 64 Nov 27 05:21 7 -> /tmp/t0
$

Observe that the Guile process has open both the script file and a couple
of pipes.  The ls process also has a file descriptor on the script file,
though it does not have the pipes open.  Clearly Guile has leaked the
script fd, but has avoided leaking the pipe fds.

The script fd ought to have the FD_CLOEXEC flag set.  Preferably,
that flag should be set immediately upon opening the file, by means of
the O_CLOEXEC flag.  I note that pipes opened by the thread system are
already opened with O_CLOEXEC.

Guile 2.0 behaves the same as 2.2 in this respect.  Guile 1.8 leaks
both the script fd and the pipe fds.  Guile 1.6 doesn't open any pipes
in this test, and also leaks the script fd.

-zefram




This bug report was last modified 4 years and 152 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.