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: <20250315141136817waFGT5DFhPs9QMwybNwb5@zte.com.cn>
Date: Sat, 15 Mar 2025 14:11:36 +0800 (CST)
From: <xie.ludan@....com.cn>
To: <stephen.smalley.work@...il.com>
Cc: <paul@...l-moore.com>, <omosnace@...hat.com>, <selinux@...r.kernel.org>,
        <linux-kernel@...r.kernel.org>
Subject: [PATCH linux-next] selinux:  use sysfs_emit() instead of scnprintf()

From: XieLudan <xie.ludan@....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@....com.cn>
---
 security/selinux/selinuxfs.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c
index 47480eb2189b..17c56fc87d98 100644
--- a/security/selinux/selinuxfs.c
+++ b/security/selinux/selinuxfs.c
@@ -126,7 +126,7 @@ static ssize_t sel_read_enforce(struct file *filp, char __user *buf,
 	char tmpbuf[TMPBUFLEN];
 	ssize_t length;
 
-	length = scnprintf(tmpbuf, TMPBUFLEN, "%d",
+	length = sysfs_emit(tmpbuf, "%d",
 			   enforcing_enabled());
 	return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
 }
@@ -206,7 +206,7 @@ static ssize_t sel_read_handle_unknown(struct file *filp, char __user *buf,
 		security_get_reject_unknown() :
 		!security_get_allow_unknown();
 
-	length = scnprintf(tmpbuf, TMPBUFLEN, "%d", handle_unknown);
+	length = sysfs_emit(tmpbuf, "%d", handle_unknown);
 	return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
 }
 
@@ -314,7 +314,7 @@ static ssize_t sel_read_policyvers(struct file *filp, char __user *buf,
 	char tmpbuf[TMPBUFLEN];
 	ssize_t length;
 
-	length = scnprintf(tmpbuf, TMPBUFLEN, "%u", POLICYDB_VERSION_MAX);
+	length = sysfs_emit(tmpbuf, "%u", POLICYDB_VERSION_MAX);
 	return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
 }
 
@@ -345,7 +345,7 @@ static ssize_t sel_read_mls(struct file *filp, char __user *buf,
 	char tmpbuf[TMPBUFLEN];
 	ssize_t length;
 
-	length = scnprintf(tmpbuf, TMPBUFLEN, "%d",
+	length = sysfs_emit(tmpbuf, "%d",
 			   security_mls_enabled());
 	return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
 }
@@ -670,7 +670,7 @@ static ssize_t sel_read_checkreqprot(struct file *filp, char __user *buf,
 	char tmpbuf[TMPBUFLEN];
 	ssize_t length;
 
-	length = scnprintf(tmpbuf, TMPBUFLEN, "%u",
+	length = sysfs_emit(tmpbuf, "%u",
 			   checkreqprot_get());
 	return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
 }
@@ -1226,7 +1226,7 @@ static ssize_t sel_read_bool(struct file *filep, char __user *buf,
 		ret = cur_enforcing;
 		goto out_unlock;
 	}
-	length = scnprintf(page, PAGE_SIZE, "%d %d", cur_enforcing,
+	length = sysfs_emit(page, "%d %d", cur_enforcing,
 			  fsi->bool_pending_values[index]);
 	mutex_unlock(&selinux_state.policy_mutex);
 	ret = simple_read_from_buffer(buf, count, ppos, page, length);
@@ -1416,7 +1416,7 @@ static ssize_t sel_read_avc_cache_threshold(struct file *filp, char __user *buf,
 	char tmpbuf[TMPBUFLEN];
 	ssize_t length;
 
-	length = scnprintf(tmpbuf, TMPBUFLEN, "%u",
+	length = sysfs_emit(tmpbuf, "%u",
 			   avc_get_cache_threshold());
 	return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
 }
@@ -1726,7 +1726,7 @@ static ssize_t sel_read_class(struct file *file, char __user *buf,
 {
 	unsigned long ino = file_inode(file)->i_ino;
 	char res[TMPBUFLEN];
-	ssize_t len = scnprintf(res, sizeof(res), "%d", sel_ino_to_class(ino));
+	ssize_t len = sysfs_emit(res, "%d", sel_ino_to_class(ino));
 	return simple_read_from_buffer(buf, count, ppos, res, len);
 }
 
@@ -1740,7 +1740,7 @@ static ssize_t sel_read_perm(struct file *file, char __user *buf,
 {
 	unsigned long ino = file_inode(file)->i_ino;
 	char res[TMPBUFLEN];
-	ssize_t len = scnprintf(res, sizeof(res), "%d", sel_ino_to_perm(ino));
+	ssize_t len = sysfs_emit(res, "%d", sel_ino_to_perm(ino));
 	return simple_read_from_buffer(buf, count, ppos, res, len);
 }
 
@@ -1758,7 +1758,7 @@ static ssize_t sel_read_policycap(struct file *file, char __user *buf,
 	unsigned long i_ino = file_inode(file)->i_ino;
 
 	value = security_policycap_supported(i_ino & SEL_INO_MASK);
-	length = scnprintf(tmpbuf, TMPBUFLEN, "%d", value);
+	length = sysfs_emit(tmpbuf, "%d", value);
 
 	return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
 }
-- 
2.25.1
<div class="zcontentRow"><p style="font-size:14px;font-family:微软雅黑,Microsoft YaHei;"><span style="font-family: sans-serif;"><span style="font-family: Arial, Helvetica, &quot;Microsoft Yahei&quot;, sans-serif; background-color: rgb(255, 255, 255);">From: XieLudan &lt;xie.ludan@....com.cn&gt;</span></span><br></p><p><br></p><p>Follow the advice in Documentation/filesystems/sysfs.rst:</p><p>show() should only use sysfs_emit() or sysfs_emit_at() when formatting</p><p>the value to be returned to user space.</p><p><br></p><p>Signed-off-by: XieLudan &lt;xie.ludan@....com.cn&gt;</p><p>---</p><p>&nbsp;security/selinux/selinuxfs.c | 20 ++++++++++----------</p><p>&nbsp;1 file changed, 10 insertions(+), 10 deletions(-)</p><p><br></p><p>diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c</p><p>index 47480eb2189b..17c56fc87d98 100644</p><p>--- a/security/selinux/selinuxfs.c</p><p>+++ b/security/selinux/selinuxfs.c</p><p>@@ -126,7 +126,7 @@ static ssize_t sel_read_enforce(struct file *filp, char __user *buf,</p><p>&nbsp;<span style="white-space:pre">	</span>char tmpbuf[TMPBUFLEN];</p><p>&nbsp;<span style="white-space:pre">	</span>ssize_t length;</p><p>&nbsp;</p><p>-<span style="white-space:pre">	</span>length = scnprintf(tmpbuf, TMPBUFLEN, "%d",</p><p>+<span style="white-space:pre">	</span>length = sysfs_emit(tmpbuf, "%d",</p><p>&nbsp;<span style="white-space:pre">			</span>&nbsp; &nbsp;enforcing_enabled());</p><p>&nbsp;<span style="white-space:pre">	</span>return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);</p><p>&nbsp;}</p><p>@@ -206,7 +206,7 @@ static ssize_t sel_read_handle_unknown(struct file *filp, char __user *buf,</p><p>&nbsp;<span style="white-space:pre">		</span>security_get_reject_unknown() :</p><p>&nbsp;<span style="white-space:pre">		</span>!security_get_allow_unknown();</p><p>&nbsp;</p><p>-<span style="white-space:pre">	</span>length = scnprintf(tmpbuf, TMPBUFLEN, "%d", handle_unknown);</p><p>+<span style="white-space:pre">	</span>length = sysfs_emit(tmpbuf, "%d", handle_unknown);</p><p>&nbsp;<span style="white-space:pre">	</span>return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);</p><p>&nbsp;}</p><p>&nbsp;</p><p>@@ -314,7 +314,7 @@ static ssize_t sel_read_policyvers(struct file *filp, char __user *buf,</p><p>&nbsp;<span style="white-space:pre">	</span>char tmpbuf[TMPBUFLEN];</p><p>&nbsp;<span style="white-space:pre">	</span>ssize_t length;</p><p>&nbsp;</p><p>-<span style="white-space:pre">	</span>length = scnprintf(tmpbuf, TMPBUFLEN, "%u", POLICYDB_VERSION_MAX);</p><p>+<span style="white-space:pre">	</span>length = sysfs_emit(tmpbuf, "%u", POLICYDB_VERSION_MAX);</p><p>&nbsp;<span style="white-space:pre">	</span>return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);</p><p>&nbsp;}</p><p>&nbsp;</p><p>@@ -345,7 +345,7 @@ static ssize_t sel_read_mls(struct file *filp, char __user *buf,</p><p>&nbsp;<span style="white-space:pre">	</span>char tmpbuf[TMPBUFLEN];</p><p>&nbsp;<span style="white-space:pre">	</span>ssize_t length;</p><p>&nbsp;</p><p>-<span style="white-space:pre">	</span>length = scnprintf(tmpbuf, TMPBUFLEN, "%d",</p><p>+<span style="white-space:pre">	</span>length = sysfs_emit(tmpbuf, "%d",</p><p>&nbsp;<span style="white-space:pre">			</span>&nbsp; &nbsp;security_mls_enabled());</p><p>&nbsp;<span style="white-space:pre">	</span>return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);</p><p>&nbsp;}</p><p>@@ -670,7 +670,7 @@ static ssize_t sel_read_checkreqprot(struct file *filp, char __user *buf,</p><p>&nbsp;<span style="white-space:pre">	</span>char tmpbuf[TMPBUFLEN];</p><p>&nbsp;<span style="white-space:pre">	</span>ssize_t length;</p><p>&nbsp;</p><p>-<span style="white-space:pre">	</span>length = scnprintf(tmpbuf, TMPBUFLEN, "%u",</p><p>+<span style="white-space:pre">	</span>length = sysfs_emit(tmpbuf, "%u",</p><p>&nbsp;<span style="white-space:pre">			</span>&nbsp; &nbsp;checkreqprot_get());</p><p>&nbsp;<span style="white-space:pre">	</span>return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);</p><p>&nbsp;}</p><p>@@ -1226,7 +1226,7 @@ static ssize_t sel_read_bool(struct file *filep, char __user *buf,</p><p>&nbsp;<span style="white-space:pre">		</span>ret = cur_enforcing;</p><p>&nbsp;<span style="white-space:pre">		</span>goto out_unlock;</p><p>&nbsp;<span style="white-space:pre">	</span>}</p><p>-<span style="white-space:pre">	</span>length = scnprintf(page, PAGE_SIZE, "%d %d", cur_enforcing,</p><p>+<span style="white-space:pre">	</span>length = sysfs_emit(page, "%d %d", cur_enforcing,</p><p>&nbsp;<span style="white-space:pre">			</span>&nbsp; fsi-&gt;bool_pending_values[index]);</p><p>&nbsp;<span style="white-space:pre">	</span>mutex_unlock(&amp;selinux_state.policy_mutex);</p><p>&nbsp;<span style="white-space:pre">	</span>ret = simple_read_from_buffer(buf, count, ppos, page, length);</p><p>@@ -1416,7 +1416,7 @@ static ssize_t sel_read_avc_cache_threshold(struct file *filp, char __user *buf,</p><p>&nbsp;<span style="white-space:pre">	</span>char tmpbuf[TMPBUFLEN];</p><p>&nbsp;<span style="white-space:pre">	</span>ssize_t length;</p><p>&nbsp;</p><p>-<span style="white-space:pre">	</span>length = scnprintf(tmpbuf, TMPBUFLEN, "%u",</p><p>+<span style="white-space:pre">	</span>length = sysfs_emit(tmpbuf, "%u",</p><p>&nbsp;<span style="white-space:pre">			</span>&nbsp; &nbsp;avc_get_cache_threshold());</p><p>&nbsp;<span style="white-space:pre">	</span>return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);</p><p>&nbsp;}</p><p>@@ -1726,7 +1726,7 @@ static ssize_t sel_read_class(struct file *file, char __user *buf,</p><p>&nbsp;{</p><p>&nbsp;<span style="white-space:pre">	</span>unsigned long ino = file_inode(file)-&gt;i_ino;</p><p>&nbsp;<span style="white-space:pre">	</span>char res[TMPBUFLEN];</p><p>-<span style="white-space:pre">	</span>ssize_t len = scnprintf(res, sizeof(res), "%d", sel_ino_to_class(ino));</p><p>+<span style="white-space:pre">	</span>ssize_t len = sysfs_emit(res, "%d", sel_ino_to_class(ino));</p><p>&nbsp;<span style="white-space:pre">	</span>return simple_read_from_buffer(buf, count, ppos, res, len);</p><p>&nbsp;}</p><p>&nbsp;</p><p>@@ -1740,7 +1740,7 @@ static ssize_t sel_read_perm(struct file *file, char __user *buf,</p><p>&nbsp;{</p><p>&nbsp;<span style="white-space:pre">	</span>unsigned long ino = file_inode(file)-&gt;i_ino;</p><p>&nbsp;<span style="white-space:pre">	</span>char res[TMPBUFLEN];</p><p>-<span style="white-space:pre">	</span>ssize_t len = scnprintf(res, sizeof(res), "%d", sel_ino_to_perm(ino));</p><p>+<span style="white-space:pre">	</span>ssize_t len = sysfs_emit(res, "%d", sel_ino_to_perm(ino));</p><p>&nbsp;<span style="white-space:pre">	</span>return simple_read_from_buffer(buf, count, ppos, res, len);</p><p>&nbsp;}</p><p>&nbsp;</p><p>@@ -1758,7 +1758,7 @@ static ssize_t sel_read_policycap(struct file *file, char __user *buf,</p><p>&nbsp;<span style="white-space:pre">	</span>unsigned long i_ino = file_inode(file)-&gt;i_ino;</p><p>&nbsp;</p><p>&nbsp;<span style="white-space:pre">	</span>value = security_policycap_supported(i_ino &amp; SEL_INO_MASK);</p><p>-<span style="white-space:pre">	</span>length = scnprintf(tmpbuf, TMPBUFLEN, "%d", value);</p><p>+<span style="white-space:pre">	</span>length = sysfs_emit(tmpbuf, "%d", value);</p><p>&nbsp;</p><p>&nbsp;<span style="white-space:pre">	</span>return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);</p><p>&nbsp;}</p><p>--&nbsp;</p><p>2.25.1</p><p style="font-size:14px;font-family:微软雅黑,Microsoft YaHei;"><br></p><p style="font-size:14px;font-family:微软雅黑,Microsoft YaHei;"><br></p><p style="font-size:14px;font-family:微软雅黑,Microsoft YaHei;"><br></p></div>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