From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 486891DA3A; Mon, 18 Dec 2023 21:57:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="hDsMDIIM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702936659; x=1734472659; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=UTSFwDQbGfcrEl1amDoPvVacSO4lCY7esjcaPwWu+8s=; b=hDsMDIIMxNDXWso+rRNEhmYd9g1qOqgorTRtIL2GMACS4adIBW0CEA+2 HSlNuKF7kETrZAV96G4Z02dGgVOv40lcbdvDDOIojiuiGCZPadno0Pk3L nYCeC+qzt8r8Sz/pZ7rYi6rLHX5Dfg9DDYQJnW6BaZTbK8PtHb7aE81sB S6d1iTwxT/OjwmMleXyJajNh1OESHGQDF5ze+pLd6yG4hAhyei+7pnF/Y 54Z/v0ZO7E2KKtiEBB9MDYD66ZTw9FHXU57Vh+jyNgRQzUBVYGwBEDBrA 1TELq5RU3wap5D/yDs8ByhalrZaXjfizqn8P1KUdSsdomAzH/JSEXT0gi Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10928"; a="9019283" X-IronPort-AV: E=Sophos;i="6.04,286,1695711600"; d="scan'208";a="9019283" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Dec 2023 13:57:38 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10928"; a="919408264" X-IronPort-AV: E=Sophos;i="6.04,286,1695711600"; d="scan'208";a="919408264" Received: from jamesgou-mobl1.amr.corp.intel.com (HELO vcostago-mobl3) ([10.213.162.171]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Dec 2023 13:57:34 -0800 From: Vinicius Costa Gomes To: Christian Brauner , Amir Goldstein Cc: hu1.chen@intel.com, miklos@szeredi.hu, malini.bhandaru@intel.com, tim.c.chen@intel.com, mikko.ylinen@intel.com, lizhen.you@intel.com, linux-unionfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel , Linus Torvalds , David Howells , Seth Forshee Subject: Re: [RFC] HACK: overlayfs: Optimize overlay/restore creds In-Reply-To: <20231218-intim-lehrstellen-dbe053d6c3a8@brauner> References: <20231214220222.348101-1-vinicius.gomes@intel.com> <87v88zp76v.fsf@intel.com> <20231218-intim-lehrstellen-dbe053d6c3a8@brauner> Date: Mon, 18 Dec 2023 13:57:31 -0800 Message-ID: <875y0vp41g.fsf@intel.com> Precedence: bulk X-Mailing-List: linux-unionfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain Christian Brauner writes: >> > Yes, the important thing is that an object cannot change >> > its non_refcount property during its lifetime - >> >> ... which means that put_creds_ref() should assert that >> there is only a single refcount - the one handed out by >> prepare_creds_ref() before removing non_refcount or >> directly freeing the cred object. >> >> I must say that the semantics of making a non-refcounted copy >> to an object whose lifetime is managed by the caller sounds a lot >> less confusing to me. > > So can't we do an override_creds() variant that is effectively just: > > /* caller guarantees lifetime of @new */ > const struct cred *foo_override_cred(const struct cred *new) > { > const struct cred *old = current->cred; > rcu_assign_pointer(current->cred, new); > return old; > } > > /* caller guarantees lifetime of @old */ > void foo_revert_creds(const struct cred *old) > { > const struct cred *override = current->cred; > rcu_assign_pointer(current->cred, old); > } > > Maybe I really fail to understand this problem or the proposed solution: > the single reference that overlayfs keeps in ovl->creator_cred is tied > to the lifetime of the overlayfs superblock, no? And anyone who needs a > long term cred reference e.g, file->f_cred will take it's own reference > anyway. So it should be safe to just keep that reference alive until > overlayfs is unmounted, no? I'm sure it's something quite obvious why > that doesn't work but I'm just not seeing it currently. My read of the code says that what you are proposing should work. (what I am seeing is that in the "optimized" cases, the only practical effect of override/revert is the rcu_assign_pointer() dance) I guess that the question becomes: Do we want this property (that the 'cred' associated with a subperblock/similar is long lived and the "inner" refcount can be omitted) to be encoded in the constructor? Or do we want it to be "encoded" in a call by call basis? I can see both working. Cheers, -- Vinicius