2019-05-24 18:04:05 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-12-16 06:29:43 +08:00
|
|
|
/* -*- mode: c; c-basic-offset: 8; -*-
|
|
|
|
* vim: noexpandtab sw=8 ts=8 sts=0:
|
|
|
|
*
|
|
|
|
* symlink.c - operations for configfs symlinks.
|
|
|
|
*
|
|
|
|
* Based on sysfs:
|
|
|
|
* sysfs is Copyright (C) 2001, 2002, 2003 Patrick Mochel
|
|
|
|
*
|
|
|
|
* configfs Copyright (C) 2005 Oracle. All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/namei.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2005-12-16 06:29:43 +08:00
|
|
|
|
|
|
|
#include <linux/configfs.h>
|
|
|
|
#include "configfs_internal.h"
|
|
|
|
|
2008-06-20 20:09:22 +08:00
|
|
|
/* Protects attachments of new symlinks */
|
|
|
|
DEFINE_MUTEX(configfs_symlink_mutex);
|
|
|
|
|
2005-12-16 06:29:43 +08:00
|
|
|
static int item_depth(struct config_item * item)
|
|
|
|
{
|
|
|
|
struct config_item * p = item;
|
|
|
|
int depth = 0;
|
|
|
|
do { depth++; } while ((p = p->ci_parent) && !configfs_is_root(p));
|
|
|
|
return depth;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int item_path_length(struct config_item * item)
|
|
|
|
{
|
|
|
|
struct config_item * p = item;
|
|
|
|
int length = 1;
|
|
|
|
do {
|
|
|
|
length += strlen(config_item_name(p)) + 1;
|
|
|
|
p = p->ci_parent;
|
|
|
|
} while (p && !configfs_is_root(p));
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fill_item_path(struct config_item * item, char * buffer, int length)
|
|
|
|
{
|
|
|
|
struct config_item * p;
|
|
|
|
|
|
|
|
--length;
|
|
|
|
for (p = item; p && !configfs_is_root(p); p = p->ci_parent) {
|
|
|
|
int cur = strlen(config_item_name(p));
|
|
|
|
|
|
|
|
/* back up enough to print this bus id with '/' */
|
|
|
|
length -= cur;
|
2018-07-02 04:56:54 +08:00
|
|
|
memcpy(buffer + length, config_item_name(p), cur);
|
2005-12-16 06:29:43 +08:00
|
|
|
*(buffer + --length) = '/';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-11 15:00:01 +08:00
|
|
|
static int configfs_get_target_path(struct config_item *item,
|
|
|
|
struct config_item *target, char *path)
|
|
|
|
{
|
|
|
|
int depth, size;
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
depth = item_depth(item);
|
|
|
|
size = item_path_length(target) + depth * 3 - 1;
|
|
|
|
if (size > PATH_MAX)
|
|
|
|
return -ENAMETOOLONG;
|
|
|
|
|
|
|
|
pr_debug("%s: depth = %d, size = %d\n", __func__, depth, size);
|
|
|
|
|
|
|
|
for (s = path; depth--; s += 3)
|
|
|
|
strcpy(s,"../");
|
|
|
|
|
|
|
|
fill_item_path(target, path, size);
|
|
|
|
pr_debug("%s: path = '%s'\n", __func__, path);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-12-16 06:29:43 +08:00
|
|
|
static int create_link(struct config_item *parent_item,
|
2006-03-11 03:42:30 +08:00
|
|
|
struct config_item *item,
|
2005-12-16 06:29:43 +08:00
|
|
|
struct dentry *dentry)
|
|
|
|
{
|
|
|
|
struct configfs_dirent *target_sd = item->ci_dentry->d_fsdata;
|
2019-09-11 15:00:01 +08:00
|
|
|
char *body;
|
2005-12-16 06:29:43 +08:00
|
|
|
int ret;
|
|
|
|
|
[PATCH] configfs: Prevent userspace from creating new entries under attaching directories
process 1: process 2:
configfs_mkdir("A")
attach_group("A")
attach_item("A")
d_instantiate("A")
populate_groups("A")
mutex_lock("A")
attach_group("A/B")
attach_item("A")
d_instantiate("A/B")
mkdir("A/B/C")
do_path_lookup("A/B/C", LOOKUP_PARENT)
ok
lookup_create("A/B/C")
mutex_lock("A/B")
ok
configfs_mkdir("A/B/C")
ok
attach_group("A/C")
attach_item("A/C")
d_instantiate("A/C")
populate_groups("A/C")
mutex_lock("A/C")
attach_group("A/C/D")
attach_item("A/C/D")
failure
mutex_unlock("A/C")
detach_groups("A/C")
nothing to do
mkdir("A/C/E")
do_path_lookup("A/C/E", LOOKUP_PARENT)
ok
lookup_create("A/C/E")
mutex_lock("A/C")
ok
configfs_mkdir("A/C/E")
ok
detach_item("A/C")
d_delete("A/C")
mutex_unlock("A")
detach_groups("A")
mutex_lock("A/B")
detach_group("A/B")
detach_groups("A/B")
nothing since no _default_ group
detach_item("A/B")
mutex_unlock("A/B")
d_delete("A/B")
detach_item("A")
d_delete("A")
Two bugs:
1/ "A/B/C" and "A/C/E" are created, but never removed while their parent are
removed in the end. The same could happen with symlink() instead of mkdir().
2/ "A" and "A/C" inodes are not locked while detach_item() is called on them,
which may probably confuse VFS.
This commit fixes 1/, tagging new directories with CONFIGFS_USET_CREATING before
building the inode and instantiating the dentry, and validating the whole
group+default groups hierarchy in a second pass by clearing
CONFIGFS_USET_CREATING.
mkdir(), symlink(), lookup(), and dir_open() simply return -ENOENT if
called in (or linking to) a directory tagged with CONFIGFS_USET_CREATING. This
does not prevent userspace from calling stat() successfuly on such directories,
but this prevents userspace from adding (children to | symlinking from/to |
read/write attributes of | listing the contents of) not validated items. In
other words, userspace will not interact with the subsystem on a new item until
the new item creation completes correctly.
It was first proposed to re-use CONFIGFS_USET_IN_MKDIR instead of a new
flag CONFIGFS_USET_CREATING, but this generated conflicts when checking the
target of a new symlink: a valid target directory in the middle of attaching
a new user-created child item could be wrongly detected as being attached.
2/ is fixed by next commit.
Signed-off-by: Louis Rilling <louis.rilling@kerlabs.com>
Signed-off-by: Joel Becker <joel.becker@oracle.com>
Signed-off-by: Mark Fasheh <mfasheh@suse.com>
2008-07-04 22:56:05 +08:00
|
|
|
if (!configfs_dirent_is_ready(target_sd))
|
2019-09-11 15:00:01 +08:00
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
body = kzalloc(PAGE_SIZE, GFP_KERNEL);
|
|
|
|
if (!body)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
configfs_get(target_sd);
|
|
|
|
spin_lock(&configfs_dirent_lock);
|
|
|
|
if (target_sd->s_type & CONFIGFS_USET_DROPPING) {
|
|
|
|
spin_unlock(&configfs_dirent_lock);
|
|
|
|
configfs_put(target_sd);
|
|
|
|
kfree(body);
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
target_sd->s_links++;
|
|
|
|
spin_unlock(&configfs_dirent_lock);
|
2019-11-04 20:43:22 +08:00
|
|
|
ret = configfs_get_target_path(parent_item, item, body);
|
2019-09-11 15:00:01 +08:00
|
|
|
if (!ret)
|
|
|
|
ret = configfs_create_link(target_sd, parent_item->ci_dentry,
|
|
|
|
dentry, body);
|
|
|
|
if (ret) {
|
2008-06-17 01:00:59 +08:00
|
|
|
spin_lock(&configfs_dirent_lock);
|
2019-09-11 15:00:01 +08:00
|
|
|
target_sd->s_links--;
|
2008-06-17 01:00:59 +08:00
|
|
|
spin_unlock(&configfs_dirent_lock);
|
2019-09-11 15:00:01 +08:00
|
|
|
configfs_put(target_sd);
|
|
|
|
kfree(body);
|
2005-12-16 06:29:43 +08:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-02 13:04:36 +08:00
|
|
|
static int get_target(const char *symname, struct path *path,
|
2012-03-18 04:24:54 +08:00
|
|
|
struct config_item **target, struct super_block *sb)
|
2005-12-16 06:29:43 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2008-08-02 13:04:36 +08:00
|
|
|
ret = kern_path(symname, LOOKUP_FOLLOW|LOOKUP_DIRECTORY, path);
|
2005-12-16 06:29:43 +08:00
|
|
|
if (!ret) {
|
2012-03-18 04:24:54 +08:00
|
|
|
if (path->dentry->d_sb == sb) {
|
2008-08-02 13:04:36 +08:00
|
|
|
*target = configfs_get_config_item(path->dentry);
|
2005-12-16 06:29:43 +08:00
|
|
|
if (!*target) {
|
|
|
|
ret = -ENOENT;
|
2008-08-02 13:04:36 +08:00
|
|
|
path_put(path);
|
2005-12-16 06:29:43 +08:00
|
|
|
}
|
2010-01-14 11:10:57 +08:00
|
|
|
} else {
|
2005-12-16 06:29:43 +08:00
|
|
|
ret = -EPERM;
|
2010-01-14 11:10:57 +08:00
|
|
|
path_put(path);
|
|
|
|
}
|
2005-12-16 06:29:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int configfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
|
|
|
|
{
|
|
|
|
int ret;
|
2008-08-02 13:04:36 +08:00
|
|
|
struct path path;
|
[PATCH] configfs: Prevent userspace from creating new entries under attaching directories
process 1: process 2:
configfs_mkdir("A")
attach_group("A")
attach_item("A")
d_instantiate("A")
populate_groups("A")
mutex_lock("A")
attach_group("A/B")
attach_item("A")
d_instantiate("A/B")
mkdir("A/B/C")
do_path_lookup("A/B/C", LOOKUP_PARENT)
ok
lookup_create("A/B/C")
mutex_lock("A/B")
ok
configfs_mkdir("A/B/C")
ok
attach_group("A/C")
attach_item("A/C")
d_instantiate("A/C")
populate_groups("A/C")
mutex_lock("A/C")
attach_group("A/C/D")
attach_item("A/C/D")
failure
mutex_unlock("A/C")
detach_groups("A/C")
nothing to do
mkdir("A/C/E")
do_path_lookup("A/C/E", LOOKUP_PARENT)
ok
lookup_create("A/C/E")
mutex_lock("A/C")
ok
configfs_mkdir("A/C/E")
ok
detach_item("A/C")
d_delete("A/C")
mutex_unlock("A")
detach_groups("A")
mutex_lock("A/B")
detach_group("A/B")
detach_groups("A/B")
nothing since no _default_ group
detach_item("A/B")
mutex_unlock("A/B")
d_delete("A/B")
detach_item("A")
d_delete("A")
Two bugs:
1/ "A/B/C" and "A/C/E" are created, but never removed while their parent are
removed in the end. The same could happen with symlink() instead of mkdir().
2/ "A" and "A/C" inodes are not locked while detach_item() is called on them,
which may probably confuse VFS.
This commit fixes 1/, tagging new directories with CONFIGFS_USET_CREATING before
building the inode and instantiating the dentry, and validating the whole
group+default groups hierarchy in a second pass by clearing
CONFIGFS_USET_CREATING.
mkdir(), symlink(), lookup(), and dir_open() simply return -ENOENT if
called in (or linking to) a directory tagged with CONFIGFS_USET_CREATING. This
does not prevent userspace from calling stat() successfuly on such directories,
but this prevents userspace from adding (children to | symlinking from/to |
read/write attributes of | listing the contents of) not validated items. In
other words, userspace will not interact with the subsystem on a new item until
the new item creation completes correctly.
It was first proposed to re-use CONFIGFS_USET_IN_MKDIR instead of a new
flag CONFIGFS_USET_CREATING, but this generated conflicts when checking the
target of a new symlink: a valid target directory in the middle of attaching
a new user-created child item could be wrongly detected as being attached.
2/ is fixed by next commit.
Signed-off-by: Louis Rilling <louis.rilling@kerlabs.com>
Signed-off-by: Joel Becker <joel.becker@oracle.com>
Signed-off-by: Mark Fasheh <mfasheh@suse.com>
2008-07-04 22:56:05 +08:00
|
|
|
struct configfs_dirent *sd;
|
2005-12-16 06:29:43 +08:00
|
|
|
struct config_item *parent_item;
|
2009-04-19 03:40:03 +08:00
|
|
|
struct config_item *target_item = NULL;
|
2017-10-16 23:18:40 +08:00
|
|
|
const struct config_item_type *type;
|
2005-12-16 06:29:43 +08:00
|
|
|
|
[PATCH] configfs: Prevent userspace from creating new entries under attaching directories
process 1: process 2:
configfs_mkdir("A")
attach_group("A")
attach_item("A")
d_instantiate("A")
populate_groups("A")
mutex_lock("A")
attach_group("A/B")
attach_item("A")
d_instantiate("A/B")
mkdir("A/B/C")
do_path_lookup("A/B/C", LOOKUP_PARENT)
ok
lookup_create("A/B/C")
mutex_lock("A/B")
ok
configfs_mkdir("A/B/C")
ok
attach_group("A/C")
attach_item("A/C")
d_instantiate("A/C")
populate_groups("A/C")
mutex_lock("A/C")
attach_group("A/C/D")
attach_item("A/C/D")
failure
mutex_unlock("A/C")
detach_groups("A/C")
nothing to do
mkdir("A/C/E")
do_path_lookup("A/C/E", LOOKUP_PARENT)
ok
lookup_create("A/C/E")
mutex_lock("A/C")
ok
configfs_mkdir("A/C/E")
ok
detach_item("A/C")
d_delete("A/C")
mutex_unlock("A")
detach_groups("A")
mutex_lock("A/B")
detach_group("A/B")
detach_groups("A/B")
nothing since no _default_ group
detach_item("A/B")
mutex_unlock("A/B")
d_delete("A/B")
detach_item("A")
d_delete("A")
Two bugs:
1/ "A/B/C" and "A/C/E" are created, but never removed while their parent are
removed in the end. The same could happen with symlink() instead of mkdir().
2/ "A" and "A/C" inodes are not locked while detach_item() is called on them,
which may probably confuse VFS.
This commit fixes 1/, tagging new directories with CONFIGFS_USET_CREATING before
building the inode and instantiating the dentry, and validating the whole
group+default groups hierarchy in a second pass by clearing
CONFIGFS_USET_CREATING.
mkdir(), symlink(), lookup(), and dir_open() simply return -ENOENT if
called in (or linking to) a directory tagged with CONFIGFS_USET_CREATING. This
does not prevent userspace from calling stat() successfuly on such directories,
but this prevents userspace from adding (children to | symlinking from/to |
read/write attributes of | listing the contents of) not validated items. In
other words, userspace will not interact with the subsystem on a new item until
the new item creation completes correctly.
It was first proposed to re-use CONFIGFS_USET_IN_MKDIR instead of a new
flag CONFIGFS_USET_CREATING, but this generated conflicts when checking the
target of a new symlink: a valid target directory in the middle of attaching
a new user-created child item could be wrongly detected as being attached.
2/ is fixed by next commit.
Signed-off-by: Louis Rilling <louis.rilling@kerlabs.com>
Signed-off-by: Joel Becker <joel.becker@oracle.com>
Signed-off-by: Mark Fasheh <mfasheh@suse.com>
2008-07-04 22:56:05 +08:00
|
|
|
sd = dentry->d_parent->d_fsdata;
|
|
|
|
/*
|
|
|
|
* Fake invisibility if dir belongs to a group/default groups hierarchy
|
|
|
|
* being attached
|
|
|
|
*/
|
|
|
|
if (!configfs_dirent_is_ready(sd))
|
2019-09-11 15:00:01 +08:00
|
|
|
return -ENOENT;
|
[PATCH] configfs: Prevent userspace from creating new entries under attaching directories
process 1: process 2:
configfs_mkdir("A")
attach_group("A")
attach_item("A")
d_instantiate("A")
populate_groups("A")
mutex_lock("A")
attach_group("A/B")
attach_item("A")
d_instantiate("A/B")
mkdir("A/B/C")
do_path_lookup("A/B/C", LOOKUP_PARENT)
ok
lookup_create("A/B/C")
mutex_lock("A/B")
ok
configfs_mkdir("A/B/C")
ok
attach_group("A/C")
attach_item("A/C")
d_instantiate("A/C")
populate_groups("A/C")
mutex_lock("A/C")
attach_group("A/C/D")
attach_item("A/C/D")
failure
mutex_unlock("A/C")
detach_groups("A/C")
nothing to do
mkdir("A/C/E")
do_path_lookup("A/C/E", LOOKUP_PARENT)
ok
lookup_create("A/C/E")
mutex_lock("A/C")
ok
configfs_mkdir("A/C/E")
ok
detach_item("A/C")
d_delete("A/C")
mutex_unlock("A")
detach_groups("A")
mutex_lock("A/B")
detach_group("A/B")
detach_groups("A/B")
nothing since no _default_ group
detach_item("A/B")
mutex_unlock("A/B")
d_delete("A/B")
detach_item("A")
d_delete("A")
Two bugs:
1/ "A/B/C" and "A/C/E" are created, but never removed while their parent are
removed in the end. The same could happen with symlink() instead of mkdir().
2/ "A" and "A/C" inodes are not locked while detach_item() is called on them,
which may probably confuse VFS.
This commit fixes 1/, tagging new directories with CONFIGFS_USET_CREATING before
building the inode and instantiating the dentry, and validating the whole
group+default groups hierarchy in a second pass by clearing
CONFIGFS_USET_CREATING.
mkdir(), symlink(), lookup(), and dir_open() simply return -ENOENT if
called in (or linking to) a directory tagged with CONFIGFS_USET_CREATING. This
does not prevent userspace from calling stat() successfuly on such directories,
but this prevents userspace from adding (children to | symlinking from/to |
read/write attributes of | listing the contents of) not validated items. In
other words, userspace will not interact with the subsystem on a new item until
the new item creation completes correctly.
It was first proposed to re-use CONFIGFS_USET_IN_MKDIR instead of a new
flag CONFIGFS_USET_CREATING, but this generated conflicts when checking the
target of a new symlink: a valid target directory in the middle of attaching
a new user-created child item could be wrongly detected as being attached.
2/ is fixed by next commit.
Signed-off-by: Louis Rilling <louis.rilling@kerlabs.com>
Signed-off-by: Joel Becker <joel.becker@oracle.com>
Signed-off-by: Mark Fasheh <mfasheh@suse.com>
2008-07-04 22:56:05 +08:00
|
|
|
|
2005-12-16 06:29:43 +08:00
|
|
|
parent_item = configfs_get_config_item(dentry->d_parent);
|
|
|
|
type = parent_item->ci_type;
|
|
|
|
|
[PATCH] configfs: Prevent userspace from creating new entries under attaching directories
process 1: process 2:
configfs_mkdir("A")
attach_group("A")
attach_item("A")
d_instantiate("A")
populate_groups("A")
mutex_lock("A")
attach_group("A/B")
attach_item("A")
d_instantiate("A/B")
mkdir("A/B/C")
do_path_lookup("A/B/C", LOOKUP_PARENT)
ok
lookup_create("A/B/C")
mutex_lock("A/B")
ok
configfs_mkdir("A/B/C")
ok
attach_group("A/C")
attach_item("A/C")
d_instantiate("A/C")
populate_groups("A/C")
mutex_lock("A/C")
attach_group("A/C/D")
attach_item("A/C/D")
failure
mutex_unlock("A/C")
detach_groups("A/C")
nothing to do
mkdir("A/C/E")
do_path_lookup("A/C/E", LOOKUP_PARENT)
ok
lookup_create("A/C/E")
mutex_lock("A/C")
ok
configfs_mkdir("A/C/E")
ok
detach_item("A/C")
d_delete("A/C")
mutex_unlock("A")
detach_groups("A")
mutex_lock("A/B")
detach_group("A/B")
detach_groups("A/B")
nothing since no _default_ group
detach_item("A/B")
mutex_unlock("A/B")
d_delete("A/B")
detach_item("A")
d_delete("A")
Two bugs:
1/ "A/B/C" and "A/C/E" are created, but never removed while their parent are
removed in the end. The same could happen with symlink() instead of mkdir().
2/ "A" and "A/C" inodes are not locked while detach_item() is called on them,
which may probably confuse VFS.
This commit fixes 1/, tagging new directories with CONFIGFS_USET_CREATING before
building the inode and instantiating the dentry, and validating the whole
group+default groups hierarchy in a second pass by clearing
CONFIGFS_USET_CREATING.
mkdir(), symlink(), lookup(), and dir_open() simply return -ENOENT if
called in (or linking to) a directory tagged with CONFIGFS_USET_CREATING. This
does not prevent userspace from calling stat() successfuly on such directories,
but this prevents userspace from adding (children to | symlinking from/to |
read/write attributes of | listing the contents of) not validated items. In
other words, userspace will not interact with the subsystem on a new item until
the new item creation completes correctly.
It was first proposed to re-use CONFIGFS_USET_IN_MKDIR instead of a new
flag CONFIGFS_USET_CREATING, but this generated conflicts when checking the
target of a new symlink: a valid target directory in the middle of attaching
a new user-created child item could be wrongly detected as being attached.
2/ is fixed by next commit.
Signed-off-by: Louis Rilling <louis.rilling@kerlabs.com>
Signed-off-by: Joel Becker <joel.becker@oracle.com>
Signed-off-by: Mark Fasheh <mfasheh@suse.com>
2008-07-04 22:56:05 +08:00
|
|
|
ret = -EPERM;
|
2005-12-16 06:29:43 +08:00
|
|
|
if (!type || !type->ct_item_ops ||
|
|
|
|
!type->ct_item_ops->allow_link)
|
|
|
|
goto out_put;
|
|
|
|
|
2019-08-03 23:51:18 +08:00
|
|
|
/*
|
|
|
|
* This is really sick. What they wanted was a hybrid of
|
|
|
|
* link(2) and symlink(2) - they wanted the target resolved
|
|
|
|
* at syscall time (as link(2) would've done), be a directory
|
|
|
|
* (which link(2) would've refused to do) *AND* be a deep
|
|
|
|
* fucking magic, making the target busy from rmdir POV.
|
|
|
|
* symlink(2) is nothing of that sort, and the locking it
|
|
|
|
* gets matches the normal symlink(2) semantics. Without
|
|
|
|
* attempts to resolve the target (which might very well
|
|
|
|
* not even exist yet) done prior to locking the parent
|
|
|
|
* directory. This perversion, OTOH, needs to resolve
|
|
|
|
* the target, which would lead to obvious deadlocks if
|
|
|
|
* attempted with any directories locked.
|
|
|
|
*
|
|
|
|
* Unfortunately, that garbage is userland ABI and we should've
|
|
|
|
* said "no" back in 2005. Too late now, so we get to
|
|
|
|
* play very ugly games with locking.
|
|
|
|
*
|
|
|
|
* Try *ANYTHING* of that sort in new code, and you will
|
|
|
|
* really regret it. Just ask yourself - what could a BOFH
|
|
|
|
* do to me and do I want to find it out first-hand?
|
|
|
|
*
|
|
|
|
* AV, a thoroughly annoyed bastard.
|
|
|
|
*/
|
|
|
|
inode_unlock(dir);
|
2012-03-18 04:24:54 +08:00
|
|
|
ret = get_target(symname, &path, &target_item, dentry->d_sb);
|
2019-08-03 23:51:18 +08:00
|
|
|
inode_lock(dir);
|
2005-12-16 06:29:43 +08:00
|
|
|
if (ret)
|
|
|
|
goto out_put;
|
|
|
|
|
2019-08-03 23:51:18 +08:00
|
|
|
if (dentry->d_inode || d_unhashed(dentry))
|
|
|
|
ret = -EEXIST;
|
|
|
|
else
|
|
|
|
ret = inode_permission(dir, MAY_WRITE | MAY_EXEC);
|
|
|
|
if (!ret)
|
|
|
|
ret = type->ct_item_ops->allow_link(parent_item, target_item);
|
2008-06-12 23:26:47 +08:00
|
|
|
if (!ret) {
|
2008-06-20 20:09:22 +08:00
|
|
|
mutex_lock(&configfs_symlink_mutex);
|
2005-12-16 06:29:43 +08:00
|
|
|
ret = create_link(parent_item, target_item, dentry);
|
2008-06-20 20:09:22 +08:00
|
|
|
mutex_unlock(&configfs_symlink_mutex);
|
2008-06-12 23:26:47 +08:00
|
|
|
if (ret && type->ct_item_ops->drop_link)
|
|
|
|
type->ct_item_ops->drop_link(parent_item,
|
|
|
|
target_item);
|
|
|
|
}
|
2005-12-16 06:29:43 +08:00
|
|
|
|
|
|
|
config_item_put(target_item);
|
2008-08-02 13:04:36 +08:00
|
|
|
path_put(&path);
|
2005-12-16 06:29:43 +08:00
|
|
|
|
|
|
|
out_put:
|
|
|
|
config_item_put(parent_item);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int configfs_unlink(struct inode *dir, struct dentry *dentry)
|
|
|
|
{
|
2019-09-11 15:00:01 +08:00
|
|
|
struct configfs_dirent *sd = dentry->d_fsdata, *target_sd;
|
2005-12-16 06:29:43 +08:00
|
|
|
struct config_item *parent_item;
|
2017-10-16 23:18:40 +08:00
|
|
|
const struct config_item_type *type;
|
2005-12-16 06:29:43 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = -EPERM; /* What lack-of-symlink returns */
|
|
|
|
if (!(sd->s_type & CONFIGFS_ITEM_LINK))
|
|
|
|
goto out;
|
|
|
|
|
2019-09-11 15:00:01 +08:00
|
|
|
target_sd = sd->s_element;
|
2005-12-16 06:29:43 +08:00
|
|
|
|
|
|
|
parent_item = configfs_get_config_item(dentry->d_parent);
|
|
|
|
type = parent_item->ci_type;
|
|
|
|
|
2008-06-17 01:00:58 +08:00
|
|
|
spin_lock(&configfs_dirent_lock);
|
2005-12-16 06:29:43 +08:00
|
|
|
list_del_init(&sd->s_sibling);
|
2008-06-17 01:00:58 +08:00
|
|
|
spin_unlock(&configfs_dirent_lock);
|
2005-12-16 06:29:43 +08:00
|
|
|
configfs_drop_dentry(sd, dentry->d_parent);
|
|
|
|
dput(dentry);
|
|
|
|
configfs_put(sd);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* drop_link() must be called before
|
2019-09-11 15:00:01 +08:00
|
|
|
* decrementing target's ->s_links, so that the order of
|
2005-12-16 06:29:43 +08:00
|
|
|
* drop_link(this, target) and drop_item(target) is preserved.
|
|
|
|
*/
|
|
|
|
if (type && type->ct_item_ops &&
|
|
|
|
type->ct_item_ops->drop_link)
|
|
|
|
type->ct_item_ops->drop_link(parent_item,
|
2019-09-11 15:00:01 +08:00
|
|
|
target_sd->s_element);
|
2005-12-16 06:29:43 +08:00
|
|
|
|
2008-06-17 01:00:59 +08:00
|
|
|
spin_lock(&configfs_dirent_lock);
|
2019-09-11 15:00:01 +08:00
|
|
|
target_sd->s_links--;
|
2008-06-17 01:00:59 +08:00
|
|
|
spin_unlock(&configfs_dirent_lock);
|
2019-09-11 15:00:01 +08:00
|
|
|
configfs_put(target_sd);
|
2005-12-16 06:29:43 +08:00
|
|
|
|
|
|
|
config_item_put(parent_item);
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-02-12 16:55:38 +08:00
|
|
|
const struct inode_operations configfs_symlink_inode_operations = {
|
2019-09-11 15:00:01 +08:00
|
|
|
.get_link = simple_get_link,
|
2006-01-26 05:31:07 +08:00
|
|
|
.setattr = configfs_setattr,
|
2005-12-16 06:29:43 +08:00
|
|
|
};
|
|
|
|
|