Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4568185pxj; Wed, 12 May 2021 08:21:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5bM/f97YjYv+OiriG4h75rIDAwk2zU8D0ldJ0ktGN4kX3t9vMhMgJAyRX9zC8T2DA0yUa X-Received: by 2002:a4a:eb97:: with SMTP id d23mr12860599ooj.70.1620832884191; Wed, 12 May 2021 08:21:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620832884; cv=none; d=google.com; s=arc-20160816; b=UG5lwF351Vg9Qw8gbOqwZhtu8VhQQD1LEyLgJ84NbaMY+Q+LDVknGGWXbGTcq95w52 TqIASxWTf2Y1EcQS5sU1mPc86IMCnE5O+4tZVmMjgUXHr6NHmj0DGddrNT6Pm8wVcBlr cnAOG2EFgO6MwhACFzeRFQ+KeN1gEouNtO+R3ZnWUnP4varm0tN7Spy83dWXvlqfKS4A wC27JrJTddn+0BPOG4psSsjeXZ57IQCFWMX+kpEAS3UD79mDndjHoFLce8ipbRErcA6I GXtSvMRzUcaseCmPNirqDsZhDEOachCwQe91cQ+k03GLYXoQ4ijTOnYM9X0xw48OR4nM tUQw== 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=linfE4RUL+w6Kk18dxWOZPM9WGodrRwQAvgYP/MRJPE=; b=YXoTNQBPiysCjmGbWYEH7W3D6nx3Eovk9i5Y/1yzpkp4Tp5i1anvl8VR33VPuobsWP jCj4rjw1Fy/cyee0u7grjDrwXJA5jPhjhwzUBDTOLqLU+OSBtak18F0B3k6x60xk/s9J MHWTxp0SrxaE9+6HdNT9eok8Nom7C0mTUE/KSXGTv3iT8pqPekjcpNLbbzH5ESBkMB0Y AK4mDWmI44Qc9G7x8ceh4sCERMtdfY9C4CQQf5PL85OkJsrjQc6dMzVcBEqM+Wy5rYIB d9Fb/z0u1PrGrCszMl4Tsn0z8vVFQVuMMGoZyT9Qh5V99aNkrAzqytNsG+zwEIMokcql eYpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FI2AWcMl; 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 v5si150979ote.104.2021.05.12.08.21.10; Wed, 12 May 2021 08:21:24 -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=FI2AWcMl; 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 S233771AbhELPU7 (ORCPT + 99 others); Wed, 12 May 2021 11:20:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:37632 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233628AbhELPJ4 (ORCPT ); Wed, 12 May 2021 11:09:56 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2E14A6142F; Wed, 12 May 2021 15:02:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620831757; bh=4aPshFcRRpN8h7tjRvA2mKCEe9AApPILfvDmRUBjODc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FI2AWcMl0TaoKTukRtu1f3oIyoI70KvamsK4gDX0D034q3MRo4Q77jFeGj4N5o3jF 777XiF829yRFg63MVwEiWZIr4qAFUZE6gFJF5qvc97QuC/zpyJxyyO3AOsuiGxvJuA 4738iqvLeLnzVklneu2SAE6v6p8pgyWVlFR9cPC8= 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 5.4 236/244] kfifo: fix ternary sign extension bugs Date: Wed, 12 May 2021 16:50:07 +0200 Message-Id: <20210512144750.555619324@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144743.039977287@linuxfoundation.org> References: <20210512144743.039977287@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 9ca3e4400c98..ecae2139274f 100644 --- a/samples/kfifo/bytestream-example.c +++ b/samples/kfifo/bytestream-example.c @@ -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 file_operations fifo_fops = { diff --git a/samples/kfifo/inttype-example.c b/samples/kfifo/inttype-example.c index 6cdeb72f83f1..7b4489e7a9a5 100644 --- a/samples/kfifo/inttype-example.c +++ b/samples/kfifo/inttype-example.c @@ -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 file_operations fifo_fops = { diff --git a/samples/kfifo/record-example.c b/samples/kfifo/record-example.c index 79ae8bb04120..eafe0838997d 100644 --- a/samples/kfifo/record-example.c +++ b/samples/kfifo/record-example.c @@ -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 file_operations fifo_fops = { -- 2.30.2