All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cachefiles: do not yet allow on idmapped mounts
@ 2021-03-24  8:51 David Howells
  0 siblings, 0 replies; 6+ messages in thread
From: David Howells @ 2021-03-24  8:51 UTC (permalink / raw)
  To: torvalds
  Cc: Christian Brauner, linux-cachefs, dhowells, linux-fsdevel, linux-kernel

From: Christian Brauner <christian.brauner@ubuntu.com>

Based on discussions (e.g. in [1]) my understanding of cachefiles and
the cachefiles userspace daemon is that it creates a cache on a local
filesystem (e.g. ext4, xfs etc.) for a network filesystem. The way this
is done is by writing "bind" to /dev/cachefiles and pointing it to the
directory to use as the cache.
Currently this directory can technically also be an idmapped mount but
cachefiles aren't yet fully aware of such mounts and thus don't take the
idmapping into account when creating cache entries. This could leave
users confused as the ownership of the files wouldn't match to what they
expressed in the idmapping. Block cache files on idmapped mounts until
the fscache rework is done and we have ported it to support idmapped
mounts.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Cc: linux-cachefs@redhat.com
Link: https://lore.kernel.org/lkml/20210303161528.n3jzg66ou2wa43qb@wittgenstein [1]
Link: https://lore.kernel.org/r/20210316112257.2974212-1-christian.brauner@ubuntu.com/ # v1
Link: https://listman.redhat.com/archives/linux-cachefs/2021-March/msg00044.html # v2
Link: https://lore.kernel.org/r/20210319114146.410329-1-christian.brauner@ubuntu.com/ # v3
---

 fs/cachefiles/bind.c |    6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
index dfb14dbddf51..38bb7764b454 100644
--- a/fs/cachefiles/bind.c
+++ b/fs/cachefiles/bind.c
@@ -118,6 +118,12 @@ static int cachefiles_daemon_add_cache(struct cachefiles_cache *cache)
 	cache->mnt = path.mnt;
 	root = path.dentry;
 
+	ret = -EINVAL;
+	if (mnt_user_ns(path.mnt) != &init_user_ns) {
+		pr_warn("File cache on idmapped mounts not supported");
+		goto error_unsupported;
+	}
+
 	/* check parameters */
 	ret = -EOPNOTSUPP;
 	if (d_is_negative(root) ||



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] cachefiles: do not yet allow on idmapped mounts
  2021-03-17 14:25   ` Dan Carpenter
  (?)
@ 2021-03-17 17:15   ` Christian Brauner
  -1 siblings, 0 replies; 6+ messages in thread
From: Christian Brauner @ 2021-03-17 17:15 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 648 bytes --]

On Wed, Mar 17, 2021 at 05:25:11PM +0300, Dan Carpenter wrote:
> Hi Christian,
> 
> url:    https://github.com/0day-ci/linux/commits/Christian-Brauner/cachefiles-do-not-yet-allow-on-idmapped-mounts/20210316-192557
> base:   1e28eed17697bcf343c6743f0028cc3b5dd88bf0
> config: x86_64-randconfig-m001-20210317 (attached as .config)
> compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
> 
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@intel.com>
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

Hey Dan,

Thanks! I already sent out a v2 yesterday that fixes this problem. :)
Christian

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] cachefiles: do not yet allow on idmapped mounts
  2021-03-16 11:22 Christian Brauner
