mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Vinicius Costa Gomes <vinicius.gomes@intel.com>
To: brauner@kernel.org, amir73il@gmail.com, hu1.chen@intel.com
Cc: miklos@szeredi.hu, malini.bhandaru@intel.com,
	tim.c.chen@intel.com, mikko.ylinen@intel.com,
	linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Vinicius Costa Gomes <vinicius.gomes@intel.com>
Subject: [PATCH overlayfs-next v3 4/4] fs/overlayfs: Drop creds usage decrement for ovl_setup_for_create()
Date: Tue,  5 Nov 2024 11:35:14 -0800	[thread overview]
Message-ID: <20241105193514.828616-5-vinicius.gomes@intel.com> (raw)
In-Reply-To: <20241105193514.828616-1-vinicius.gomes@intel.com>

After the previous commit, we do not need to modify the mounter
credentials (returned by override_creds()) 'usage' counter when
preparing for "create" operations, as 'usage' will be kept constant.

Add a warning to verify that we are indeed working with the mounter
credentials (stored in the superblock). Failure in this assumption
means that creds may leak.

Suggested-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
---
 fs/overlayfs/dir.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/fs/overlayfs/dir.c b/fs/overlayfs/dir.c
index 74769d47c8ae..de012db6c169 100644
--- a/fs/overlayfs/dir.c
+++ b/fs/overlayfs/dir.c
@@ -571,7 +571,12 @@ static int ovl_setup_cred_for_create(struct dentry *dentry, struct inode *inode,
 		put_cred(override_cred);
 		return err;
 	}
-	put_cred(override_creds(override_cred));
+
+	/*
+	 * We must be called with creator creds already, otherwise we risk
+	 * leaking creds.
+	 */
+	WARN_ON_ONCE(override_creds(override_cred) != ovl_creds(dentry->d_sb));
 	put_cred(override_cred);
 
 	return 0;
-- 
2.47.0


  parent reply	other threads:[~2024-11-05 19:35 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-05 19:35 [PATCH overlayfs-next v3 0/4] overlayfs: Optimize override/revert creds Vinicius Costa Gomes
2024-11-05 19:35 ` [PATCH overlayfs-next v3 1/4] cred: Add a light version of override/revert_creds() Vinicius Costa Gomes
2024-11-06 18:56   ` kernel test robot
2024-11-05 19:35 ` [PATCH overlayfs-next v3 2/4] fs/backing-file: Convert to revert/override_creds_light() Vinicius Costa Gomes
2024-11-05 19:35 ` [PATCH overlayfs-next v3 3/4] fs/overlayfs: Optimize override/revert creds Vinicius Costa Gomes
2024-11-05 19:35 ` Vinicius Costa Gomes [this message]
2024-11-05 20:47 ` [PATCH overlayfs-next v3 0/4] overlayfs: " Amir Goldstein
2024-11-05 22:27   ` Vinicius Costa Gomes

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=20241105193514.828616-5-vinicius.gomes@intel.com \
    --to=vinicius.gomes@intel.com \
    --cc=amir73il@gmail.com \
    --cc=brauner@kernel.org \
    --cc=hu1.chen@intel.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=malini.bhandaru@intel.com \
    --cc=mikko.ylinen@intel.com \
    --cc=miklos@szeredi.hu \
    --cc=tim.c.chen@intel.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

all inboxes | Powered by JetHome®