From: Karel Zak <kzak@redhat.com>
To: Sami Kerola <kerolasa@iki.fi>
Cc: util-linux@vger.kernel.org
Subject: Re: [PATCH 04/12] agetty: fix chown(3), chmod(3) and open(3) race
Date: Mon, 9 Nov 2015 10:01:18 +0100 [thread overview]
Message-ID: <20151109090118.GS19508@ws.net.home> (raw)
In-Reply-To: <1446319284-24778-5-git-send-email-kerolasa@iki.fi>
On Sat, Oct 31, 2015 at 07:21:16PM +0000, Sami Kerola wrote:
> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
> ---
> term-utils/agetty.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/term-utils/agetty.c b/term-utils/agetty.c
> index 0237b79..a9c8785 100644
> --- a/term-utils/agetty.c
> +++ b/term-utils/agetty.c
> @@ -1004,23 +1004,23 @@ static void open_tty(char *tty, struct termios *tp, struct options *op)
> (int)sizeof(buf)) || (len < 0))
> log_err(_("/dev/%s: cannot open as standard input: %m"), tty);
>
> + /* Open the tty as standard input. */
> + if ((fd = open(buf, O_RDWR|O_NOCTTY|O_NONBLOCK, 0)) < 0)
> + log_err(_("/dev/%s: cannot open as standard input: %m"), tty);
> +
> /*
> * There is always a race between this reset and the call to
> * vhangup() that s.o. can use to get access to your tty.
> * Linux login(1) will change tty permissions. Use root owner and group
> * with permission -rw------- for the period between getty and login.
> */
> - if (chown(buf, 0, gid) || chmod(buf, (gid ? 0620 : 0600))) {
> + if (fchown(fd, 0, gid) || fchmod(fd, (gid ? 0620 : 0600))) {
Note that this is only a cosmetic change, because we re-open() the tty
later (and it's not dangerous due to vhangup & friends in login(1)).
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
next prev parent reply other threads:[~2015-11-09 9:01 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-31 19:21 [PATCH 00/12] pull: race fixes Sami Kerola
2015-10-31 19:21 ` [PATCH 01/12] login: fix stat(2) race Sami Kerola
2015-10-31 19:21 ` [PATCH 02/12] swapon: fix stat(3) and open(3) race Sami Kerola
2015-10-31 19:21 ` [PATCH 03/12] fsck: retire stat(3) when access(3) does better job Sami Kerola
2015-10-31 19:21 ` [PATCH 04/12] agetty: fix chown(3), chmod(3) and open(3) race Sami Kerola
2015-11-09 9:01 ` Karel Zak [this message]
2015-10-31 19:21 ` [PATCH 05/12] script, hwclock: check file exist with access(3) rather than stat(3) Sami Kerola
2015-11-09 8:43 ` Karel Zak
2015-10-31 19:21 ` [PATCH 06/12] lib/fileutils: add is_same_inode() check Sami Kerola
2015-11-09 8:54 ` Karel Zak
2015-10-31 19:21 ` [PATCH 07/12] include/blkdev: add open_blkdev_or_file() function Sami Kerola
2015-11-09 8:51 ` Karel Zak
2015-11-22 21:27 ` Sami Kerola
2015-10-31 19:21 ` [PATCH 08/12] mkfs.bfs: fix block device open race Sami Kerola
2015-11-09 8:48 ` Karel Zak
2015-11-22 21:24 ` Sami Kerola
2015-10-31 19:21 ` [PATCH 09/12] mkfs.minix: " Sami Kerola
2015-10-31 19:21 ` [PATCH 10/12] mkswap: " Sami Kerola
2015-10-31 19:21 ` [PATCH 11/12] mesg: fix multiple races Sami Kerola
2015-10-31 19:21 ` [PATCH 12/12] fdformat: fix block device open race Sami Kerola
2015-11-09 8:58 ` [PATCH 00/12] pull: race fixes Karel Zak
2015-12-02 9:54 ` Karel Zak
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=20151109090118.GS19508@ws.net.home \
--to=kzak@redhat.com \
--cc=kerolasa@iki.fi \
--cc=util-linux@vger.kernel.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