Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4752883pxj; Wed, 12 May 2021 12:26:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQj1rmY+vN43RYL7RKrSzOG5+hEgZisbBHcuWFqeU/p+kjG0vAEial91tfcQpEnkqYM7UM X-Received: by 2002:a17:906:cf82:: with SMTP id um2mr39254199ejb.322.1620847456947; Wed, 12 May 2021 12:24:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620847456; cv=none; d=google.com; s=arc-20160816; b=esObj7WXDSs4wk6F7uYHjOrp72sSOENAahXLjiNYoHPxuqp30exAWcHLqXNkMp4I4e 1rxf6tJkgnQosSMEmvkVO0tmuVTZxDj/Ikanu52EfEWvsixmcpY7TRzPfgB73X7R9aB9 GU4PL/+VZMwL42elkSQpWjcQoB5ZXAI3Qjop3aeYo+nvOn51aaaUmT/enxlP6tY2GDRY YW0e75BoZi+ZiTLF9Jf7/6sX82YSbegF6yWQbgx9Rh6DMdVV+oqjmSyH9n3US3HLSKgU HnelRYPAHewEWqM4DLz5j2jiq3dVlSQ00Tlm9fBmXygPmHWYxXCS99WPxqRrHmOHjSeo vlRA== 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=3YYnzeuQ47LUDdc0ltHzJUPOTrmQ/v4K40ovjNAyvnY=; b=pEHQZdIFnlSsAEcA1n7Zu9lHO0bPZ4yRIuWM0RJMEDNpwcv7qt4zEGaKacvxKCZFJr vBxlpFWeDbwQm/Za+jBuCTwUOGlVRfItkY4jq5LhX8/k0Udm7IqgFSO+nEoapwVGu6rt 38IiktIA0hQlOgEFAZ77yn+/9xVXf10lsT/NaErPzPgCzCUv8jlnd+Rp0ZB4nbFdK1gL T4s/we2+GTXFsqddC3MXIVOqT4coTQge6WPlCH1XFnbgtRTo1Bv93oUSJ313HBfyv5su WbD3ES9FVvPp3JrwKc4YJGYTkueR5Ky/XZV+E+2sA5qlL4Z1aJ936eVdcv/kub5Lkyi5 3lZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xP4In9n2; 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 d21si697647ejm.343.2021.05.12.12.23.53; Wed, 12 May 2021 12:24:16 -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=xP4In9n2; 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 S1379612AbhELTUD (ORCPT + 99 others); Wed, 12 May 2021 15:20:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:46628 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244641AbhELQu5 (ORCPT ); Wed, 12 May 2021 12:50:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 35E6161C84; Wed, 12 May 2021 16:17:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620836236; bh=42TrdJ6vRDRiwh71ldf9/z4htKYkP4JsmoC3QXfPeEU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xP4In9n2LJMERsxLy1/+kgdtV37ygV3v8mG4JSxf8HzY6O5ETCqTTtU4AkiKobG55 SAMXGo6CIpUZBy48lu+qkQf5qw14k456k36c/Upi3y+gCYxJkedWYjI+IX8vffdAPn 7Pe8N3RBRDUB+wZIkreGes+xID+sa7s/EJDaLADI= 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.12 665/677] kfifo: fix ternary sign extension bugs Date: Wed, 12 May 2021 16:51:51 +0200 Message-Id: <20210512144859.463085398@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144837.204217980@linuxfoundation.org> References: <20210512144837.204217980@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 c406f03ee551..5a90aa527877 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 proc_ops fifo_proc_ops = { diff --git a/samples/kfifo/inttype-example.c b/samples/kfifo/inttype-example.c index 78977fc4a23f..e5403d8c971a 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 proc_ops fifo_proc_ops = { diff --git a/samples/kfifo/record-example.c b/samples/kfifo/record-example.c index c507998a2617..f64f3d62d6c2 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 proc_ops fifo_proc_ops = { -- 2.30.2