Skip to contentSkip to conversation

debugfs: Fix debugfs_read_file_str()

PATCH In review Dietmar Eggemann 4 participants 4 messages May 27, 2021 – Jun 4, 2021 Driver core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 debugfs: Fix debugfs_read_file_str()

Read the entire size of the buffer, including the trailing new line character.
Discovered while reading the sched domain names of CPU0:

before:

cat /sys/kernel/debug/sched/domains/cpu0/domain*/name SMTMCDIE

after:

cat /sys/kernel/debug/sched/domains/cpu0/domain*/name SMT
MC
DIE

Fixes 9af0440ec86eb ("debugfs: Implement debugfs_create_str()")
---
 fs/debugfs/file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/debugfs/file.c +1 -1
index e813acfaa6e8..ba7c01cd9a5d 100644
@@ -893,7 +893,7 @@ ssize_t debugfs_read_file_str(struct file *file, char __user *user_buf,
 
 	copy[copy_len] = '\n';
 
-	ret = simple_read_from_buffer(user_buf, count, ppos, copy, copy_len);
+	ret = simple_read_from_buffer(user_buf, count, ppos, copy, len);
 	kfree(copy);
 
 	return ret;
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw

fs/debugfs/file.c ssize_t debugfs_read_file_str(struct file *file, char __user *user_buf, · line 897

Quoted 8 lines · On Thu, 27 May 2021 11:11:05 +0200 Dietmar Eggemann <[email protected]>…

+++ b/fs/debugfs/file.c

fs/debugfs/file.c +1 -1
@@ -893,7 +893,7 @@ ssize_t debugfs_read_file_str(struct file *file, char __user *user_buf,
 
 	copy[copy_len] = '\n';
 
-	ret = simple_read_from_buffer(user_buf, count, ppos, copy, copy_len);
+	ret = simple_read_from_buffer(user_buf, count, ppos, copy, len);
 	kfree(copy);

As we have:

	len = strlen(str) + 1;
	[..]
	copy_len = strscpy(copy, str, len);

I can't think of any situation that len is not equal to copy_len + 1. :-/

Anyway, either "len" or "copy_len + 1" would work.

-- Steve

Acked-by on v1 1/1
#2 lore raw
In reply to Dietmar Eggemann
Quoted 11 lines · Dietmar Eggemann

Read the entire size of the buffer, including the trailing new line character.
Discovered while reading the sched domain names of CPU0:

before:

cat /sys/kernel/debug/sched/domains/cpu0/domain*/name SMTMCDIE

after:

Quoted 7 lines

cat /sys/kernel/debug/sched/domains/cpu0/domain*/name SMT
MC
DIE

Fixes 9af0440ec86eb ("debugfs: Implement debugfs_create_str()")

Urgh.. so much for last minute changes :/

Greg, AFAICT that commit has since landed in Linus, will you take care of this?

#3 lore raw
Quoted 20 lines · Peter Zijlstra
Quoted 11 lines · Dietmar Eggemann

Read the entire size of the buffer, including the trailing new line character.
Discovered while reading the sched domain names of CPU0:

before:

cat /sys/kernel/debug/sched/domains/cpu0/domain*/name SMTMCDIE

after:

Quoted 7 lines

cat /sys/kernel/debug/sched/domains/cpu0/domain*/name SMT
MC
DIE

Fixes 9af0440ec86eb ("debugfs: Implement debugfs_create_str()")
Quoted 6 lines

Urgh.. so much for last minute changes :/

Greg, AFAICT that commit has since landed in Linus, will you take care of this?

Yes, I'll pick it up now, thanks.

greg k-h