Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4634978pxj; Wed, 12 May 2021 09:43:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwj8gPQ/qJMgbyvMrmQy9ytwJme7LK4scPmGP0LIvQi5YOC09qLs0AthUWuZQMBT/AxSpgv X-Received: by 2002:a17:906:a18e:: with SMTP id s14mr36467982ejy.311.1620837795466; Wed, 12 May 2021 09:43:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620837795; cv=none; d=google.com; s=arc-20160816; b=A7INo6MoOY1CjE3hcCzG45/WtctMCIQXucItF5LZ0csgoiQcyaQdIHuv7niXxg028f vG2FnHnBIe/0U+LVTS6y2L+IyNC/4XA7xiV+pelOsZ5XMzP5lo/1d5rb77lmZRNGIytO dyJfW65PMh5C7+JLdFjUzUfJM8y7NvUQnf27lyzFzNS6YidW8chJJBRo27R4BIBVXBIO nKtamqv3BnLXjE4p5FyK5tW3V8MOjKRnk4EmBlLXEhOrXS6B35jtWL8XLG4vEDtEJw8N D1zcfGa/jk37BteBjwB6sA01KxF3DCBNvykIxW9eCdGBDTuDYHDGI63+MqcxyksrS4jO XP2w== 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=kopUyT6nEhdt7PzUBytQSM7ZdvB1Ydf6V9+If2Aycti10wBeew+TWva1HOZNCF4yXu U6OgAd6FB8uUeCkcxYoMdWz8EhjcIH+/jzMrBk9XvzGe+iYDBvBaYmfr7j9xtCCS3ZY1 C2f8wWmuD6iFA0MYiPwY27OSGdWI2lNjly8hlZncHLF7+vNErsDAzQZMMcQMtyHVUTqy Q6t8IR5ZwvujL0vcyV/hx0jMW98GDV+YUDzr7qHZoQ1IJ4MossCCqlgFFlFtH35SbNPQ h0sfucQqEMItj73mcZHOt0Fau3Pbumii6FtWUDBs3E0qFAE79ote8VHaWKbnCn/Og9I3 jnNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cgUO6IlL; 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 e21si13510eds.204.2021.05.12.09.42.51; Wed, 12 May 2021 09:43:15 -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=cgUO6IlL; 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 S243340AbhELQka (ORCPT + 99 others); Wed, 12 May 2021 12:40:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:41730 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236898AbhELPrM (ORCPT ); Wed, 12 May 2021 11:47:12 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1580D61C9E; Wed, 12 May 2021 15:23:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620833036; bh=42TrdJ6vRDRiwh71ldf9/z4htKYkP4JsmoC3QXfPeEU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cgUO6IlLHts0Rpnf2np3SUW9RFVquY25myRgR0qF6j7hYZoYYy1TYZ98XgJBcnZQj ikpTqm8MnUGTPn4Jv/ztDA7sTSycTU8cyZiQsm9RprKGXhrhDLhQnJv01ng50PSjtJ tXA9zXetxICs/uj/80WhN3B6UGQ45cpyWgYUKZY8= 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.10 516/530] kfifo: fix ternary sign extension bugs Date: Wed, 12 May 2021 16:50:26 +0200 Message-Id: <20210512144836.715179107@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@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