@ 2021-03-17 14:25   ` Dan Carpenter
  0 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2021-03-17 14:25 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 14952 bytes --]

Hi Christian,

url:    https://github.com/0day-ci/linux/commits/Christian-Brauner/cachefiles-do-not-yet-allow-on-idmapped-mounts/20210316-192557
base:   1e28eed17697bcf343c6743f0028cc3b5dd88bf0
config: x86_64-randconfig-m001-20210317 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

New smatch warnings:
fs/cachefiles/bind.c:247 cachefiles_daemon_add_cache() error: uninitialized symbol 'root'.

vim +/root +247 fs/cachefiles/bind.c

9ae326a69004de David Howells        2009-04-03   81  static int cachefiles_daemon_add_cache(struct cachefiles_cache *cache)
9ae326a69004de David Howells        2009-04-03   82  {
9ae326a69004de David Howells        2009-04-03   83  	struct cachefiles_object *fsdef;
b0446be4be4476 Al Viro              2009-08-09   84  	struct path path;
9ae326a69004de David Howells        2009-04-03   85  	struct kstatfs stats;
9ae326a69004de David Howells        2009-04-03   86  	struct dentry *graveyard, *cachedir, *root;
9ae326a69004de David Howells        2009-04-03   87  	const struct cred *saved_cred;
9ae326a69004de David Howells        2009-04-03   88  	int ret;
9ae326a69004de David Howells        2009-04-03   89  
9ae326a69004de David Howells        2009-04-03   90  	_enter("");
9ae326a69004de David Howells        2009-04-03   91  
9ae326a69004de David Howells        2009-04-03   92  	/* we want to work under the module's security ID */
9ae326a69004de David Howells        2009-04-03   93  	ret = cachefiles_get_security_ID(cache);
9ae326a69004de David Howells        2009-04-03   94  	if (ret < 0)
9ae326a69004de David Howells        2009-04-03   95  		return ret;
9ae326a69004de David Howells        2009-04-03   96  
9ae326a69004de David Howells        2009-04-03   97  	cachefiles_begin_secure(cache, &saved_cred);
9ae326a69004de David Howells        2009-04-03   98  
9ae326a69004de David Howells        2009-04-03   99  	/* allocate the root index object */
9ae326a69004de David Howells        2009-04-03  100  	ret = -ENOMEM;
9ae326a69004de David Howells        2009-04-03  101  
9ae326a69004de David Howells        2009-04-03  102  	fsdef = kmem_cache_alloc(cachefiles_object_jar, GFP_KERNEL);
9ae326a69004de David Howells        2009-04-03  103  	if (!fsdef)
9ae326a69004de David Howells        2009-04-03  104  		goto error_root_object;
9ae326a69004de David Howells        2009-04-03  105  
9ae326a69004de David Howells        2009-04-03  106  	ASSERTCMP(fsdef->backer, ==, NULL);
9ae326a69004de David Howells        2009-04-03  107  
9ae326a69004de David Howells        2009-04-03  108  	atomic_set(&fsdef->usage, 1);
9ae326a69004de David Howells        2009-04-03  109  	fsdef->type = FSCACHE_COOKIE_TYPE_INDEX;
9ae326a69004de David Howells        2009-04-03  110  
9ae326a69004de David Howells        2009-04-03  111  	_debug("- fsdef %p", fsdef);
9ae326a69004de David Howells        2009-04-03  112  
9ae326a69004de David Howells        2009-04-03  113  	/* look up the directory at the root of the cache */
b0446be4be4476 Al Viro              2009-08-09  114  	ret = kern_path(cache->rootdirname, LOOKUP_DIRECTORY, &path);
9ae326a69004de David Howells        2009-04-03  115  	if (ret < 0)
9ae326a69004de David Howells        2009-04-03  116  		goto error_open_root;
9ae326a69004de David Howells        2009-04-03  117  
b2653f9eca0ed7 Christian Brauner    2021-03-16  118  	ret = -EINVAL;
b2653f9eca0ed7 Christian Brauner    2021-03-16  119  	if (mnt_user_ns(path.mnt) != &init_user_ns)
b2653f9eca0ed7 Christian Brauner    2021-03-16  120  		goto error_unsupported;
                                                                ^^^^^^^^^^^^^^^^^^^^^^^
Needs to be moved after we initialize root.

b2653f9eca0ed7 Christian Brauner    2021-03-16  121  
b0446be4be4476 Al Viro              2009-08-09  122  	cache->mnt = path.mnt;
b0446be4be4476 Al Viro              2009-08-09  123  	root = path.dentry;
                                                        ^^^^^^^^^^^^^^^^^^
Here

9ae326a69004de David Howells        2009-04-03  124  
9ae326a69004de David Howells        2009-04-03  125  	/* check parameters */
9ae326a69004de David Howells        2009-04-03  126  	ret = -EOPNOTSUPP;
466b77bc954c23 David Howells        2015-03-17  127  	if (d_is_negative(root) ||
466b77bc954c23 David Howells        2015-03-17  128  	    !d_backing_inode(root)->i_op->lookup ||
466b77bc954c23 David Howells        2015-03-17  129  	    !d_backing_inode(root)->i_op->mkdir ||
5d6c31910bc071 Andreas Gruenbacher  2016-09-29  130  	    !(d_backing_inode(root)->i_opflags & IOP_XATTR) ||
9ae326a69004de David Howells        2009-04-03  131  	    !root->d_sb->s_op->statfs ||
9ae326a69004de David Howells        2009-04-03  132  	    !root->d_sb->s_op->sync_fs)
9ae326a69004de David Howells        2009-04-03  133  		goto error_unsupported;
9ae326a69004de David Howells        2009-04-03  134  
9ae326a69004de David Howells        2009-04-03  135  	ret = -EROFS;
bc98a42c1f7d0f David Howells        2017-07-17  136  	if (sb_rdonly(root->d_sb))
9ae326a69004de David Howells        2009-04-03  137  		goto error_unsupported;
9ae326a69004de David Howells        2009-04-03  138  
9ae326a69004de David Howells        2009-04-03  139  	/* determine the security of the on-disk cache as this governs
9ae326a69004de David Howells        2009-04-03  140  	 * security ID of files we create */
9ae326a69004de David Howells        2009-04-03  141  	ret = cachefiles_determine_cache_security(cache, root, &saved_cred);
9ae326a69004de David Howells        2009-04-03  142  	if (ret < 0)
9ae326a69004de David Howells        2009-04-03  143  		goto error_unsupported;
9ae326a69004de David Howells        2009-04-03  144  
9ae326a69004de David Howells        2009-04-03  145  	/* get the cache size and blocksize */
ebabe9a9001af0 Christoph Hellwig    2010-07-07  146  	ret = vfs_statfs(&path, &stats);
9ae326a69004de David Howells        2009-04-03  147  	if (ret < 0)
9ae326a69004de David Howells        2009-04-03  148  		goto error_unsupported;
9ae326a69004de David Howells        2009-04-03  149  
9ae326a69004de David Howells        2009-04-03  150  	ret = -ERANGE;
9ae326a69004de David Howells        2009-04-03  151  	if (stats.f_bsize <= 0)
9ae326a69004de David Howells        2009-04-03  152  		goto error_unsupported;
9ae326a69004de David Howells        2009-04-03  153  
9ae326a69004de David Howells        2009-04-03  154  	ret = -EOPNOTSUPP;
9ae326a69004de David Howells        2009-04-03  155  	if (stats.f_bsize > PAGE_SIZE)
9ae326a69004de David Howells        2009-04-03  156  		goto error_unsupported;
9ae326a69004de David Howells        2009-04-03  157  
9ae326a69004de David Howells        2009-04-03  158  	cache->bsize = stats.f_bsize;
9ae326a69004de David Howells        2009-04-03  159  	cache->bshift = 0;
9ae326a69004de David Howells        2009-04-03  160  	if (stats.f_bsize < PAGE_SIZE)
9ae326a69004de David Howells        2009-04-03  161  		cache->bshift = PAGE_SHIFT - ilog2(stats.f_bsize);
9ae326a69004de David Howells        2009-04-03  162  
9ae326a69004de David Howells        2009-04-03  163  	_debug("blksize %u (shift %u)",
9ae326a69004de David Howells        2009-04-03  164  	       cache->bsize, cache->bshift);
9ae326a69004de David Howells        2009-04-03  165  
9ae326a69004de David Howells        2009-04-03  166  	_debug("size %llu, avail %llu",
9ae326a69004de David Howells        2009-04-03  167  	       (unsigned long long) stats.f_blocks,
9ae326a69004de David Howells        2009-04-03  168  	       (unsigned long long) stats.f_bavail);
9ae326a69004de David Howells        2009-04-03  169  
9ae326a69004de David Howells        2009-04-03  170  	/* set up caching limits */
9ae326a69004de David Howells        2009-04-03  171  	do_div(stats.f_files, 100);
9ae326a69004de David Howells        2009-04-03  172  	cache->fstop = stats.f_files * cache->fstop_percent;
9ae326a69004de David Howells        2009-04-03  173  	cache->fcull = stats.f_files * cache->fcull_percent;
9ae326a69004de David Howells        2009-04-03  174  	cache->frun  = stats.f_files * cache->frun_percent;
9ae326a69004de David Howells        2009-04-03  175  
9ae326a69004de David Howells        2009-04-03  176  	_debug("limits {%llu,%llu,%llu} files",
9ae326a69004de David Howells        2009-04-03  177  	       (unsigned long long) cache->frun,
9ae326a69004de David Howells        2009-04-03  178  	       (unsigned long long) cache->fcull,
9ae326a69004de David Howells        2009-04-03  179  	       (unsigned long long) cache->fstop);
9ae326a69004de David Howells        2009-04-03  180  
9ae326a69004de David Howells        2009-04-03  181  	stats.f_blocks >>= cache->bshift;
9ae326a69004de David Howells        2009-04-03  182  	do_div(stats.f_blocks, 100);
9ae326a69004de David Howells        2009-04-03  183  	cache->bstop = stats.f_blocks * cache->bstop_percent;
9ae326a69004de David Howells        2009-04-03  184  	cache->bcull = stats.f_blocks * cache->bcull_percent;
9ae326a69004de David Howells        2009-04-03  185  	cache->brun  = stats.f_blocks * cache->brun_percent;
9ae326a69004de David Howells        2009-04-03  186  
9ae326a69004de David Howells        2009-04-03  187  	_debug("limits {%llu,%llu,%llu} blocks",
9ae326a69004de David Howells        2009-04-03  188  	       (unsigned long long) cache->brun,
9ae326a69004de David Howells        2009-04-03  189  	       (unsigned long long) cache->bcull,
9ae326a69004de David Howells        2009-04-03  190  	       (unsigned long long) cache->bstop);
9ae326a69004de David Howells        2009-04-03  191  
9ae326a69004de David Howells        2009-04-03  192  	/* get the cache directory and check its type */
9ae326a69004de David Howells        2009-04-03  193  	cachedir = cachefiles_get_directory(cache, root, "cache");
9ae326a69004de David Howells        2009-04-03  194  	if (IS_ERR(cachedir)) {
9ae326a69004de David Howells        2009-04-03  195  		ret = PTR_ERR(cachedir);
9ae326a69004de David Howells        2009-04-03  196  		goto error_unsupported;
9ae326a69004de David Howells        2009-04-03  197  	}
9ae326a69004de David Howells        2009-04-03  198  
9ae326a69004de David Howells        2009-04-03  199  	fsdef->dentry = cachedir;
9ae326a69004de David Howells        2009-04-03  200  	fsdef->fscache.cookie = NULL;
9ae326a69004de David Howells        2009-04-03  201  
9ae326a69004de David Howells        2009-04-03  202  	ret = cachefiles_check_object_type(fsdef);
9ae326a69004de David Howells        2009-04-03  203  	if (ret < 0)
9ae326a69004de David Howells        2009-04-03  204  		goto error_unsupported;
9ae326a69004de David Howells        2009-04-03  205  
9ae326a69004de David Howells        2009-04-03  206  	/* get the graveyard directory */
9ae326a69004de David Howells        2009-04-03  207  	graveyard = cachefiles_get_directory(cache, root, "graveyard");
9ae326a69004de David Howells        2009-04-03  208  	if (IS_ERR(graveyard)) {
9ae326a69004de David Howells        2009-04-03  209  		ret = PTR_ERR(graveyard);
9ae326a69004de David Howells        2009-04-03  210  		goto error_unsupported;
9ae326a69004de David Howells        2009-04-03  211  	}
9ae326a69004de David Howells        2009-04-03  212  
9ae326a69004de David Howells        2009-04-03  213  	cache->graveyard = graveyard;
9ae326a69004de David Howells        2009-04-03  214  
9ae326a69004de David Howells        2009-04-03  215  	/* publish the cache */
9ae326a69004de David Howells        2009-04-03  216  	fscache_init_cache(&cache->cache,
9ae326a69004de David Howells        2009-04-03  217  			   &cachefiles_cache_ops,
9ae326a69004de David Howells        2009-04-03  218  			   "%s",
9ae326a69004de David Howells        2009-04-03  219  			   fsdef->dentry->d_sb->s_id);
9ae326a69004de David Howells        2009-04-03  220  
f29507ce667010 Kiran Kumar Modukuri 2018-06-21  221  	fscache_object_init(&fsdef->fscache, &fscache_fsdef_index,
f29507ce667010 Kiran Kumar Modukuri 2018-06-21  222  			    &cache->cache);
9ae326a69004de David Howells        2009-04-03  223  
9ae326a69004de David Howells        2009-04-03  224  	ret = fscache_add_cache(&cache->cache, &fsdef->fscache, cache->tag);
9ae326a69004de David Howells        2009-04-03  225  	if (ret < 0)
9ae326a69004de David Howells        2009-04-03  226  		goto error_add_cache;
9ae326a69004de David Howells        2009-04-03  227  
9ae326a69004de David Howells        2009-04-03  228  	/* done */
9ae326a69004de David Howells        2009-04-03  229  	set_bit(CACHEFILES_READY, &cache->flags);
9ae326a69004de David Howells        2009-04-03  230  	dput(root);
9ae326a69004de David Howells        2009-04-03  231  
0227d6abb37845 Fabian Frederick     2014-06-06  232  	pr_info("File cache on %s registered\n", cache->cache.identifier);
9ae326a69004de David Howells        2009-04-03  233  
9ae326a69004de David Howells        2009-04-03  234  	/* check how much space the cache has */
9ae326a69004de David Howells        2009-04-03  235  	cachefiles_has_space(cache, 0, 0);
9ae326a69004de David Howells        2009-04-03  236  	cachefiles_end_secure(cache, saved_cred);
9ae326a69004de David Howells        2009-04-03  237  	return 0;
9ae326a69004de David Howells        2009-04-03  238  
9ae326a69004de David Howells        2009-04-03  239  error_add_cache:
9ae326a69004de David Howells        2009-04-03  240  	dput(cache->graveyard);
9ae326a69004de David Howells        2009-04-03  241  	cache->graveyard = NULL;
9ae326a69004de David Howells        2009-04-03  242  error_unsupported:
9ae326a69004de David Howells        2009-04-03  243  	mntput(cache->mnt);
9ae326a69004de David Howells        2009-04-03  244  	cache->mnt = NULL;
9ae326a69004de David Howells        2009-04-03  245  	dput(fsdef->dentry);
9ae326a69004de David Howells        2009-04-03  246  	fsdef->dentry = NULL;
9ae326a69004de David Howells        2009-04-03 @247  	dput(root);
                                                        ^^^^^^^^^^

9ae326a69004de David Howells        2009-04-03  248  error_open_root:
9ae326a69004de David Howells        2009-04-03  249  	kmem_cache_free(cachefiles_object_jar, fsdef);
9ae326a69004de David Howells        2009-04-03  250  error_root_object:
9ae326a69004de David Howells        2009-04-03  251  	cachefiles_end_secure(cache, saved_cred);
6ff66ac77aeaa9 Fabian Frederick     2014-09-25  252  	pr_err("Failed to register: %d\n", ret);
9ae326a69004de David Howells        2009-04-03  253  	return ret;
9ae326a69004de David Howells        2009-04-03  254  }

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 34575 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] cachefiles: do not yet allow on idmapped mounts
@ 2021-03-17 14:25   ` Dan Carpenter
  0 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2021-03-17 14:25 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 14952 bytes --]

