Linux filesystem development
 help / color / mirror / Atom feed
From: Christian Brauner <brauner@kernel.org>
To: Gabriel Ryan <gabe@cs.columbia.edu>
Cc: viro@zeniv.linux.org.uk, jack@suse.cz, linux-fsdevel@vger.kernel.org
Subject: Re: Race in fs/posix_acl.c posix_acl_update_mode and related checks on inode->i_mode in kernel v6.6
Date: Fri, 19 Jan 2024 16:04:20 +0100	[thread overview]
Message-ID: <20240119-rastplatz-sauer-b8a809f0498c@brauner> (raw)
In-Reply-To: <CALbthtcSSJig8dzTT0LNkhYOFEZCWZR1fvX8UCN2Z57_78oWnA@mail.gmail.com>

On Thu, Jan 18, 2024 at 11:30:29AM -0500, Gabriel Ryan wrote:
> We found races in the fs subsystem in kernel v6.6 using a race testing
> tool we are developing based on modified KCSAN. We are reporting the
> races because they appear to be a potential bug. The races occur on
> inode->i_mode, which is updated in
> 
> fs/posix_acl.c:722 posix_acl_update_mode
> 
> and can race with reads in the following locations:
> 
> security/selinux/hooks.c:3087 selinux_inode_permission
> include/linux/fsnotify.h:65 fsnotify_parent
> include/linux/device_cgroup.h:24 devcgroup_inode_permission
> fs/open.c:923,931 do_dentry_open
> fs/namei.c:342 acl_permission_check
> fs/namei.c:3242 may_open
> 
> 
> In cases where multiple threads are updating and accessing a single
> inode simultaneously, it seems like this could potentially lead to
> undefined behavior, if for example an access check is passed based on
> one i_mode setting, and then the inode->imode is modified by another
> thread.

Uhm, you need to provide more details than that. This is too vague to be
meaningful especially without any traces. IIRC, posix_acl_update_mode()
is called:

* when a new inode is created before it has been added to the
  d+i-cache. Unless of course, there is a filesystem that updates the
  mode of the inode _after_ the inode has been added to the d+icache.

* The other codepath would be setting an ACL directly via ->set_acl()
  through one of the setxattr() system calls. But even in that case the
  race would be semantically benign. IOW, if we passed the permission
  check on inode->i_mode and it's changed afterwads we don't care. We
  accept such races.

  So the issue you're referencing is what exactly? That the update to
  inode->i_mode can be done through a pointer when passing
  &inode->i_mode directly to posix_acl_update_mode() in which case you
  worry about torn reads/writes? So that would be fixed with a
  WRITE_ONCE() in posix_acl_update_mode()?

  reply	other threads:[~2024-01-19 15:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-18 16:30 Race in fs/posix_acl.c posix_acl_update_mode and related checks on inode->i_mode in kernel v6.6 Gabriel Ryan
2024-01-19 15:04 ` Christian Brauner [this message]
     [not found]   ` <CALbthtcRoJ_mBRmEBUmyMDw-WPpLOyAEecpu6jj+1AFBEWrkoA@mail.gmail.com>
2024-01-22 15:10     ` 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=20240119-rastplatz-sauer-b8a809f0498c@brauner \
    --to=brauner@kernel.org \
    --cc=gabe@cs.columbia.edu \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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