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>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210908120723.3920701-1-lang.yu@amd.com>
Date:   Wed, 8 Sep 2021 20:07:23 +0800
From:   Lang Yu <lang.yu@....com>
To:     Joe Perches <joe@...ches.com>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        "Rafael J . Wysocki" <rafael@...nel.org>,
        <linux-kernel@...r.kernel.org>
CC:     Lang Yu <lang.yu@....com>
Subject: [PATCH] sysfs: Remove page boundary align limitation on sysfs_emit and sysfs_emit_at

The key purpose of sysfs_emit and sysfs_emit_at is to
ensure that no overrun is done. Make them more equivalent
with scnprintf.

Signed-off-by: Lang Yu <lang.yu@....com>
---
 fs/sysfs/file.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index 9aefa7779b29..b754f2ef186f 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -732,14 +732,16 @@ EXPORT_SYMBOL_GPL(sysfs_change_owner);
 int sysfs_emit(char *buf, const char *fmt, ...)
 {
 	va_list args;
-	int len;
+	int len, offset;
 
-	if (WARN(!buf || offset_in_page(buf),
+	offset = offset_in_page(buf);
+
+	if (WARN(!buf,
 		 "invalid sysfs_emit: buf:%p\n", buf))
 		return 0;
 
 	va_start(args, fmt);
-	len = vscnprintf(buf, PAGE_SIZE, fmt, args);
+	len = vscnprintf(buf, PAGE_SIZE - offset, fmt, args);
 	va_end(args);
 
 	return len;
@@ -760,14 +762,16 @@ EXPORT_SYMBOL_GPL(sysfs_emit);
 int sysfs_emit_at(char *buf, int at, const char *fmt, ...)
 {
 	va_list args;
-	int len;
+	int len, offset;
+
+	offset = offset_in_page(buf);
 
-	if (WARN(!buf || offset_in_page(buf) || at < 0 || at >= PAGE_SIZE,
+	if (WARN(!buf || at < 0 || at + offset >= PAGE_SIZE,
 		 "invalid sysfs_emit_at: buf:%p at:%d\n", buf, at))
 		return 0;
 
 	va_start(args, fmt);
-	len = vscnprintf(buf + at, PAGE_SIZE - at, fmt, args);
+	len = vscnprintf(buf + at, PAGE_SIZE - at - offset, fmt, args);
 	va_end(args);
 
 	return len;
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