[PATCH linux-next] selinux: avc: use sysfs_emit() instead of scnprintf()

xie.ludan@zte.com.cn posted 1 patch 9 months, 1 week ago
security/selinux/avc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH linux-next] selinux: avc: use sysfs_emit() instead of scnprintf()
Posted by xie.ludan@zte.com.cn 9 months, 1 week ago
From: XieLudan <xie.ludan@zte.com.cn>

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

Signed-off-by: XieLudan <xie.ludan@zte.com.cn>
---
 security/selinux/avc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/security/selinux/avc.c b/security/selinux/avc.c
index 4b4837a20225..007bd94975c0 100644
--- a/security/selinux/avc.c
+++ b/security/selinux/avc.c
@@ -164,7 +164,7 @@ int avc_get_hash_stats(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(&selinux_avc.avc_cache.active_nodes),
 			 slots_used, AVC_CACHE_SLOTS, max_chain_len);
-- 
2.25.1
Re: [PATCH linux-next] selinux: avc: use sysfs_emit() instead of scnprintf()
Posted by Stephen Smalley 9 months ago
On Sat, Mar 15, 2025 at 2:12 AM <xie.ludan@zte.com.cn> wrote:
>
> From: XieLudan <xie.ludan@zte.com.cn>
>
>
> Follow the advice in Documentation/filesystems/sysfs.rst:
>
> show() should only use sysfs_emit() or sysfs_emit_at() when formatting
>
> the value to be returned to user space.
>
>
> Signed-off-by: XieLudan <xie.ludan@zte.com.cn>

NAK.
Despite being mounted under /sys, selinuxfs is its own pseudo
filesystem and thus shouldn't use sysfs functions.

>
> ---
>
>  security/selinux/avc.c | 2 +-
>
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
>
> diff --git a/security/selinux/avc.c b/security/selinux/avc.c
>
> index 4b4837a20225..007bd94975c0 100644
>
> --- a/security/selinux/avc.c
>
> +++ b/security/selinux/avc.c
>
> @@ -164,7 +164,7 @@ int avc_get_hash_stats(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(&selinux_avc.avc_cache.active_nodes),
>
>   slots_used, AVC_CACHE_SLOTS, max_chain_len);
>
> --
>
> 2.25.1
>
>
>
>
>