]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
kfifo: fix ternary sign extension bugs
authorDan Carpenter <dan.carpenter@oracle.com>
Fri, 30 Apr 2021 05:54:15 +0000 (22:54 -0700)
committerKelsey Skunberg <kelsey.skunberg@canonical.com>
Mon, 24 May 2021 23:46:44 +0000 (17:46 -0600)
BugLink: https://bugs.launchpad.net/bugs/1929455
[ Upstream commit 926ee00ea24320052b46745ef4b00d91c05bd03d ]

The intent with this code was to return negative error codes but instead
it returns positives.

The problem is how type promotion works with ternary operations.  These
functions return long, "ret" is an int and "copied" is a u32.  The
negative error code is first cast to u32 so it becomes a high positive and
then cast to long where it's still a positive.

We could fix this by declaring "ret" as a ssize_t but let's just get rid
of the ternaries instead.

Link: https://lkml.kernel.org/r/YIE+/cK1tBzSuQPU@mwanda
Fixes: 5bf2b19320ec ("kfifo: add example files to the kernel sample directory")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Stefani Seibold <stefani@seibold.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kelsey Skunberg <kelsey.skunberg@canonical.com>
samples/kfifo/bytestream-example.c
samples/kfifo/inttype-example.c
samples/kfifo/record-example.c

index c406f03ee5519f3a97e021f0f7db290699c1d239..5a90aa527877551707ec74691c2d4d6b5630c90e 100644 (file)
@@ -122,8 +122,10 @@ static ssize_t fifo_write(struct file *file, const char __user *buf,
        ret = kfifo_from_user(&test, buf, count, &copied);
 
        mutex_unlock(&write_lock);
+       if (ret)
+               return ret;
 
-       return ret ? ret : copied;
+       return copied;
 }
 
 static ssize_t fifo_read(struct file *file, char __user *buf,
@@ -138,8 +140,10 @@ static ssize_t fifo_read(struct file *file, char __user *buf,
        ret = kfifo_to_user(&test, buf, count, &copied);
 
        mutex_unlock(&read_lock);
+       if (ret)
+               return ret;
 
-       return ret ? ret : copied;
+       return copied;
 }
 
 static const struct proc_ops fifo_proc_ops = {
index 78977fc4a23f74a22652f3cbfd88bf697de592a1..e5403d8c971a5bb7f4ce6dff835ed2a5b7efda35 100644 (file)
@@ -115,8 +115,10 @@ static ssize_t fifo_write(struct file *file, const char __user *buf,
        ret = kfifo_from_user(&test, buf, count, &copied);
 
        mutex_unlock(&write_lock);
+       if (ret)
+               return ret;
 
-       return ret ? ret : copied;
+       return copied;
 }
 
 static ssize_t fifo_read(struct file *file, char __user *buf,
@@ -131,8 +133,10 @@ static ssize_t fifo_read(struct file *file, char __user *buf,
        ret = kfifo_to_user(&test, buf, count, &copied);
 
        mutex_unlock(&read_lock);
+       if (ret)
+               return ret;
 
-       return ret ? ret : copied;
+       return copied;
 }
 
 static const struct proc_ops fifo_proc_ops = {
index c507998a2617cca9b3efa182ff86f2a313be2f1b..f64f3d62d6c2a4b93e50ef0f6424b8072d6770c7 100644 (file)
@@ -129,8 +129,10 @@ static ssize_t fifo_write(struct file *file, const char __user *buf,
        ret = kfifo_from_user(&test, buf, count, &copied);
 
        mutex_unlock(&write_lock);
+       if (ret)
+               return ret;
 
-       return ret ? ret : copied;
+       return copied;
 }
 
 static ssize_t fifo_read(struct file *file, char __user *buf,
@@ -145,8 +147,10 @@ static ssize_t fifo_read(struct file *file, char __user *buf,
        ret = kfifo_to_user(&test, buf, count, &copied);
 
        mutex_unlock(&read_lock);
+       if (ret)
+               return ret;
 
-       return ret ? ret : copied;
+       return copied;
 }
 
 static const struct proc_ops fifo_proc_ops = {