Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp417985pxj; Thu, 20 May 2021 12:21:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySzzuOPmvcTCQhVME/GCnvwa90gyyj9oLCMhqBGsr1Wy/sh1q+uH8NuP9qK6rr1FdWVDKa X-Received: by 2002:a17:906:6c96:: with SMTP id s22mr6322869ejr.468.1621538464831; Thu, 20 May 2021 12:21:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621538464; cv=none; d=google.com; s=arc-20160816; b=vLo7O3dbxtGy5OQN5YHW32uS1SaH7Byx6bWDyJV/MqNk1NpclwJ4akV0wRE4cKbJfR e1IFu223BhqlufrvD/FG+0osA+YaQN/ZAHOfI8g+Jvy98dxRm1eOPST3mp1c4731uDx1 L/KWmvYxfjDh+BuNRLqPGM7bFI2445JHtvyIl+GJDSZBqY7EksockaA/o9oSl+XeOLYE ltEEqzPW9ycLZKudWUTWIJVo+uFfTeC4Sa2n4cCROEF2o6jLHXl/TANawG2rfOFYfIag cC+l5MiJ486xSZDhAnX25UB2F6AfmoaSt9YlUikxBT8opiQCfa5WIX9KGdirUYFzdlbU 6eLw== 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=h1HOZ8FItbTAjKTKIGcSx1x1qM8nysLypOJCAYIiXiFSm1MvoSyfTwVVHWSfd7Rr/O AK2yQ2vK9Ck1q2GbdMgnUfjWR/z7gLf77+4+dcFDnoNhbF3WmKrZfjK9fs/IVZbOYNU3 VGBDqvv7Yut25yRV/jfYyqpVXdEF1hmU6zM9THnzpsPLMxZiNZM1Xpza6XZyjhy7olHa 3SkmJSN+KFDW/L6OrEF7bkCGbSCQC1u/J7uuoU8tdvbHWRpPd1N0wm4yC5+bBNihG4L1 oBE4SzJjEiGEhHlbisAJP+DkEHGYaDKm4m7+iRUdWuNzPuRgbNHPYZKSDNs9LFPMxSw4 RoLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GfWdi7vD; 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 gb34si2976264ejc.697.2021.05.20.12.20.41; Thu, 20 May 2021 12:21:04 -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=GfWdi7vD; 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 S238829AbhETKuV (ORCPT + 99 others); Thu, 20 May 2021 06:50:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:33416 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237430AbhETKeY (ORCPT ); Thu, 20 May 2021 06:34:24 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D9A8E61C58; Thu, 20 May 2021 09:53:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504398; bh=/ZW8JwvHwnl77jWCkthAo3Vaac0GolRsZMMhyixU/f4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GfWdi7vDXrbJZvon4k71rJILPx2b/Q85NhzjKI33xzyvpKKfUfF0eky9aQDtOUdzL ETn4Xt8J65Q8fNz6t/itBXTU+jQaLqbHHxYuNmy7tUYBgKg4QWVAu6nJHqPIPl6Ro4 xoBgLlYOK5YRbZM5LoV8mOqgi+eQmws0eXIlaSzY= 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.14 227/323] kfifo: fix ternary sign extension bugs Date: Thu, 20 May 2021 11:21:59 +0200 Message-Id: <20210520092127.932801293@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092120.115153432@linuxfoundation.org> References: <20210520092120.115153432@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