linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] sysfs: Remove page boundary align limitation on sysfs_emit and sysfs_emit_at
@ 2021-09-08 12:07 Lang Yu
  2021-09-08 12:32 ` Greg Kroah-Hartman
  2021-09-09  5:05 ` Joe Perches
  0 siblings, 2 replies; 23+ messages in thread
From: Lang Yu @ 2021-09-08 12:07 UTC (permalink / raw)
  To: Joe Perches, Greg Kroah-Hartman, Rafael J . Wysocki, linux-kernel; +Cc: Lang Yu

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@amd.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


^ permalink raw reply related	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2021-09-09  8:48 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-08 12:07 [PATCH] sysfs: Remove page boundary align limitation on sysfs_emit and sysfs_emit_at Lang Yu
2021-09-08 12:32 ` Greg Kroah-Hartman
2021-09-08 12:52   ` Yu, Lang
2021-09-08 13:04     ` Greg Kroah-Hartman
2021-09-08 13:21       ` Yu, Lang
2021-09-08 13:49         ` Greg Kroah-Hartman
2021-09-08 15:33           ` Yu, Lang
2021-09-09  5:19             ` Greg Kroah-Hartman
2021-09-09  5:31               ` Yu, Lang
2021-09-09  6:05                 ` Greg Kroah-Hartman
2021-09-09  5:05 ` Joe Perches
2021-09-09  5:27   ` Yu, Lang
2021-09-09  5:34     ` Greg Kroah-Hartman
2021-09-09  5:59       ` Yu, Lang
2021-09-09  6:07         ` Greg Kroah-Hartman
2021-09-09  5:44     ` Joe Perches
2021-09-09  5:52       ` Yu, Lang
2021-09-09  6:07         ` Greg Kroah-Hartman
2021-09-09  6:22           ` Yu, Lang
2021-09-09  6:35             ` Greg Kroah-Hartman
2021-09-09  7:48               ` Yu, Lang
2021-09-09  7:59                 ` Greg Kroah-Hartman
2021-09-09  8:48                   ` Yu, Lang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).