]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
/dev/zero: fixups for ->read
authorChristoph Hellwig <hch@lst.de>
Mon, 7 Sep 2020 08:27:00 +0000 (10:27 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 7 Sep 2020 08:46:35 +0000 (10:46 +0200)
Reported the cleared bytes in case of a partial clear_user instead
of -EFAULT, and remove a pointless conditional, as cleared must be
non-zero by the time we hit the signal_pending check.

Reported-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20200907082700.2057137-1-hch@lst.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/char/mem.c

index 1dc99ab158457a25c4c53eb183c1034f3bf9d74e..94c2b556cf9728ea66973f97b0d0222c97b36da5 100644 (file)
@@ -733,14 +733,20 @@ static ssize_t read_zero(struct file *file, char __user *buf,
 
        while (count) {
                size_t chunk = min_t(size_t, count, PAGE_SIZE);
+               size_t left;
 
-               if (clear_user(buf + cleared, chunk))
-                       return cleared ? cleared : -EFAULT;
+               left = clear_user(buf + cleared, chunk);
+               if (unlikely(left)) {
+                       cleared += (chunk - left);
+                       if (!cleared)
+                               return -EFAULT;
+                       break;
+               }
                cleared += chunk;
                count -= chunk;
 
                if (signal_pending(current))
-                       return cleared ? cleared : -ERESTARTSYS;
+                       break;
                cond_resched();
        }