Hi Christian,

url:    https://github.com/0day-ci/linux/commits/Christian-Brauner/cachefiles-do-not-yet-allow-on-idmapped-mounts/20210316-192557
base:   1e28eed17697bcf343c6743f0028cc3b5dd88bf0
config: x86_64-randconfig-m001-20210317 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

New smatch warnings:
fs/cachefiles/bind.c:247 cachefiles_daemon_add_cache() error: uninitialized symbol 'root'.

vim +/root +247 fs/cachefiles/bind.c

9ae326a69004de David Howells        2009-04-03   81  static int cachefiles_daemon_add_cache(struct cachefiles_cache *cache)
9ae326a69004de David Howells        2009-04-03   82  {
9ae326a69004de David Howells        2009-04-03   83  	struct cachefiles_object *fsdef;
b0446be4be4476 Al Viro              2009-08-09   84  	struct path path;
9ae326a69004de David Howells        2009-04-03   85  	struct kstatfs stats;
9ae326a69004de David Howells        2009-04-03   86  	struct dentry *graveyard, *cachedir, *root;
9ae326a69004de David Howells        2009-04-03   87  	const struct cred *saved_cred;
9ae326a69004de David Howells        2009-04-03   88  	int ret;
9ae326a69004de David Howells        2009-04-03   89  
9ae326a69004de David Howells        2009-04-03   90  	_enter("");
9ae326a69004de David Howells        2009-04-03   91  
9ae326a69004de David Howells        2009-04-03   92  	/* we want to work under the module's security ID */
9ae326a69004de David Howells        2009-04-03   93  	ret = cachefiles_get_security_ID(cache);
9ae326a69004de David Howells        2009-04-03   94  	if (ret < 0)
9ae326a69004de David Howells        2009-04-03   95  		return ret;
9ae326a69004de David Howells        2009-04-03   96  
9ae326a69004de David Howells        2009-04-03   97  	cachefiles_begin_secure(cache, &saved_cred);
9ae326a69004de David Howells        2009-04-03   98  
9ae326a69004de David Howells        2009-04-03   99  	/* allocate the root index object */
9ae326a69004de David Howells        2009-04-03  100  	ret = -ENOMEM;
9ae326a69004de David Howells        2009-04-03  101  
9ae326a69004de David Howells        2009-04-03  102  	fsdef = kmem_cache_alloc(cachefiles_object_jar, GFP_KERNEL);
9ae326a69004de David Howells        2009-04-03  103  	if (!fsdef)
9ae326a69004de David Howells        2009-04-03  104  		goto error_root_object;
9ae326a69004de David Howells        2009-04-03  105  
9ae326a69004de David Howells        2009-04-03  106  	ASSERTCMP(fsdef->backer, ==, NULL);
9ae326a69004de David Howells        2009-04-03  107  
9ae326a69004de David Howells        2009-04-03  108  	atomic_set(&fsdef->usage, 1);
9ae326a69004de David Howells        2009-04-03  109  	fsdef->type = FSCACHE_COOKIE_TYPE_INDEX;
9ae326a69004de David Howells        2009-04-03  110  
9ae326a69004de David Howells        2009-04-03  111  	_debug("- fsdef %p", fsdef);
9ae326a69004de David Howells        2009-04-03  112  
9ae326a69004de David Howells        2009-04-03  113  	/* look up the directory at the root of the cache */
b0446be4be4476 Al Viro              2009-08-09  114  	ret = kern_path(cache->rootdirname, LOOKUP_DIRECTORY, &path);
9ae326a69004de David Howells        2009-04-03  115  	if (ret < 0)
9ae326a69004de David Howells        2009-04-03  116  		goto error_open_root;
9ae326a69004de David Howells        2009-04-03  117  
b2653f9eca0ed7 Christian Brauner    2021-03-16  118  	ret = -EINVAL;
b2653f9eca0ed7 Christian Brauner    2021-03-16  119  	if (mnt_user_ns(path.mnt) != &init_user_ns)
b2653f9eca0ed7 Christian Brauner    2021-03-16  120  		goto error_unsupported;
                                                                ^^^^^^^^^^^^^^^^^^^^^^^
Needs to be moved after we initialize root.

b2653f9eca0ed7 Christian Brauner    2021-03-16  121  
b0446be4be4476 Al Viro              2009-08-09  122  	cache->mnt = path.mnt;
b0446be4be4476 Al Viro              2009-08-09  123  	root = path.dentry;
                                                        ^^^^^^^^^^^^^^^^^^
Here

9ae326a69004de David Howells        2009-04-03  124  
9ae326a69004de David Howells        2009-04-03  125  	/* check parameters */
9ae326a69004de David Howells        2009-04-03  126  	ret = -EOPNOTSUPP;
466b77bc954c23 David Howells        2015-03-17  127  	if (d_is_negative(root) ||
466b77bc954c23 David Howells        2015-03-17  128  	    !d_backing_inode(root)->i_op->lookup ||
466b77bc954c23 David Howells        2015-03-17  129  	    !d_backing_inode(root)->i_op->mkdir ||
5d6c31910bc071 Andreas Gruenbacher  2016-09-29  130  	    !(d_backing_inode(root)->i_opflags & IOP_XATTR) ||
9ae326a69004de David Howells        2009-04-03  131  	    !root->d_sb->s_op->statfs ||
9ae326a69004de David Howells        2009-04-03  132  	    !root->d_sb->s_op->sync_fs)
9ae326a69004de David Howells        2009-04-03  133  		goto error_unsupported;
9ae326a69004de David Howells        2009-04-03  134  
9ae326a69004de David Howells        2009-04-03  135  	ret = -EROFS;
bc98a42c1f7d0f David Howells        2017-07-17  136  	if (sb_rdonly(root->d_sb))
9ae326a69004de David Howells        2009-04-03  137  		goto error_unsupported;
9ae326a69004de David Howells        2009-04-03  138  
9ae326a69004de David Howells        2009-04-03  139  	/* determine the security of the on-disk cache as this governs
9ae326a69004de David Howells        2009-04-03  140  	 * security ID of files we create */
9ae326a69004de David Howells        2009-04-03  141  	ret = cachefiles_determine_cache_security(cache, root, &saved_cred);
9ae326a69004de David Howells        2009-04-03  142  	if (ret < 0)
9ae326a69004de David Howells        2009-04-03  143  		goto error_unsupported;
9ae326a69004de David Howells        2009-04-03  144  
9ae326a69004de David Howells        2009-04-03  145  	/* get the cache size and blocksize */
ebabe9a9001af0 Christoph Hellwig    2010-07-07  146  	ret = vfs_statfs(&path, &stats);
9ae326a69004de David Howells        2009-04-03  147  	if (ret < 0)
9ae326a69004de David Howells        2009-04-03  148  		goto error_unsupported;
9ae326a69004de David Howells        2009-04-03  149  
9ae326a69004de David Howells        2009-04-03  150  	ret = -ERANGE;
9ae326a69004de David Howells        2009-04-03  151  	if (stats.f_bsize <= 0)
9ae326a69004de David Howells        2009-04-03  152  		goto error_unsupported;
9ae326a69004de David Howells        2009-04-03  153  
9ae326a69004de David Howells        2009-04-03  154  	ret = -EOPNOTSUPP;
9ae326a69004de David Howells        2009-04-03  155  	if (stats.f_bsize > PAGE_SIZE)
9ae326a69004de David Howells        2009-04-03  156  		goto error_unsupported;
9ae326a69004de David Howells        2009-04-03  157  
9ae326a69004de David Howells        2009-04-03  158  	cache->bsize = stats.f_bsize;
9ae326a69004de David Howells        2009-04-03  159  	cache->bshift = 0;
9ae326a69004de David Howells        2009-04-03  160  	if (stats.f_bsize < PAGE_SIZE)
9ae326a69004de David Howells        2009-04-03  161  		cache->bshift = PAGE_SHIFT - ilog2(stats.f_bsize);
9ae326a69004de David Howells        2009-04-03  162  
9ae326a69004de David Howells        2009-04-03  163  	_debug("blksize %u (shift %u)",
9ae326a69004de David Howells        2009-04-03  164  	       cache->bsize, cache->bshift);
9ae326a69004de David Howells        2009-04-03  165  
9ae326a69004de David Howells        2009-04-03  166  	_debug("size %llu, avail %llu",
9ae326a69004de David Howells        2009-04-03  167  	       (unsigned long long) stats.f_blocks,
9ae326a69004de David Howells        2009-04-03  168  	       (unsigned long long) stats.f_bavail);
9ae326a69004de David Howells        2009-04-03  169  
9ae326a69004de David Howells        2009-04-03  170  	/* set up caching limits */
9ae326a69004de David Howells        2009-04-03  171  	do_div(stats.f_files, 100);
9ae326a69004de David Howells        2009-04-03  172  	cache->fstop = stats.f_files * cache->fstop_percent;
9ae326a69004de David Howells        2009-04-03  173  	cache->fcull = stats.f_files * cache->fcull_percent;
9ae326a69004de David Howells        2009-04-03  174  	cache->frun  = stats.f_files * cache->frun_percent;
9ae326a69004de David Howells        2009-04-03  175  
9ae326a69004de David Howells        2009-04-03  176  	_debug("limits {%llu,%llu,%llu} files",
9ae326a69004de David Howells        2009-04-03  177  	       (unsigned long long) cache->frun,
9ae326a69004de David Howells        2009-04-03  178  	       (unsigned long long) cache->fcull,
9ae326a69004de David Howells        2009-04-03  179  	       (unsigned long long) cache->fstop);
9ae326a69004de David Howells        2009-04-03  180  
9ae326a69004de David Howells        2009-04-03  181  	stats.f_blocks >>= cache->bshift;
9ae326a69004de David Howells        2009-04-03  182  	do_div(stats.f_blocks, 100);
9ae326a69004de David Howells        2009-04-03  183  	cache->bstop = stats.f_blocks * cache->bstop_percent;
9ae326a69004de David Howells        2009-04-03  184  	cache->bcull = stats.f_blocks * cache->bcull_percent;
9ae326a69004de David Howells        2009-04-03  185  	cache->brun  = stats.f_blocks * cache->brun_percent;
9ae326a69004de David Howells        2009-04-03  186  
9ae326a69004de David Howells        2009-04-03  187  	_debug("limits {%llu,%llu,%llu} blocks",
9ae326a69004de David Howells        2009-04-03  188  	       (unsigned long long) cache->brun,
9ae326a69004de David Howells        2009-04-03  189  	       (unsigned long long) cache->bcull,
9ae326a69004de David Howells        2009-04-03  190  	       (unsigned long long) cache->bstop);
9ae326a69004de David Howells        2009-04-03  191  
9ae326a69004de David Howells        2009-04-03  192  	/* get the cache directory and check its type */
9ae326a69004de David Howells        2009-04-03  193  	cachedir = cachefiles_get_directory(cache, root, "cache");
9ae326a69004de David Howells        2009-04-03  194  	if (IS_ERR(cachedir)) {
9ae326a69004de David Howells        2009-04-03  195  		ret = PTR_ERR(cachedir);
9ae326a69004de David Howells        2009-04-03  196  		goto error_unsupported;
9ae326a69004de David Howells        2009-04-03  197  	}
9ae326a69004de David Howells        2009-04-03  198  
9ae326a69004de David Howells        2009-04-03  199  	fsdef->dentry = cachedir;
9ae326a69004de David Howells        2009-04-03  200  	fsdef->fscache.cookie = NULL;
9ae326a69004de David Howells        2009-04-03  201  
9ae326a69004de David Howells        2009-04-03  202  	ret = cachefiles_check_object_type(fsdef);
9ae326a69004de David Howells        2009-04-03  203  	if (ret < 0)
9ae326a69004de David Howells        2009-04-03  204  		goto error_unsupported;
9ae326a69004de David Howells        2009-04-03  205  
9ae326a69004de David Howells        2009-04-03  206  	/* get the graveyard directory */
9ae326a69004de David Howells        2009-04-03  207  	graveyard = cachefiles_get_directory(cache, root, "graveyard");
9ae326a69004de David Howells        2009-04-03  208  	if (IS_ERR(graveyard)) {
9ae326a69004de David Howells        2009-04-03  209  		ret = PTR_ERR(graveyard);
9ae326a69004de David Howells        2009-04-03  210  		goto error_unsupported;
9ae326a69004de David Howells        2009-04-03  211  	}
9ae326a69004de David Howells        2009-04-03  212  
9ae326a69004de David Howells        2009-04-03  213  	cache->graveyard = graveyard;
9ae326a69004de David Howells        2009-04-03  214  
9ae326a69004de David Howells        2009-04-03  215  	/* publish the cache */
9ae326a69004de David Howells        2009-04-03  216  	fscache_init_cache(&cache->cache,
9ae326a69004de David Howells        2009-04-03  217  			   &cachefiles_cache_ops,
9ae326a69004de David Howells        2009-04-03  218  			   "%s",
9ae326a69004de David Howells        2009-04-03  219  			   fsdef->dentry->d_sb->s_id);
9ae326a69004de David Howells        2009-04-03  220  
f29507ce667010 Kiran Kumar Modukuri 2018-06-21  221  	fscache_object_init(&fsdef->fscache, &fscache_fsdef_index,
f29507ce667010 Kiran Kumar Modukuri 2018-06-21  222  			    &cache->cache);
9ae326a69004de David Howells        2009-04-03  223  
9ae326a69004de David Howells        2009-04-03  224  	ret = fscache_add_cache(&cache->cache, &fsdef->fscache, cache->tag);
9ae326a69004de David Howells        2009-04-03  225  	if (ret < 0)
9ae326a69004de David Howells        2009-04-03  226  		goto error_add_cache;
9ae326a69004de David Howells        2009-04-03  227  
9ae326a69004de David Howells        2009-04-03  228  	/* done */
9ae326a69004de David Howells        2009-04-03  229  	set_bit(CACHEFILES_READY, &cache->flags);
9ae326a69004de David Howells        2009-04-03  230  	dput(root);
9ae326a69004de David Howells        2009-04-03  231  
0227d6abb37845 Fabian Frederick     2014-06-06  232  	pr_info("File cache on %s registered\n", cache->cache.identifier);
9ae326a69004de David Howells        2009-04-03  233  
9ae326a69004de David Howells        2009-04-03  234  	/* check how much space the cache has */
9ae326a69004de David Howells        2009-04-03  235  	cachefiles_has_space(cache, 0, 0);
9ae326a69004de David Howells        2009-04-03  236  	cachefiles_end_secure(cache, saved_cred);
9ae326a69004de David Howells        2009-04-03  237  	return 0;
9ae326a69004de David Howells        2009-04-03  238  
9ae326a69004de David Howells        2009-04-03  239  error_add_cache:
9ae326a69004de David Howells        2009-04-03  240  	dput(cache->graveyard);
9ae326a69004de David Howells        2009-04-03  241  	cache->graveyard = NULL;
9ae326a69004de David Howells        2009-04-03  242  error_unsupported:
9ae326a69004de David Howells        2009-04-03  243  	mntput(cache->mnt);
9ae326a69004de David Howells        2009-04-03  244  	cache->mnt = NULL;
9ae326a69004de David Howells        2009-04-03  245  	dput(fsdef->dentry);
9ae326a69004de David Howells        2009-04-03  246  	fsdef->dentry = NULL;
9ae326a69004de David Howells        2009-04-03 @247  	dput(root);
                                                        ^^^^^^^^^^

9ae326a69004de David Howells        2009-04-03  248  error_open_root:
9ae326a69004de David Howells        2009-04-03  249  	kmem_cache_free(cachefiles_object_jar, fsdef);
9ae326a69004de David Howells        2009-04-03  250  error_root_object:
9ae326a69004de David Howells        2009-04-03  251  	cachefiles_end_secure(cache, saved_cred);
6ff66ac77aeaa9 Fabian Frederick     2014-09-25  252  	pr_err("Failed to register: %d\n", ret);
9ae326a69004de David Howells        2009-04-03  253  	return ret;
9ae326a69004de David Howells        2009-04-03  254  }

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 34575 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] cachefiles: do not yet allow on idmapped mounts
@ 2021-03-17 13:04 kernel test robot
  0 siblings, 0 replies; 6+ messages in thread
