Implement ->proc_write_buf() so procfs copies in what is written before
it pins the entry, and look at the first character of that copy. Writes
larger than PAGE_SIZE - 1 bytes fail with -EINVAL now.

Signed-off-by: Christian Brauner (Amutable) <[email protected]>
---
 kernel/locking/lockdep_proc.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
index 9b034b5b94bd..2a66ea09c2aa 100644
--- a/kernel/locking/lockdep_proc.c
+++ b/kernel/locking/lockdep_proc.c
@@ -669,18 +669,14 @@ static int lock_stat_open(struct inode *inode, struct 
file *file)
        return 0;
 }
 
-static ssize_t lock_stat_write(struct file *file, const char __user *buf,
-                              size_t count, loff_t *ppos)
+static ssize_t lock_stat_write(struct file *file, char *buf, size_t count,
+                              loff_t *ppos)
 {
        struct lock_class *class;
        unsigned long idx;
-       char c;
 
        if (count) {
-               if (get_user(c, buf))
-                       return -EFAULT;
-
-               if (c != '0')
+               if (buf[0] != '0')
                        return count;
 
                iterate_lock_classes(idx, class) {
@@ -703,7 +699,7 @@ static int lock_stat_release(struct inode *inode, struct 
file *file)
 static const struct proc_ops lock_stat_proc_ops = {
        .proc_seq_ops   = &lockstat_ops,
        .proc_open      = lock_stat_open,
-       .proc_write     = lock_stat_write,
+       .proc_write_buf = lock_stat_write,
        .proc_release   = lock_stat_release,
 };
 #endif /* CONFIG_LOCK_STAT */

-- 
2.53.0

Reply via email to