From patchwork Sat Mar 15 06:11:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: xie.ludan@zte.com.cn X-Patchwork-Id: 14017727 Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.216.63.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8EADB10F9; Sat, 15 Mar 2025 06:11:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=63.216.63.35 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742019110; cv=none; b=XvDc800C9zCGqRQEciVhu/epeqgYFHxfekiriQJ31FkpwspsWCfk8SCxsnBaL3aa7rn+VZyVxxvlNKTJKHJmyEaXKk4Qiwjn2poYogp1tvFhFALQfaCz263RC6LgXi/75bnE9av2ZxFMQ/0fIQAFLPrt/szbau5Rn5Ju4XXkytA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742019110; c=relaxed/simple; bh=F3BjX/Q6lKUXb9XViAVRqC+1CzuTF37QoEnuiDAZ5y8=; h=Date:Message-ID:Mime-Version:From:To:Cc:Subject:Content-Type; b=HB3A9UJTUjNkNtksE7oNSa91eePXniXBTVvC7ZzrlU7ds/IbcyzpkjZsBYAPOKpqkyhU3QBknKB/YxL7dtT64WcgLXfKIteUvNV62EeDby1WP4bYh+BAVtVzqiFQlQksIVKYSD2fNdLmdyJVS/Ar2GEuY50heB4CrPL28P46328= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zte.com.cn; spf=pass smtp.mailfrom=zte.com.cn; arc=none smtp.client-ip=63.216.63.35 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zte.com.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zte.com.cn Received: from mse-fl1.zte.com.cn (unknown [10.5.228.132]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mxhk.zte.com.cn (FangMail) with ESMTPS id 4ZF9qN2PZ8z5B1J5; Sat, 15 Mar 2025 14:11:44 +0800 (CST) Received: from xaxapp05.zte.com.cn ([10.99.98.109]) by mse-fl1.zte.com.cn with SMTP id 52F6Ba7W009253; Sat, 15 Mar 2025 14:11:36 +0800 (+08) (envelope-from xie.ludan@zte.com.cn) Received: from mapi (xaxapp05[null]) by mapi (Zmail) with MAPI id mid32; Sat, 15 Mar 2025 14:11:36 +0800 (CST) Date: Sat, 15 Mar 2025 14:11:36 +0800 (CST) X-Zmail-TransId: 2afc67d51a1810b-60f06 X-Mailer: Zmail v1.0 Message-ID: <20250315141136817waFGT5DFhPs9QMwybNwb5@zte.com.cn> Precedence: bulk X-Mailing-List: selinux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 From: To: Cc: , , , Subject: =?utf-8?q?=5BPATCH_linux-next=5D_selinux=3A__use_sysfs=5Femit=28=29?= =?utf-8?q?_instead_of_scnprintf=28=29?= X-MAIL: mse-fl1.zte.com.cn 52F6Ba7W009253 X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 67D51A20.000/4ZF9qN2PZ8z5B1J5 From: XieLudan 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 --- 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); }