2022-12-05 12:01:18

by ye.xingchen

[permalink] [raw]
Subject: [PATCH security-next] 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.

Signed-off-by: ye xingchen <[email protected]>
---
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 9a43af0ebd7d..517fe3454aec 100644
--- a/security/selinux/avc.c
+++ b/security/selinux/avc.c
@@ -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


2022-12-06 20:34:55

by Paul Moore

[permalink] [raw]
Subject: Re: [PATCH security-next] selinux: use sysfs_emit() to instead of scnprintf()

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.
>
> Signed-off-by: ye xingchen <[email protected]>
> ---
> security/selinux/avc.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)

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

> diff --git a/security/selinux/avc.c b/security/selinux/avc.c
> index 9a43af0ebd7d..517fe3454aec 100644
> --- a/security/selinux/avc.c
> +++ b/security/selinux/avc.c
> @@ -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

--
paul-moore.com

2022-12-06 23:02:23

by Paul Moore

[permalink] [raw]
Subject: Re: [PATCH security-next] selinux: use sysfs_emit() to instead of scnprintf()

On Tue, Dec 6, 2022 at 3:26 PM Paul Moore <[email protected]> wrote:
>
> 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.
> >
> > Signed-off-by: ye xingchen <[email protected]>
> > ---
> > 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 :)

--
paul-moore.com