Skip to contentSkip to conversation

selinux: use sysfs_emit() to instead of scnprintf()

PATCH Superseded [email protected] 2 participants 3 messages Dec 5, 2022 – Dec 6, 2022 SELinux security module

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selinux: use sysfs_emit() to instead of scnprintf()

From: ye xingchen <[email protected]>

Follow the advice of the Documentation/filesystems/sysfs.rst and show() should only use sysfs_emit() or sysfs_emit_at() when formatting the value to be returned to user space.

---
 security/selinux/avc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
security/selinux/avc.c +1 -1
index 9a43af0ebd7d..517fe3454aec 100644
@@ -174,7 +174,7 @@ int avc_get_hash_stats(struct selinux_avc *avc, char *page)
 
 	rcu_read_unlock();
 
-	return scnprintf(page, PAGE_SIZE, "entries: %d\nbuckets used: %d/%d\n"
+	return sysfs_emit(page, "entries: %d\nbuckets used: %d/%d\n"
 			 "longest chain: %d\n",
 			 atomic_read(&avc->avc_cache.active_nodes),
 			 slots_used, AVC_CACHE_SLOTS, max_chain_len);
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 10 lines · On Mon, Dec 5, 2022 at 6:32 AM <[email protected]> wrote:

From: ye xingchen <[email protected]>

Follow the advice of the Documentation/filesystems/sysfs.rst and show() should only use sysfs_emit() or sysfs_emit_at() when formatting the value to be returned to user space.

---
 security/selinux/avc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

SELinux uses securityfs, not sysfs, for entries under /sys/fs/selinux.

Quoted 15 lines
security/selinux/avc.c +1 -2
index 9a43af0ebd7d..517fe3454aec 100644
@@ -174,7 +174,7 @@ int avc_get_hash_stats(struct selinux_avc *avc, char *page)
 
        rcu_read_unlock();
 
-       return scnprintf(page, PAGE_SIZE, "entries: %d\nbuckets used: %d/%d\n"
+       return sysfs_emit(page, "entries: %d\nbuckets used: %d/%d\n"
                         "longest chain: %d\n",
                         atomic_read(&avc->avc_cache.active_nodes),
                         slots_used, AVC_CACHE_SLOTS, max_chain_len);
--

2.25.1

Signature · 1 line
paul-moore.com
maintainer
#2 lore raw
Quoted 8 lines · Paul Moore
Quoted 6 lines · On Mon, Dec 5, 2022 at 6:32 AM <[email protected]> wrote:

From: ye xingchen <[email protected]>

Follow the advice of the Documentation/filesystems/sysfs.rst and show() should only use sysfs_emit() or sysfs_emit_at() when formatting the value to be returned to user space.

Quoted 6 lines
Quoted 4 lines
---
 security/selinux/avc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

SELinux uses securityfs, not sysfs, for entries under /sys/fs/selinux.

Sorry, a little mental mistake in the above, SELinux uses *selinuxfs* and not sysfs.

Thanks to the little birdie that pointed this out :)

Signature · 1 line
paul-moore.com