mainThe GNU Bourne-Again SHell - Support: sr #110788, Bash leaks file fd to child...

 
 

sr #110788: Bash leaks file fd to child processes

Submitter:  wangyuhang <rokutowang>
Submitted:  Sat 26 Nov 2022 10:19:52 AM UTC
   
 
Category:  None Priority:  5 - Normal
Severity:  3 - Normal Status:  Invalid
Privacy:  Public Assigned to:  None
Open/Closed:  Open Operating System:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Sat 26 Nov 2022 10:19:52 AM UTC, original submission:  

Hello,

I find that the file descriptor leaks when I execute the command pvs in bash 5.2, The abnormal scenario is similar to the bug which reported by http://lists.gnu.org/archive/html/bug-bash/2017-01/msg00026.html

When I execute pvs in the terminal opened through xshell,it’s ok

> PV         VG      Fmt  Attr PSize    PFree
>  /dev/sda2  euleros lvm2 a--  <126.00g    0


But when I execute pvs in the terminal opened through vscode(use Remote-SHH to connect linux), the File descriptor was leaked

>File descriptor 19 (/dev/ptmx) leaked on pvs invocation. Parent PID 3789: /usr/bin/bash
>File descriptor 20 (/dev/ptmx) leaked on pvs invocation. Parent PID 3789: /usr/bin/bash
>File descriptor 21 (/dev/ptmx) leaked on pvs invocation. Parent PID 3789: /usr/bin/bash
>File descriptor 99 (/root/.vscode-server/bin/899d46d82c4c95423fb7e10e68eba52050e30ba3/vscode-remote-lock.root.899d46d82c4c95423fb7e10e68eba52050e30ba3) leaked on pvs invocation. Parent PID 3789: /usr/bin/bash
>  PV         VG      Fmt  Attr PSize    PFree
>  /dev/sda2  euleros lvm2 a--  <126.00g    0


I found that the leaked file descriptor was created in subst.c

> /* Pipe the output of executing STRING into the current shell. */
> if (pipe(fildes) < 0)
> {
>     sys_error("%s", _("cannot make pipe for command substitution"));
>     goto error_exit;
> }

add it leaked in

> if (--bufn <= 0)
> {
>     SET_CLOSE_ON_EXEC(fd);
>     bufn = zread(fd, buf, sizeof(buf));
>     if (bufn <= 0)
>         break;
>     bufp = buf;
> }


I try to add SET_CLOSE_ON_EXEC (fd) before zread, but it doesn't seem to work.

wangyuhang <rokutowang>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by chet (Updated the item)
  • -email is unavailable- added by rokutowang (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-11-29 chet StatusNone Invalid

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code