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>] [thread-next>] [day] [month] [year] [list]
Date:	Fri, 16 Jan 2015 16:29:10 -0500
From:	Vivien Didelot <vivien.didelot@...oirfairelinux.com>
To:	linux-kernel@...r.kernel.org
Cc:	Vivien Didelot <vivien.didelot@...oirfairelinux.com>,
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	kernel@...oirfairelinux.com
Subject: [PATCH] sysfs: group: allow is_visible to drop permissions

Using the optional is_visible function, it is actually possible to
either hide an attribute, or add a new permission, but not remove one.

This commit uses all the UGO bits returned by is_visible instead of
OR'ing them with the default attribute mode.

Concretely, this allows a driver to use macros like DEVICE_ATTR_RW to
set the attribute show and store functions and remove the S_IWUSR
permission in is_visible if the implementation doesn't provide a setter.

Signed-off-by: Vivien Didelot <vivien.didelot@...oirfairelinux.com>
---
 fs/sysfs/group.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c
index 7d2a860..a8cfe03 100644
--- a/fs/sysfs/group.c
+++ b/fs/sysfs/group.c
@@ -41,7 +41,7 @@ static int create_files(struct kernfs_node *parent, struct kobject *kobj,
 
 	if (grp->attrs) {
 		for (i = 0, attr = grp->attrs; *attr && !error; i++, attr++) {
-			umode_t mode = 0;
+			umode_t mode = (*attr)->mode;
 
 			/*
 			 * In update mode, we're changing the permissions or
@@ -51,13 +51,15 @@ static int create_files(struct kernfs_node *parent, struct kobject *kobj,
 			if (update)
 				kernfs_remove_by_name(parent, (*attr)->name);
 			if (grp->is_visible) {
-				mode = grp->is_visible(kobj, *attr, i);
-				if (!mode)
+				umode_t ugo = grp->is_visible(kobj, *attr, i);
+
+				if (!(ugo & S_IRWXUGO))
 					continue;
+
+				mode = (mode & ~S_IRWXUGO) | (ugo & S_IRWXUGO);
 			}
 			error = sysfs_add_file_mode_ns(parent, *attr, false,
-						       (*attr)->mode | mode,
-						       NULL);
+						       mode, NULL);
 			if (unlikely(error))
 				break;
 		}
-- 
2.2.2

--
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