linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] sysctl: Make sure proc handlers can't expose heap memory
@ 2020-05-04 19:08 Kees Cook
  2020-05-04 19:59 ` Luis Chamberlain
  2020-05-05  5:58 ` Christoph Hellwig
  0 siblings, 2 replies; 9+ messages in thread
From: Kees Cook @ 2020-05-04 19:08 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Luis Chamberlain, Iurii Zaikin, Alexey Dobriyan, linux-mm,
	linux-fsdevel, linux-kernel

Just as a precaution, make sure that proc handlers don't accidentally
grow "count" beyond the allocated kbuf size.

Signed-off-by: Kees Cook <keescook@chromium.org>
---
This applies to hch's sysctl cleanup tree...
---
 fs/proc/proc_sysctl.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index 15030784566c..535ab26473af 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -546,6 +546,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *ubuf,
 	struct inode *inode = file_inode(filp);
 	struct ctl_table_header *head = grab_header(inode);
 	struct ctl_table *table = PROC_I(inode)->sysctl_entry;
+	size_t count_max = count;
 	void *kbuf;
 	ssize_t error;
 
@@ -590,6 +591,8 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *ubuf,
 
 	if (!write) {
 		error = -EFAULT;
+		if (WARN_ON(count > count_max))
+			count = count_max;
 		if (copy_to_user(ubuf, kbuf, count))
 			goto out_free_buf;
 	}
-- 
2.20.1


-- 
Kees Cook

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

end of thread, other threads:[~2020-05-05 23:23 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-04 19:08 [PATCH] sysctl: Make sure proc handlers can't expose heap memory Kees Cook
2020-05-04 19:59 ` Luis Chamberlain
2020-05-04 20:32   ` Kees Cook
2020-05-04 21:59     ` Luis Chamberlain
2020-05-05  6:34       ` Greg KH
2020-05-05 20:41         ` Kees Cook
2020-05-05 22:03           ` Luis Chamberlain
2020-05-05 23:23             ` Kees Cook
2020-05-05  5:58 ` Christoph Hellwig

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).