Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1328995pxu; Mon, 23 Nov 2020 18:45:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJzno/HaXkop8h8xKaIE9u4Kv6JBRVgOJJdtij6iRC9fIsmmIF1y7B5JycectKaWYcag4wWS X-Received: by 2002:a17:906:a186:: with SMTP id s6mr2390320ejy.193.1606185941266; Mon, 23 Nov 2020 18:45:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606185941; cv=none; d=google.com; s=arc-20160816; b=jy7Kfs+UeNG82o41flte3LNDGJeoUyWYJiwZzvb4SROrh9LxG3/hbLIM8h4FeoiZOb b5roWxaZMD58ML31In/GO4hrYPu0tFxpmdbLc+1NTZDQ9A+1IBRxuJcq/d1CJ6kAX2uV RJkfRKgG56a0A0Qv7TBR/Q3BhA8pGmNXC+NMdp5Q2AoJjnOmvp0rteH59YhbR5sIJ9Hu z818WvP77SHdUACcN2RcRsbvcozAjLSskIUQ4bjVfCmZ4eOW8ugVdc0I/W6C+G9QEtcq kkLTZJuD8zm438hVVFavrFeSuHbZGQ2lc06yTmrAZHhwOT0VSPUomnaWnc8oFH1Et0hk VK3A== 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=xVH/w27esbvRJmYzHZd61NLqVTDTLxcIOcb+6NSdeag=; b=mp8SEFvstneDIIvx+E/Y81o5qnHAfUtVZbHPEgi8s41XJ+l236oM34sBm5zqjQItcL MivTtzmrV72631lkz1n8WvxBbYWoE6VgAZrwi5mvGzPx5vmID9QeTdTVSI47HEWpxOlz plah2Jiqb+B4JAhXA5cBoKaEtkNsUQmh6qYeAESXjEIZLM9yczGNVc1umckH9TZtCqHB lUBXkWpZVpAtoDSJwdru2OZUFm5m06+QHV/NlTi3MaVSjLqDK9gxZM3aKCmzwf0Wd6S9 NLu6g5dXqGmQjKaRnL2K+nge1LUTwo+CDVZSf0/mB/0bdWUPZ7Z6VsVICBSRgYrljuHO 2ZGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=L3te3WzF; 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 qx1si7561168ejb.251.2020.11.23.18.45.18; Mon, 23 Nov 2020 18:45:41 -0800 (PST) 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=L3te3WzF; 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 S2388883AbgKWNVH (ORCPT + 99 others); Mon, 23 Nov 2020 08:21:07 -0500 Received: from mail.kernel.org ([198.145.29.99]:51194 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732121AbgKWMio (ORCPT ); Mon, 23 Nov 2020 07:38:44 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DC0F02076E; Mon, 23 Nov 2020 12:38:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606135123; bh=dgVuDh2GXuI7HQa+oO0rr1S4SG+f7PWa0Qrjleo+wu4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L3te3WzFtbZ9eZwFmlUJwcSHJM0hI5nWrt2K+0Qp0SeLwy/DclZAJt5c3fg3v9LxQ 46or8BEx62CjlGoy16Yib1rkBOixYKrBHHWcOjxvdXVom4pHMoVH+6hE/nLEk8xrYK 15f4VEtD3wL1pSpOPW97SmwXeV+F/mmYFOO+xMig= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yicong Yang , Andrew Morton , Al Viro , Linus Torvalds , Sasha Levin Subject: [PATCH 5.4 112/158] libfs: fix error cast of negative value in simple_attr_write() Date: Mon, 23 Nov 2020 13:22:20 +0100 Message-Id: <20201123121825.344489004@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201123121819.943135899@linuxfoundation.org> References: <20201123121819.943135899@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: Yicong Yang [ Upstream commit 488dac0c9237647e9b8f788b6a342595bfa40bda ] The attr->set() receive a value of u64, but simple_strtoll() is used for doing the conversion. It will lead to the error cast if user inputs a negative value. Use kstrtoull() instead of simple_strtoll() to convert a string got from the user to an unsigned value. The former will return '-EINVAL' if it gets a negetive value, but the latter can't handle the situation correctly. Make 'val' unsigned long long as what kstrtoull() takes, this will eliminate the compile warning on no 64-bit architectures. Fixes: f7b88631a897 ("fs/libfs.c: fix simple_attr_write() on 32bit machines") Signed-off-by: Yicong Yang Signed-off-by: Andrew Morton Cc: Al Viro Link: https://lkml.kernel.org/r/1605341356-11872-1-git-send-email-yangyicong@hisilicon.com Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- fs/libfs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index 5fd9cc0e2ac9e..247b58a68240a 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -887,7 +887,7 @@ ssize_t simple_attr_write(struct file *file, const char __user *buf, size_t len, loff_t *ppos) { struct simple_attr *attr; - u64 val; + unsigned long long val; size_t size; ssize_t ret; @@ -905,7 +905,9 @@ ssize_t simple_attr_write(struct file *file, const char __user *buf, goto out; attr->set_buf[size] = '\0'; - val = simple_strtoll(attr->set_buf, NULL, 0); + ret = kstrtoull(attr->set_buf, 0, &val); + if (ret) + goto out; ret = attr->set(attr->data, val); if (ret == 0) ret = len; /* on success, claim we got the whole input */ -- 2.27.0