lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-id: <1412762671-2940-1-git-send-email-andrzej.p@samsung.com>
Date:	Wed, 08 Oct 2014 12:04:31 +0200
From:	Andrzej Pietrasiewicz <andrzej.p@...sung.com>
To:	linux-kernel@...r.kernel.org
Cc:	Joel Becker <jlbec@...lplan.org>, linux-usb@...r.kernel.org,
	Andrzej Pietrasiewicz <andrzej.p@...sung.com>,
	Felipe Balbi <balbi@...com>,
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	Sebastian Andrzej Siewior <bigeasy@...utronix.de>,
	Marek Szyprowski <m.szyprowski@...sung.com>
Subject: [PATCH] fs: configfs: add allow_drop() to configfs_item_operations

Sometimes it might be desirable to prohibit removing a symbolic link
in configfs. One example is USB gadget: when a gadget is already bound,
if USB function symlink (used to associate USB functions with USB
configurations) is removed, the gadget must be thrown away, too.
A better solution would be to fail with e.g. -EBUSY.

Why add a new method? Even though (*drop_link)() does have a return value,
it is ignored in fs/configfs/symlink.c:configfs_unlink(). It could be
tempting to just check the return value, but some users of configfs might
already depend on the fact that (*drop_link)() is called _after_
corresponding filesystem entities are torn down. In other words, the
semantics of (*drop_link)() is "the final, unconditional cleanup". In order
not to break this semantics, a new method is added and its value is checked
in fs/configfs/symlink.c:configfs_unlink().

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@...sung.com>
---
 fs/configfs/symlink.c    | 11 +++++++++--
 include/linux/configfs.h |  1 +
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/fs/configfs/symlink.c b/fs/configfs/symlink.c
index cc9f254..52851dc 100644
--- a/fs/configfs/symlink.c
+++ b/fs/configfs/symlink.c
@@ -198,6 +198,13 @@ int configfs_unlink(struct inode *dir, struct dentry *dentry)
 
 	parent_item = configfs_get_config_item(dentry->d_parent);
 	type = parent_item->ci_type;
+	if (type && type->ct_item_ops &&
+	    type->ct_item_ops->allow_drop) {
+		ret = type->ct_item_ops->allow_drop(parent_item,
+							sl->sl_target);
+		if (ret)
+			goto out_put;
+	}
 
 	spin_lock(&configfs_dirent_lock);
 	list_del_init(&sd->s_sibling);
@@ -224,10 +231,10 @@ int configfs_unlink(struct inode *dir, struct dentry *dentry)
 	config_item_put(sl->sl_target);
 	kfree(sl);
 
-	config_item_put(parent_item);
-
 	ret = 0;
 
+out_put:
+	config_item_put(parent_item);
 out:
 	return ret;
 }
diff --git a/include/linux/configfs.h b/include/linux/configfs.h
index 34025df..29df5e1 100644
--- a/include/linux/configfs.h
+++ b/include/linux/configfs.h
@@ -226,6 +226,7 @@ struct configfs_item_operations {
 	ssize_t	(*show_attribute)(struct config_item *, struct configfs_attribute *,char *);
 	ssize_t	(*store_attribute)(struct config_item *,struct configfs_attribute *,const char *, size_t);
 	int (*allow_link)(struct config_item *src, struct config_item *target);
+	int (*allow_drop)(struct config_item *src, struct config_item *target);
 	int (*drop_link)(struct config_item *src, struct config_item *target);
 };
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