Openembedded Core Discussions
 help / color / mirror / Atom feed
From: "Seebs" <seebs@seebs.net>
To: "Yu, Mingli" <mingli.yu@windriver.com>
Cc: <openembedded-core@lists.openembedded.org>,
	<randy.macleod@windriver.com>, <pavelmn@axis.com>
Subject: Re: [OE-core] [pseudo][PATCH] pseudo_util.c: Open file with O_CLOEXEC to avoid fd leak
Date: Thu, 9 Apr 2020 00:25:56 -0500	[thread overview]
Message-ID: <20200409002556.4eb074a2@seebsdell> (raw)
In-Reply-To: <1586399921-418794-1-git-send-email-mingli.yu@windriver.com>

On Thu, 9 Apr 2020 10:38:41 +0800
"Yu, Mingli" <mingli.yu@windriver.com> wrote:

> -	fd = open(pseudo_path, O_WRONLY | O_APPEND | O_CREAT, 0644);
> +	fd = open(pseudo_path, O_WRONLY | O_APPEND | O_CREAT |
> O_CLOEXEC, 0644);

I'm not confident in this.

This code is shared between the pseudo client and the pseudo server. In
the pseudo server, it's possible that we coincidentally end up with fd
being 2 already. In that case, we'd end up with this fd on 2, but then
on exec (such as when execing the server) we'd possibly end up with it
closed?

Looking more closely, dup2 will clear the CLOEXEC flag, so in the
server path, if prefer_fd is 2 and fd doesn't start out as 2, we end up
with it cleared...

But also so far as I can tell the code around the dup2 call there is
probably generally wrong; it's explicitly closing the previous holder of
that descriptor, which is unnecessary, and checking whether the file
descriptor is already the desired one, which is also unnecessary. So
this might need to be revisited.

Looking at it more, the only time this seems like it should be relevant
would be in the case where we're in the pseudo client, but
PSEUDO_DEBUG_FILE is set in the environment. Otherwise, the client
should end up just using stderr, and the server shouldn't care because
it's expecting this to be fd 2 and we probably want the child process
to end up with fd 2 open.

What's the observed failure mode that we're fixing?

-s

  parent reply	other threads:[~2020-04-09  5:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-09  2:38 [pseudo][PATCH] pseudo_util.c: Open file with O_CLOEXEC to avoid fd leak Yu, Mingli
2020-04-09  3:02 ` ✗ patchtest: failure for " Patchwork
2020-04-09  5:25 ` Seebs [this message]
2020-04-09  6:30   ` [OE-core] [pseudo][PATCH] " Yu, Mingli
2020-04-09 15:17     ` Seebs

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200409002556.4eb074a2@seebsdell \
    --to=seebs@seebs.net \
    --cc=mingli.yu@windriver.com \
    --cc=openembedded-core@lists.openembedded.org \
    --cc=pavelmn@axis.com \
    --cc=randy.macleod@windriver.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox