Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp357628pxj; Thu, 20 May 2021 10:55:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZ0vuyyV12/1ds3myPNiTIBZpKtrakldFx2JIKBWOerV7p5k65qeyIjIhJHNlthlFKR8pV X-Received: by 2002:a05:6402:1345:: with SMTP id y5mr6119950edw.107.1621533303080; Thu, 20 May 2021 10:55:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621533303; cv=none; d=google.com; s=arc-20160816; b=XgnJ+mfeBbhQrzP1JNdFbxAbudgUGdv6AedAqwnUHAkSWhBxqmiVrYqEFFCvh1NtLz gE2HbL9bmlq4Lz73vzhRWEPKfvFzEPoww8Y9v4SVtFqwRMP4K0ijhld3vsc+Mbi6+Guh madyE8hF7ud+DIVFeUR+8EZU/Q79aj+aX+uAy73wbzIuyyJICw7U4Rlhx9ey+VxaDSe4 3KfOi4BDXuRfhREmG9/MCDtOHxPXxwix1lH/GV7BUBgaaDNz1Xpp4PuiAPt32IEiRKqv BkFEepaUr8yAuV8CN9XtlXHj5nEw6/xHEGIG/kQ2F/dwSdAYWrB9xK3x/9pwqippxs4k n9bQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=glT/5hpvSYu9vSZzH8eGyoSlfHMBr13knGcUCa3yg38=; b=sP8aLNEtUuQKknPwGUUt5QRh1OWj5UlnOdRCu139o/TDpyvfrkmBHk53SWvyyoXeX5 ueD9yUw3+imoqzMhOVDdl5ifBiKWzOhxPkuE1131zzdRAj9cRWu03/Bo0dhMDwa2HMZC imKW37iS/Hsi7OCzJJeLI+WZa1w4ibBWJ+HeDpQxRcKyNedFP6AozohPgeO12dWOQzth +YxBW9wje6Dp69VU1DxrzQA8Iv31bb8lae2NWkMQDgMr5o8E8mLfH3Dl2DWwnQsv3V5L m7ddFr0ib5A8NLHrvXvw+NLlzb70kpoL+KceE4VOqMVoSLBXP1c2bTdKtkf2assrTwjO 4JYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YvoaofHv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a1si2646759edy.232.2021.05.20.10.54.36; Thu, 20 May 2021 10:55:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YvoaofHv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235374AbhETKMg (ORCPT + 99 others); Thu, 20 May 2021 06:12:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:36868 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235441AbhETKFC (ORCPT ); Thu, 20 May 2021 06:05:02 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0017461932; Thu, 20 May 2021 09:40:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621503654; bh=/ZW8JwvHwnl77jWCkthAo3Vaac0GolRsZMMhyixU/f4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YvoaofHv/GtiDlh2hEA6H4oGde9vP6Xf8QjoChkIe6Ks5QBxG4jHklJcjbSLkoAGK LYW6UAMPmVWZ5IyAEWcV+VqMfLVIz5C2PoLLa22huiGZxNbn1miEL/UdHY4YDSUD6Y goyCKTmBvDNGAJPOe5aQ/vExxYWkyHdqPEDFAD7g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Stefani Seibold , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 4.19 292/425] kfifo: fix ternary sign extension bugs Date: Thu, 20 May 2021 11:21:01 +0200 Message-Id: <20210520092141.049406998@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092131.308959589@linuxfoundation.org> References: <20210520092131.308959589@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dan Carpenter [ 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 Cc: Stefani Seibold Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- samples/kfifo/bytestream-example.c | 8 ++++++-- samples/kfifo/inttype-example.c | 8 ++++++-- samples/kfifo/record-example.c | 8 ++++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/samples/kfifo/bytestream-example.c b/samples/kfifo/bytestream-example.c index 2fca916d9edf..a7f5ee8b6edc 100644 --- a/samples/kfifo/bytestream-example.c +++ b/samples/kfifo/bytestream-example.c @@ -124,8 +124,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, @@ -140,8 +142,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 file_operations fifo_fops = { diff --git a/samples/kfifo/inttype-example.c b/samples/kfifo/inttype-example.c index 8dc3c2e7105a..a326a37e9163 100644 --- a/samples/kfifo/inttype-example.c +++ b/samples/kfifo/inttype-example.c @@ -117,8 +117,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, @@ -133,8 +135,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 file_operations fifo_fops = { diff --git a/samples/kfifo/record-example.c b/samples/kfifo/record-example.c index 2d7529eeb294..deb87a2e4e6b 100644 --- a/samples/kfifo/record-example.c +++ b/samples/kfifo/record-example.c @@ -131,8 +131,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, @@ -147,8 +149,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 file_operations fifo_fops = { -- 2.30.2