Linux filesystem development
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Shakeel Butt <shakeel.butt@linux.dev>
Cc: "Christian Brauner" <brauner@kernel.org>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Michal Koutný" <mkoutny@suse.com>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Jori Koolstra" <jkoolstra@xs4all.nl>,
	"Meta kernel team" <kernel-team@meta.com>,
	cgroups@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	driver-core@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] cgroup: allocate the inode for cgroup_may_write() before cgroup_mutex
Date: Fri, 20 Nov 2026 01:24:18 -1000	[thread overview]
Message-ID: <b8b2c07c12f5a156e2d72ab4ee4444cc@kernel.org> (raw)
In-Reply-To: <20261118230346.3700213-1-shakeel.butt@linux.dev>

Hello, Shakeel.

On Wed, Nov 18, 2026 at 03:03:45PM -0800, Shakeel Butt wrote:
> +	dst_cgrp = cgroup_kn_break_active(of->kn);
>  	if (IS_ERR(dst_cgrp))
>  		return PTR_ERR(dst_cgrp);
> +	new = new_inode(of->file->f_path.dentry->d_sb);
> +	cgroup_lock();

I don't really like new_inode() being called on every write, and twice on
every clone3(CLONE_INTO_CGROUP). The inode is often not cached but not
mostly. It's not a lot of overhead, but doing it the right way isn't that
complicated either. How about peeking at the inode cache before taking the
locks, preallocating only when the peek misses, and then looking up again
under cgroup_mutex? If the peek turns out wrong, it can drop the locks,
allocate and retry, so that nothing is allocated under the lock. Can we
apply the same shape in other places too?

> 	scoped_with_creds(of->file->f_cred)
> -		ret = cgroup_attach_permissions(src_cgrp, dst_cgrp,
> -						of->file->f_path.dentry->d_sb,
> +		ret = cgroup_attach_permissions(src_cgrp, dst_cgrp, &new,
> 						threadgroup, ctx->ns);

AFAICS, this changes behavior under Smack. Smack labels a new inode from the
allocating task's creds, and the allocation used to be inside
scoped_with_creds(). Now the inode gets the writer's label and the
permission check runs with the opener's creds, which can fail when the two
differ. Maybe the allocation can use the opener's creds too?

Thanks.

--
tejun

      reply	other threads:[~2026-11-20 11:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 23:03 [PATCH] cgroup: allocate the inode for cgroup_may_write() before cgroup_mutex Shakeel Butt
2026-11-20 11:24 ` Tejun Heo [this message]

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=b8b2c07c12f5a156e2d72ab4ee4444cc@kernel.org \
    --to=tj@kernel.org \
    --cc=brauner@kernel.org \
    --cc=cgroups@vger.kernel.org \
    --cc=driver-core@lists.linux.dev \
    --cc=gregkh@linuxfoundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=jkoolstra@xs4all.nl \
    --cc=kernel-team@meta.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mkoutny@suse.com \
    --cc=shakeel.butt@linux.dev \
    /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