mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Christian Brauner <brauner@kernel.org>
To: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	ptikhomirov@virtuozzo.com, Andrey Ryabinin <arbn@yandex-team.com>,
	Linus Torvalds <torvalds@linuxfoundation.org>
Subject: Re: [PATCH] fs/coredump: open coredump file in O_WRONLY instead of O_RDWR
Date: Mon, 15 May 2023 19:55:04 +0200	[thread overview]
Message-ID: <20230515-bekochen-ertrinken-ce677c8d9e6e@brauner> (raw)
In-Reply-To: <14af0872-a7c2-0aab-b21d-189af055f528@yandex-team.ru>

On Wed, May 10, 2023 at 06:15:41PM +0300, Vladimir Sementsov-Ogievskiy wrote:
> Gently ping.
> 
> Is there any interest?

The question that I would've loved to have an answer to was why was it
made O_RDWR and not just O_WRONLY in the first place. Was there a time
when this was meaningful? Because honestly this looks innocent and
straightforward and then it always makes me go and think "Oh, there's
probably a good reason and something super obvious I'm missing.".

Funny enough, this code was originally:

    if (open_namei("core",O_CREAT | O_WRONLY | O_TRUNC,0600,&inode,NULL)

and then became:

    if (open_namei("core",O_CREAT | 2 | O_TRUNC,0600,&inode,NULL))

in

    commit 9cb9f18b5d26 ("[PATCH] Linux-0.99.10 (June 7, 1993)")

Author/applier of said patch Cced (more for the fun of referencing
Linux-0.99.10 than anything else).

So after this commit the flag combination just got copied over and over.
First when coredump handling was moved out of fs/exec.c into the
individual binfmt handlers and then again when it was moved back into
fs/exec.c and then again when it was moved to fs/coredump.c.

So that open-coded 2 added in commit 9cb9f18b5d26 ("[PATCH]
Linux-0.99.10 (June 7, 1993)") survived for 23 years until it was
replaced by Jan in 378c6520e7d2 ("fs/coredump: prevent fsuid=0 dumps
into user-controlled directories"). 

So no one could be bothered for 23 years to use O_RDWR instead of that
lonely 2 which is kinda funny. :)

In any case, I don't see anything that suggests this would cause issues.
So I'm going to pick this up unless I'm being told I'm being obviously
stupid and this absolutely needs to be O_RDWR...

> 
> On 20.04.23 15:04, Vladimir Sementsov-Ogievskiy wrote:
> > This makes it possible to make stricter apparmor profile and don't
> > allow the program to read any coredump in the system.
> > 
> > Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> > ---
> >   fs/coredump.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/fs/coredump.c b/fs/coredump.c
> > index 5df1e6e1eb2b..8f263a389175 100644
> > --- a/fs/coredump.c
> > +++ b/fs/coredump.c
> > @@ -646,7 +646,7 @@ void do_coredump(const kernel_siginfo_t *siginfo)
> >   	} else {
> >   		struct mnt_idmap *idmap;
> >   		struct inode *inode;
> > -		int open_flags = O_CREAT | O_RDWR | O_NOFOLLOW |
> > +		int open_flags = O_CREAT | O_WRONLY | O_NOFOLLOW |
> >   				 O_LARGEFILE | O_EXCL;
> >   		if (cprm.limit < binfmt->min_coredump)
> 
> -- 
> Best regards,
> Vladimir
> 

  reply	other threads:[~2023-05-15 17:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-20 12:04 Vladimir Sementsov-Ogievskiy
2023-05-10 15:15 ` Vladimir Sementsov-Ogievskiy
2023-05-15 17:55   ` Christian Brauner [this message]
2023-05-15 18:50     ` Linus Torvalds
2023-05-15 19:13       ` Linus Torvalds
2023-05-16  8:05         ` Vladimir Sementsov-Ogievskiy
2023-05-16 13:46         ` Christian Brauner
2023-05-16 13:47           ` Christian Brauner

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=20230515-bekochen-ertrinken-ce677c8d9e6e@brauner \
    --to=brauner@kernel.org \
    --cc=arbn@yandex-team.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ptikhomirov@virtuozzo.com \
    --cc=torvalds@linuxfoundation.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=vsementsov@yandex-team.ru \
    /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

all inboxes | Powered by JetHome®