From: kernel test robot @ 2021-03-17 13:04 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 15621 bytes --]

CC: kbuild-all(a)lists.01.org
In-Reply-To: <20210316112257.2974212-1-christian.brauner@ubuntu.com>
References: <20210316112257.2974212-1-christian.brauner@ubuntu.com>
TO: Christian Brauner <christian.brauner@ubuntu.com>

Hi Christian,

I love your patch! Perhaps something to improve:

[auto build test WARNING on 1e28eed17697bcf343c6743f0028cc3b5dd88bf0]

url:    https://github.com/0day-ci/linux/commits/Christian-Brauner/cachefiles-do-not-yet-allow-on-idmapped-mounts/20210316-192557
base:   1e28eed17697bcf343c6743f0028cc3b5dd88bf0
:::::: branch date: 26 hours ago
:::::: commit date: 26 hours ago
config: x86_64-randconfig-m001-20210317 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

New smatch warnings:
fs/cachefiles/bind.c:247 cachefiles_daemon_add_cache() error: uninitialized symbol 'root'.

Old smatch warnings:
fs/cachefiles/bind.c:106 cachefiles_daemon_add_cache() warn: argument 2 to %lx specifier is cast from pointer
fs/cachefiles/bind.c:106 cachefiles_daemon_add_cache() warn: argument 3 to %lx specifier is cast from pointer

