fs, proc: truncate /proc/pid/comm writes to first TASK_COMM_LEN bytes
[platform/adaptation/renesas_rcar/renesas_kernel.git] / fs / proc / base.c
index a193086..3861bce 100644 (file)
@@ -1348,11 +1348,10 @@ static ssize_t comm_write(struct file *file, const char __user *buf,
        struct inode *inode = file_inode(file);
        struct task_struct *p;
        char buffer[TASK_COMM_LEN];
+       const size_t maxlen = sizeof(buffer) - 1;
 
        memset(buffer, 0, sizeof(buffer));
-       if (count > sizeof(buffer) - 1)
-               count = sizeof(buffer) - 1;
-       if (copy_from_user(buffer, buf, count))
+       if (copy_from_user(buffer, buf, count > maxlen ? maxlen : count))
                return -EFAULT;
 
        p = get_proc_task(inode);