Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4697795pxj; Wed, 12 May 2021 11:08:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9Yak6KLt/NbBOKd0WeyBGXpoyLJTiQeWhNOnzQKMahanp0vCxEkbbkGfq7k8xmGxCqzfM X-Received: by 2002:a17:906:80cd:: with SMTP id a13mr38714282ejx.109.1620842883676; Wed, 12 May 2021 11:08:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620842883; cv=none; d=google.com; s=arc-20160816; b=gc3zn5hCrjube072NGm8Yv1tkK1+iNky+k95GVcfsz/cPNbyDCU/BumjYXT8Esk0/Z kjPo7TngAx12NitixjgIf5MrbjjliJlf7ZyVmRvzV0huKt9YqowMelXZkQJeaNL5JzNl LC6Ci3K8nlj0w+3gUj02eoUBICfJOhf6v1+dSgEPHGIDUzcw1WRwc7x+0c/7AylAKZLq Ch7qs1iR/tD6zw3LRR/Pf4ggEMSnYgpwawGA5XBFgBpvWZERmIZF2YNrs4mwPl5U025X oOkvYQqnpYLEOE3xfgnG/MsC9yyJ7opKVYf9ZHGKh1gKjmeaS4CtH9kJab74hxpatFYt USSw== 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=WepPzuJWDa4O+Z1wahKDlYVgpSnwd9U14gTCkBSeA7/+aRco/ruHTe1grWp+wvG4jk DKSh0+4SnZXob9RkhHf8/rCPcOvAUBM3q8Ge4BWCzl6f/vS9aeHgSG9p3t9TS2ZqVvEq Cgmh942BN+jGLSKwpW/+/cWpL1eYnIBk5Y/2djlUqoRm9X9nbnUErH1FG72QKN7iuOr/ ZuNJC66s2wavnhOAt1ihisrZUMRBxg99pnn/9dCO5g2x66kefL+3MOGef1rXpzFGjV2z 1M6CixEH52DzTIXTYa7Jp4pb2DFixoV2wNB701tjhUMKNxGrkmeUhvC5zHoxHDaGVTFj tN0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="ZjVO5mM/"; 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 o15si56777edc.604.2021.05.12.11.07.39; Wed, 12 May 2021 11:08: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="ZjVO5mM/"; 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 S1349978AbhELSAQ (ORCPT + 99 others); Wed, 12 May 2021 14:00:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:41044 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241009AbhELQ0N (ORCPT ); Wed, 12 May 2021 12:26:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2CCE1619BF; Wed, 12 May 2021 15:49:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620834549; bh=42TrdJ6vRDRiwh71ldf9/z4htKYkP4JsmoC3QXfPeEU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZjVO5mM/ftn92dny+7eTk1BnwWZ6YScYTWYa/U7t99m1EywoOEZnasB9l1LvttMdY rE4dcHv6tFjbyFCiGZcPpRrlmJe8hy8TtZyiEuODLlQtxFppdCXEEZsdE7JVN06R4p 1wkkLH1FkMWqDp2qpbgC6v2pxKnRhLtnN/UgM8zI= 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.11 588/601] kfifo: fix ternary sign extension bugs Date: Wed, 12 May 2021 16:51:05 +0200 Message-Id: <20210512144847.211878240@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144827.811958675@linuxfoundation.org> References: <20210512144827.811958675@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