linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Amir Goldstein <amir73il@gmail.com>
To: Christian Brauner <brauner@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Josef Bacik <josef@toxicpanda.com>,
	 linux-fsdevel@vger.kernel.org, viro@zeniv.linux.org.uk,
	jack@suse.cz,  david@fromorbit.com, hch@lst.de,
	Mimi Zohar <zohar@linux.ibm.com>
Subject: Re: [PATCH][RFC] fs: add levels to inode write access
Date: Fri, 31 May 2024 16:09:17 +0300	[thread overview]
Message-ID: <CAOQ4uxhCkK4H32Y8KQTrg0W3y4wpiiDBAfOs4TPLkRprKgKK3A@mail.gmail.com> (raw)
In-Reply-To: <20240531-beheben-panzerglas-5ba2472a3330@brauner>

On Fri, May 31, 2024 at 3:32 PM Christian Brauner <brauner@kernel.org> wrote:
>
> On Fri, May 31, 2024 at 12:02:16PM +0200, Christian Brauner wrote:
> > On Thu, May 30, 2024 at 08:49:12AM -0700, Linus Torvalds wrote:
> > > On Thu, 30 May 2024 at 03:32, Christian Brauner <brauner@kernel.org> wrote:
> > > >
> > > > Ofc depends on whether Linus still agrees that removing this might be
> > > > something we could try.
> > >
> > > I _definitely_ do not want to see any more complex deny_write_access().
> > >
> > > So yes, if people have good reasons to override the inode write
> > > access, I'd rather remove it entirely than make it some eldritch
> > > horror that is even worse than what we have now.
> > >
> > > It would obviously have to be tested in case some odd case actually
> > > depends on the ETXTBSY semantics, since we *have* supported it for a
> > > long time.  But iirc nobody even noticed when we removed it from
> > > shared libraries, so...
> > >
> > > That said, verity seems to depend on it as a way to do the
> > > "enable_verity()" atomically with no concurrent writes, and I see some
> > > i_writecount noise in the integrity code too.

This one is a bit more challenging.
The IMA ima_bprm_check() LSM hook (called from exec_binprm() context)
may read the file (in ima_collect_measurement()) and record the signature
of the file to be executed, assuming that it cannot be modified.
Not sure how to deal with this expectation.

Only thing I could think of is that IMA would be allowed to
deny_write_access() and set FMODE_EXEC_DENY_WRITE
as a hint for do_close_execat() to allow_write_access(), but
it's pretty ugly, I admit.

> > >
> > > But maybe that's just a belt-and-suspenders thing?
> > >
> > > Because if execve() no longer does it, I think we should just remove
> > > that i_writecount thing entirely.
> >
> > deny_write_access() is being used from kernel_read_file() which has a
> > few wrappers around it and they are used in various places:
> >
> > (1) kernel_read_file() based helpers:
> >   (1.1) kernel_read_file_from_path()
> >   (1.2) kernel_read_file_from_path_initns()
> >   (1.3) kernel_read_file_from_fd()
> >
> > (2) kernel_read_file() users:
> >     (2.1) kernel/module/main.c:init_module_from_file()
> >     (2.2) security/loadpin/loadpin.c:read_trusted_verity_root_digests()
> >
> > (3) kernel_read_file_from_path() users:
> >     (3.1) security/integrity/digsig.c:integrity_load_x509()
> >     (3.2) security/integrity/ima/ima_fs.c:ima_read_busy()
> >
> > (4) kernel_read_file_from_path_initns() users:
> >     (4.1) drivers/base/firmware_loader/main.c:fw_get_filesystem_firmware()
> >
> > (5) kernel_read_file_from_fd() users:
> >     (5.1) kernel/kexec_file.c:kimage_file_prepare_segments()
> >
> > In order to remove i_writecount completely we would need to do this in
>
> Sorry, typo s/i_write_count/deny_write_access()/g
> (I don't think we can remove i_writecount itself as it's used for file
> leases and locks.)

Indeed, i_writecount (as does i_readcount) is used by fs/locks.c:
check_conflicting_open(), but not as a synchronization primitive.

>
> > multiple steps as some of that stuff seems potentially sensitive.
> >
> > The exec deny write mechanism can be removed because we have a decent
> > understanding of the implications and there's decent justification for
> > removing it.
> >
> > So I propose that I do various testing (LTP) etc. now, send the patch
> > and then put this into -next to see if anything breaks?

Wouldn't hurt to see what else we are missing.

Thanks,
Amir.

  parent reply	other threads:[~2024-05-31 13:09 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-29 20:41 [PATCH][RFC] fs: add levels to inode write access Josef Bacik
2024-05-29 22:00 ` Jeff Layton
2024-05-30  1:14 ` Matthew Wilcox
2024-05-30 10:32 ` Christian Brauner
2024-05-30 12:57   ` Amir Goldstein
2024-05-30 14:58   ` Josef Bacik
2024-05-30 15:23   ` Christian Brauner
2024-05-30 15:49   ` Linus Torvalds
2024-05-31 10:02     ` Christian Brauner
2024-05-31 12:32       ` Christian Brauner
2024-05-31 13:01         ` [PATCH] fs: don't block i_writecount during exec Christian Brauner
2024-05-31 15:40           ` Linus Torvalds
2024-05-31 18:08             ` Jeff Layton
2024-05-31 22:08           ` Josef Bacik
2024-06-03 13:52           ` (subset) " Christian Brauner
2024-06-06 12:45           ` Aishwarya TCV
2024-06-06 15:37             ` Mark Brown
2024-06-06 16:53               ` Josef Bacik
2024-06-06 17:33                 ` Mark Brown
2024-06-06 17:49                   ` Mark Brown
2024-08-07  9:59                     ` Tudor Ambarus
2024-09-04 17:04           ` Jann Horn
2024-09-05  7:38             ` Roberto Sassu
2024-05-31 13:09         ` Amir Goldstein [this message]
2024-05-31 14:50           ` [PATCH][RFC] fs: add levels to inode write access Christian Brauner
2024-05-31 15:47             ` Matthew Wilcox
2024-05-31 22:14               ` Matthew Wilcox

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=CAOQ4uxhCkK4H32Y8KQTrg0W3y4wpiiDBAfOs4TPLkRprKgKK3A@mail.gmail.com \
    --to=amir73il@gmail.com \
    --cc=brauner@kernel.org \
    --cc=david@fromorbit.com \
    --cc=hch@lst.de \
    --cc=jack@suse.cz \
    --cc=josef@toxicpanda.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=zohar@linux.ibm.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;
as well as URLs for NNTP newsgroup(s).