Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp557185pxj; Thu, 20 May 2021 16:10:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz9u006BkTDHMYumWSfSkEQgspCVciCaYYjeiExenWj2BPe+CCKRiTiJLiyqqXOjcHj9ngz X-Received: by 2002:a17:906:a20b:: with SMTP id r11mr7137635ejy.323.1621552202677; Thu, 20 May 2021 16:10:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621552202; cv=none; d=google.com; s=arc-20160816; b=AxhPc210H+XmvVsTJs15tNj/IgYVvpHDA3R/zqmm9q3PBxS6ynVfbosWo9Uss6Ml4C hExhNeW13e/LUFtBSskoX55GFTPe+cjzoKq9EvAN4iMvMhD71l2v0LzKqijJZRvP8Iy4 wjxn3PclzKmBFyNlEzLu4vjMNjQykubf2Zz+sSW2C0kdsPFMsboGqwC6Jca/H/RRlHr0 7VSeK+/6vpUxFNl44rWL2NeUiMWJ8ij3IjMAo59/HPV7X0ajmN7YIQkeqUiu/6hBTDv5 qoWVpjsnq4oBKHbjyFJ9JLZFudJTjSo5yVniKH5dWHJ9BAFGgjwZBvHFkwnf310CGqLz 7fhg== 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=sW/Rm9ENVjGHvbixW8WyjEH/jKkO4vdLui4cCU8Pxyz1Ip/2439xpmtAJsFubwAE4E s9nxBM8KQmW5y42rr8CxRUdFUD30jaVw24dLFYujXwFAStN1BlobcZY8M4cmCfEmKFiz tYchigQiK0AMb38Hhry9w4CuiD/2LIQJkFo8XqRLqxNGaIDX3ed5/KgpFrDjf2LuYPoO XeqLnt2zHzDX9r3eN4pvgQKmcRtcQpDJXKbst5wFPpNKvwEPo3/Mfse4RrwTOvGG9ywh 166m0cBDCrosnuow4EB3P06L7oWrAUDhUBj8LP+6jaEx0ldijC5JFP3Vahw0Lfc10Ohp uUGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ziGdYPqU; 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 h11si3690833ede.61.2021.05.20.16.09.29; Thu, 20 May 2021 16:10:02 -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=ziGdYPqU; 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 S240889AbhETLTg (ORCPT + 99 others); Thu, 20 May 2021 07:19:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:56262 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239357AbhETK7G (ORCPT ); Thu, 20 May 2021 06:59:06 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C2D2561D01; Thu, 20 May 2021 10:02:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504974; bh=/ZW8JwvHwnl77jWCkthAo3Vaac0GolRsZMMhyixU/f4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ziGdYPqUe/eBrObgGZ3T7B0PT388nwa+605icYvqqj1k/gAT7OGYFHzFAxPBqjOZg GDEHaieCr1neNOvhIgcMKtkZzAK+xqvRi3iEyhVOU2vPcbwnuhtiYXyu6V0fyQXayq JRptOxKF8UqJUlpZku3AEFuAD6Qa1W8n1vQY0yD0= 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.9 165/240] kfifo: fix ternary sign extension bugs Date: Thu, 20 May 2021 11:22:37 +0200 Message-Id: <20210520092114.188530857@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092108.587553970@linuxfoundation.org> References: <20210520092108.587553970@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