vim +/root +247 fs/cachefiles/bind.c

9ae326a69004de David Howells        2009-04-03   77  
9ae326a69004de David Howells        2009-04-03   78  /*
9ae326a69004de David Howells        2009-04-03   79   * add a cache
9ae326a69004de David Howells        2009-04-03   80   */
9ae326a69004de David Howells        2009-04-03   81  static int cachefiles_daemon_add_cache(struct cachefiles_cache *cache)
9ae326a69004de David Howells        2009-04-03   82  {
9ae326a69004de David Howells        2009-04-03   83  	struct cachefiles_object *fsdef;
b0446be4be4476 Al Viro              2009-08-09   84  	struct path path;
9ae326a69004de David Howells        2009-04-03   85  	struct kstatfs stats;
9ae326a69004de David Howells        2009-04-03   86  	struct dentry *graveyard, *cachedir, *root;
9ae326a69004de David Howells        2009-04-03   87  	const struct cred *saved_cred;
9ae326a69004de David Howells        2009-04-03   88  	int ret;
9ae326a69004de David Howells        2009-04-03   89  
9ae326a69004de David Howells        2009-04-03   90  	_enter("");
9ae326a69004de David Howells        2009-04-03   91  
9ae326a69004de David Howells        2009-04-03   92  	/* we want to work under the module's security ID */
9ae326a69004de David Howells        2009-04-03   93  	ret = cachefiles_get_security_ID(cache);
9ae326a69004de David Howells        2009-04-03   94  	if (ret < 0)
9ae326a69004de David Howells        2009-04-03   95  		return ret;
9ae326a69004de David Howells        2009-04-03   96  
9ae326a69004de David Howells        2009-04-03   97  	cachefiles_begin_secure(cache, &saved_cred);
9ae326a69004de David Howells        2009-04-03   98  
9ae326a69004de David Howells        2009-04-03   99  	/* allocate the root index object */
9ae326a69004de David Howells        2009-04-03  100  	ret = -ENOMEM;
9ae326a69004de David Howells        2009-04-03  101  
9ae326a69004de David Howells        2009-04-03  102  	fsdef = kmem_cache_alloc(cachefiles_object_jar, GFP_KERNEL);
9ae326a69004de David Howells        2009-04-03  103  	if (!fsdef)
9ae326a69004de David Howells        2009-04-03  104  		goto error_root_object;
9ae326a69004de David Howells        2009-04-03  105  
9ae326a69004de David Howells        2009-04-03  106  	ASSERTCMP(fsdef->backer, ==, NULL);
9ae326a69004de David Howells        2009-04-03  107  
9ae326a69004de David Howells        2009-04-03  108  	atomic_set(&fsdef->usage, 1);
9ae326a69004de David Howells        2009-04-03  109  	fsdef->type = FSCACHE_COOKIE_TYPE_INDEX;
9ae326a69004de David Howells        2009-04-03  110  
9ae326a69004de David Howells        2009-04-03  111  	_debug("- fsdef %p", fsdef);
9ae326a69004de David Howells        2009-04-03  112  
9ae326a69004de David Howells        2009-04-03  113  	/* look up the directory at the root of the cache */
b0446be4be4476 Al Viro              2009-08-09  114  	ret = kern_path(cache->rootdirname, LOOKUP_DIRECTORY, &path);
9ae326a69004de David Howells        2009-04-03  115  	if (ret < 0)
9ae326a69004de David Howells        2009-04-03  116  		goto error_open_root;
9ae326a69004de David Howells        2009-04-03  117  
b2653f9eca0ed7 Christian Brauner    2021-03-16  118  	ret = -EINVAL;
b2653f9eca0ed7 Christian Brauner    2021-03-16  119  	if (mnt_user_ns(path.mnt) != &init_user_ns)
b2653f9eca0ed7 Christian Brauner    2021-03-16  120  		goto error_unsupported;
b2653f9eca0ed7 Christian Brauner    2021-03-16  121  
b0446be4be4476 Al Viro              2009-08-09  122  	cache->mnt = path.mnt;
b0446be4be4476 Al Viro              2009-08-09  123  	root = path.dentry;
9ae326a69004de David Howells        2009-04-03  124  
9ae326a69004de David Howells        2009-04-03  125  	/* check parameters */
9ae326a69004de David Howells        2009-04-03  126  	ret = -EOPNOTSUPP;
466b77bc954c23 David Howells        2015-03-17  127  	if (d_is_negative(root) ||
466b77bc954c23 David Howells        2015-03-17  128  	    !d_backing_inode(root)->i_op->lookup ||
466b77bc954c23 David Howells        2015-03-17  129  	    !d_backing_inode(root)->i_op->mkdir ||
5d6c31910bc071 Andreas Gruenbacher  2016-09-29  130  	    !(d_backing_inode(root)->i_opflags & IOP_XATTR) ||
9ae326a69004de David Howells        2009-04-03  131  	    !root->d_sb->s_op->statfs ||
9ae326a69004de David Howells        2009-04-03  132  	    !root->d_sb->s_op->sync_fs)
9ae326a69004de David Howells        2009-04-03  133  		goto error_unsupported;
9ae326a69004de David Howells        2009-04-03  134  
9ae326a69004de David Howells        2009-04-03  135  	ret = -EROFS;
bc98a42c1f7d0f David Howells        2017-07-17  136  	if (sb_rdonly(root->d_sb))
9ae326a69004de David Howells        2009-04-03  137  		goto error_unsupported;
9ae326a69004de David Howells        2009-04-03  138  
9ae326a69004de David Howells        2009-04-03  139  	/* determine the security of the on-disk cache as this governs
9ae326a69004de David Howells        2009-04-03  140  	 * security ID of files we create */
9ae326a69004de David Howells        2009-04-03  141  	ret = cachefiles_determine_cache_security(cache, root, &saved_cred);
9ae326a69004de David Howells        2009-04-03  142  	if (ret < 0)
9ae326a69004de David Howells        2009-04-03  143  		goto error_unsupported;
9ae326a69004de David Howells        2009-04-03  144  
9ae326a69004de David Howells        2009-04-03  145  	/* get the cache size and blocksize */
ebabe9a9001af0 Christoph Hellwig    2010-07-07  146  	ret = vfs_statfs(&path, &stats);
9ae326a69004de David Howells        2009-04-03  147  	if (ret < 0)
9ae326a69004de David Howells        2009-04-03  148  		goto error_unsupported;
9ae326a69004de David Howells        2009-04-03  149  
9ae326a69004de David Howells        2009-04-03  150  	ret = -ERANGE;
9ae326a69004de David Howells        2009-04-03  151  	if (stats.f_bsize <= 0)
9ae326a69004de David Howells        2009-04-03  152  		goto error_unsupported;
9ae326a69004de David Howells        2009-04-03  153  
9ae326a69004de David Howells        2009-04-03  154  	ret = -EOPNOTSUPP;
9ae326a69004de David Howells        2009-04-03  155  	if (stats.f_bsize > PAGE_SIZE)
9ae326a69004de David Howells        2009-04-03  156  		goto error_unsupported;
9ae326a69004de David Howells        2009-04-03  157  
9ae326a69004de David Howells        2009-04-03  158  	cache->bsize = stats.f_bsize;
9ae326a69004de David Howells        2009-04-03  159  	cache->bshift = 0;
9ae326a69004de David Howells        2009-04-03  160  	if (stats.f_bsize < PAGE_SIZE)
9ae326a69004de David Howells        2009-04-03  161  		cache->bshift = PAGE_SHIFT - ilog2(stats.f_bsize);
9ae326a69004de David Howells        2009-04-03  162  
9ae326a69004de David Howells        2009-04-03  163  	_debug("blksize %u (shift %u)",
9ae326a69004de David Howells        2009-04-03  164  	       cache->bsize, cache->bshift);
9ae326a69004de David Howells        2009-04-03  165  
9ae326a69004de David Howells        2009-04-03  166  	_debug("size %llu, avail %llu",
9ae326a69004de David Howells        2009-04-03  167  	       (unsigned long long) stats.f_blocks,
9ae326a69004de David Howells        2009-04-03  168  	       (unsigned long long) stats.f_bavail);
9ae326a69004de David Howells        2009-04-03  169  
9ae326a69004de David Howells        2009-04-03  170  	/* set up caching limits */
9ae326a69004de David Howells        2009-04-03  171  	do_div(stats.f_files, 100);
9ae326a69004de David Howells        2009-04-03  172  	cache->fstop = stats.f_files * cache->fstop_percent;
9ae326a69004de David Howells        2009-04-03  173  	cache->fcull = stats.f_files * cache->fcull_percent;
9ae326a69004de David Howells        2009-04-03  174  	cache->frun  = stats.f_files * cache->frun_percent;
9ae326a69004de David Howells        2009-04-03  175  
9ae326a69004de David Howells        2009-04-03  176  	_debug("limits {%llu,%llu,%llu} files",
9ae326a69004de David Howells        2009-04-03  177  	       (unsigned long long) cache->frun,
9ae326a69004de David Howells        2009-04-03  178  	       (unsigned long long) cache->fcull,
9ae326a69004de David Howells        2009-04-03  179  	       (unsigned long long) cache->fstop);
9ae326a69004de David Howells        2009-04-03  180  
9ae326a69004de David Howells        2009-04-03  181  	stats.f_blocks >>= cache->bshift;
9ae326a69004de David Howells        2009-04-03  182  	do_div(stats.f_blocks, 100);
9ae326a69004de David Howells        2009-04-03  183  	cache->bstop = stats.f_blocks * cache->bstop_percent;
9ae326a69004de David Howells        2009-04-03  184  	cache->bcull = stats.f_blocks * cache->bcull_percent;
9ae326a69004de David Howells        2009-04-03  185  	cache->brun  = stats.f_blocks * cache->brun_percent;
9ae326a69004de David Howells        2009-04-03  186  
9ae326a69004de David Howells        2009-04-03  187  	_debug("limits {%llu,%llu,%llu} blocks",
9ae326a69004de David Howells        2009-04-03  188  	       (unsigned long long) cache->brun,
9ae326a69004de David Howells        2009-04-03  189  	       (unsigned long long) cache->bcull,
9ae326a69004de David Howells        2009-04-03  190  	       (unsigned long long) cache->bstop);
9ae326a69004de David Howells        2009-04-03  191  
9ae326a69004de David Howells        2009-04-03  192  	/* get the cache directory and check its type */
9ae326a69004de David Howells        2009-04-03  193  	cachedir = cachefiles_get_directory(cache, root, "cache");
9ae326a69004de David Howells        2009-04-03  194  	if (IS_ERR(cachedir)) {
9ae326a69004de David Howells        2009-04-03  195  		ret = PTR_ERR(cachedir);
9ae326a69004de David Howells        2009-04-03  196  		goto error_unsupported;
9ae326a69004de David Howells        2009-04-03  197  	}
9ae326a69004de David Howells        2009-04-03  198  
9ae326a69004de David Howells        2009-04-03  199  	fsdef->dentry = cachedir;
9ae326a69004de David Howells        2009-04-03  200  	fsdef->fscache.cookie = NULL;
9ae326a69004de David Howells        2009-04-03  201  
9ae326a69004de David Howells        2009-04-03  202  	ret = cachefiles_check_object_type(fsdef);
9ae326a69004de David Howells        2009-04-03  203  	if (ret < 0)
9ae326a69004de David Howells        2009-04-03  204  		goto error_unsupported;
9ae326a69004de David Howells        2009-04-03  205  
9ae326a69004de David Howells        2009-04-03  206  	/* get the graveyard directory */
9ae326a69004de David Howells        2009-04-03  207  	graveyard = cachefiles_get_directory(cache, root, "graveyard");
9ae326a69004de David Howells        2009-04-03  208  	if (IS_ERR(graveyard)) {
9ae326a69004de David Howells        2009-04-03  209  		ret = PTR_ERR(graveyard);
9ae326a69004de David Howells        2009-04-03  210  		goto error_unsupported;
9ae326a69004de David Howells        2009-04-03  211  	}
9ae326a69004de David Howells        2009-04-03  212  
9ae326a69004de David Howells        2009-04-03  213  	cache->graveyard = graveyard;
9ae326a69004de David Howells        2009-04-03  214  
9ae326a69004de David Howells        2009-04-03  215  	/* publish the cache */
9ae326a69004de David Howells        2009-04-03  216  	fscache_init_cache(&cache->cache,
9ae326a69004de David Howells        2009-04-03  217  			   &cachefiles_cache_ops,
9ae326a69004de David Howells        2009-04-03  218  			   "%s",
9ae326a69004de David Howells        2009-04-03  219  			   fsdef->dentry->d_sb->s_id);
9ae326a69004de David Howells        2009-04-03  220  
f29507ce667010 Kiran Kumar Modukuri 2018-06-21  221  	fscache_object_init(&fsdef->fscache, &fscache_fsdef_index,
f29507ce667010 Kiran Kumar Modukuri 2018-06-21  222  			    &cache->cache);
9ae326a69004de David Howells        2009-04-03  223  
9ae326a69004de David Howells        2009-04-03  224  	ret = fscache_add_cache(&cache->cache, &fsdef->fscache, cache->tag);
9ae326a69004de David Howells        2009-04-03  225  	if (ret < 0)
9ae326a69004de David Howells        2009-04-03  226  		goto error_add_cache;
9ae326a69004de David Howells        2009-04-03  227  
9ae326a69004de David Howells        2009-04-03  228  	/* done */
9ae326a69004de David Howells        2009-04-03  229  	set_bit(CACHEFILES_READY, &cache->flags);
9ae326a69004de David Howells        2009-04-03  230  	dput(root);
9ae326a69004de David Howells        2009-04-03  231  
0227d6abb37845 Fabian Frederick     2014-06-06  232  	pr_info("File cache on %s registered\n", cache->cache.identifier);
9ae326a69004de David Howells        2009-04-03  233  
9ae326a69004de David Howells        2009-04-03  234  	/* check how much space the cache has */
9ae326a69004de David Howells        2009-04-03  235  	cachefiles_has_space(cache, 0, 0);
9ae326a69004de David Howells        2009-04-03  236  	cachefiles_end_secure(cache, saved_cred);
9ae326a69004de David Howells        2009-04-03  237  	return 0;
9ae326a69004de David Howells        2009-04-03  238  
9ae326a69004de David Howells        2009-04-03  239  error_add_cache:
9ae326a69004de David Howells        2009-04-03  240  	dput(cache->graveyard);
9ae326a69004de David Howells        2009-04-03  241  	cache->graveyard = NULL;
9ae326a69004de David Howells        2009-04-03  242  error_unsupported:
9ae326a69004de David Howells        2009-04-03  243  	mntput(cache->mnt);
9ae326a69004de David Howells        2009-04-03  244  	cache->mnt = NULL;
9ae326a69004de David Howells        2009-04-03  245  	dput(fsdef->dentry);
9ae326a69004de David Howells        2009-04-03  246  	fsdef->dentry = NULL;
9ae326a69004de David Howells        2009-04-03 @247  	dput(root);
9ae326a69004de David Howells        2009-04-03  248  error_open_root:
9ae326a69004de David Howells        2009-04-03  249  	kmem_cache_free(cachefiles_object_jar, fsdef);
9ae326a69004de David Howells        2009-04-03  250  error_root_object:
9ae326a69004de David Howells        2009-04-03  251  	cachefiles_end_secure(cache, saved_cred);
6ff66ac77aeaa9 Fabian Frederick     2014-09-25  252  	pr_err("Failed to register: %d\n", ret);
9ae326a69004de David Howells        2009-04-03  253  	return ret;
9ae326a69004de David Howells        2009-04-03  254  }
9ae326a69004de David Howells        2009-04-03  255  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 34575 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] cachefiles: do not yet allow on idmapped mounts
@ 2021-03-16 11:22 Christian Brauner
  2021-03-17 14:25   ` Dan Carpenter
  0 siblings, 1 reply; 6+ messages in thread
From: Christian Brauner @ 2021-03-16 11:22 UTC (permalink / raw)
  To: David Howells, linux-cachefs; +Cc: linux-fsdevel, Christian Brauner

Based on discussion with David Howells my understanding of cachefiles
and the cachefiles userspace daemon is that it creates a cache on a
local filesystem (e.g. ext4, xfs etc.) for a network filesystem. The way
this is done is by writing "bind" to /dev/cachefiles and pointing it to
the directory to use as the cache.
So from our offline discussion I gather that cachefilesd creates a cache
on a local filesystem (ext4, xfs etc.) for a network filesystem. The way
this is done is by writing "bind" to /dev/cachefiles and pointing it to
a directory to use as the cache.
Currently this directory can technically also be an idmapped mount but
cachefiles aren't yet fully aware of such mounts and thus don't take the
idmapping into account. This could leave users confused as the ownership
of the files wouldn't match to what they expressed in the idmapping. So
let's not allow this for now and only make cachefiles aware of idmapped
mounts after it's current rewrite/rework is done.

Link: https://lore.kernel.org/lkml/20210303161528.n3jzg66ou2wa43qb@wittgenstein
Cc: David Howells <dhowells@redhat.com>
Cc: linux-cachefs@redhat.com
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
---
 fs/cachefiles/bind.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
index dfb14dbddf51..bd7eab9a0539 100644
--- a/fs/cachefiles/bind.c
+++ b/fs/cachefiles/bind.c
@@ -115,6 +115,10 @@ static int cachefiles_daemon_add_cache(struct cachefiles_cache *cache)
 	if (ret < 0)
 		goto error_open_root;
 
+	ret = -EINVAL;
+	if (mnt_user_ns(path.mnt) != &init_user_ns)
+		goto error_unsupported;
+
 	cache->mnt = path.mnt;
 	root = path.dentry;
 

base-commit: 1e28eed17697bcf343c6743f0028cc3b5dd88bf0
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-03-24  8:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-24  8:51 [PATCH] cachefiles: do not yet allow on idmapped mounts David Howells
  -- strict thread matches above, loose matches on Subject: below --
2021-03-17 13:04 kernel test robot
2021-03-16 11:22 Christian Brauner
2021-03-17 14:25 ` Dan Carpenter
2021-03-17 14:25   ` Dan Carpenter
2021-03-17 17:15   ` Christian Brauner

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.