public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Sergey Bugaev <bugaevc@gmail.com>
To: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
Cc: "Cristian Rodríguez" <crrodriguez@opensuse.org>,
	libc-alpha@sourceware.org, bug-hurd <bug-hurd@gnu.org>,
	"Samuel Thibault" <samuel.thibault@gnu.org>
Subject: Re: [RFC PATCH v2 4/7] csu: Fix standard fds' mode
Date: Thu, 20 Apr 2023 00:16:22 +0300	[thread overview]
Message-ID: <CAN9u=HfbJVhcGut5MEVdS6ZT45pEMg4iL9Rb0P47hEYPEkj6Lw@mail.gmail.com> (raw)
In-Reply-To: <cfe2cef6-bac7-d934-e3bd-935f3e84f5ab@linaro.org>

On Wed, Apr 19, 2023 at 11:45 PM Adhemerval Zanella Netto
<adhemerval.zanella@linaro.org> wrote:
> > I might be missing something, but why statically linked only? I don't
> > see anything like that in elf/Makefile (but maybe I don't know where
> > to look, please tell me!), and also the same behavior is certainly
> > exhibited by dynamically linked executables too. That ls -l I posted
> > above is from a dynamic executable.
>
> At least on Hurd, __libc_check_standard_fds is only built for !SHARED.

Right, so I see that there is a separate Hurd version of this. My
patch attempted to change the generic csu/check_fds.c, not the Hurd
version. (Maybe there's no need to add O_IGNORE_CTTY into the generic
version then).

In the Hurd version all the logic is in init_standard_fds (which runs
through the _hurd_fd_subinit hook) and not in
__libc_check_standard_fds (), which is empty and indeed only built
for !SHARED -- as the comment there says, to make sure this file is
pulled in when linking against libc.a.

Also the Hurd version still does

  check_one_fd (STDIN_FILENO, O_RDONLY);
  check_one_fd (STDOUT_FILENO, O_RDWR);
  check_one_fd (STDERR_FILENO, O_RDWR);

and opens /dev/null (not /dev/full), so in any case either the
generic one needs changes, or the Hurd one. If we want to port the
"always fail" change onto the Hurd version, we can take advantage of
the fact that on the Hurd we can truly open /dev/null with mode = 0
(not O_RDONLY), and it will be neither readable nor writable.

> >> is this really needed now? playing silly games with this fds will always result in silly prices.
>
> My understanding of this code is to enforce that on setuid program with
> stdin/stdout/stderr closed any operation fail.

Yes, but is that still considered desirable / a good idea? As opposed
to making such operations no-op successfully (opening /dev/null with
the expected mode).

Sergey

  reply	other threads:[~2023-04-19 21:16 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-19 16:02 [RFC PATCH v2 0/7] O_IGNORE_CTTY everywhere & misc fixes Sergey Bugaev
2023-04-19 16:02 ` [RFC PATCH v2 1/7] misc: Convert daemon () to GNU coding style Sergey Bugaev
2023-04-21 12:18   ` Adhemerval Zanella Netto
2023-04-22 11:47     ` Samuel Thibault
2023-04-19 16:02 ` [RFC PATCH v2 2/7] misc: Ignore SIGHUP in daemon () while forking Sergey Bugaev
2023-04-21 12:55   ` Adhemerval Zanella Netto
2023-04-19 16:02 ` [RFC PATCH v2 3/7] Use O_CLOEXEC in more places (BZ #15722) Sergey Bugaev
2023-04-21 12:55   ` Adhemerval Zanella Netto
2023-04-22 11:50     ` Samuel Thibault
2023-04-19 16:02 ` [RFC PATCH v2 4/7] csu: Fix standard fds' mode Sergey Bugaev
2023-04-19 19:13   ` Cristian Rodríguez
2023-04-19 19:40     ` Sergey Bugaev
2023-04-19 20:45       ` Adhemerval Zanella Netto
2023-04-19 21:16         ` Sergey Bugaev [this message]
2023-04-20 11:47           ` Adhemerval Zanella Netto
2023-04-20 12:06             ` Cristian Rodríguez
2023-04-20 15:13               ` Adhemerval Zanella Netto
2023-04-21 17:16               ` Paul Eggert
2023-04-19 16:02 ` [RFC PATCH v2 5/7] hurd: Make dl-sysdep's open () cope with O_IGNORE_CTTY Sergey Bugaev
2023-04-20 21:06   ` Samuel Thibault
2023-04-19 16:02 ` [RFC PATCH v2 6/7] include/fcntl.h: Define O_IGNORE_CTTY Sergey Bugaev
2023-04-19 16:02 ` [RFC PATCH v2 7/7] Use O_IGNORE_CTTY where appropriate Sergey Bugaev

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='CAN9u=HfbJVhcGut5MEVdS6ZT45pEMg4iL9Rb0P47hEYPEkj6Lw@mail.gmail.com' \
    --to=bugaevc@gmail.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=bug-hurd@gnu.org \
    --cc=crrodriguez@opensuse.org \
    --cc=libc-alpha@sourceware.org \
    --cc=samuel.thibault@gnu.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).