Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1237561pxu; Mon, 23 Nov 2020 15:35:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJwF0f7gAJgJPzpp2VOJZz+8K/p0AZjzdy4auaOhkr5AFuO4oeqxQJLakOPqu9daD9Z+BHAD X-Received: by 2002:aa7:d6c2:: with SMTP id x2mr1504521edr.206.1606174521764; Mon, 23 Nov 2020 15:35:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606174521; cv=none; d=google.com; s=arc-20160816; b=DLMzd/zkcs7SoVG+dVtsSKXTWnLCzfrBeCskJDAGL1sPWbmI/mEfzZuz4jfwQMJtlL 4ysilzj3fpJfsEenKyX6/op4PhVetxTa2lf1rTM0d5bcMRGYcHHC/Huo78gHV3iXw94x LvDfT3XduwkbImJvrMpGOVjBdcXyd2t9p1Nwyfhu1GtIksHv3HL2ZMBSpfcWdYbdF9q8 AwijMWft9/I/c9yf0i0IC4adbfUIFhNWZqZcImfLQjgV5+pF99gnAsZXnGFg110CPcka FYSQZt+7jHSj6tDJ+n7Z3RkQSzKBqrXJ2haS5tztNHVozJwXllXynkicllM2O9F4VqHU hh0A== 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=Q5W39TjTkqUN71U3skfRR89sxc9dJ/OS0G/UCnbRMgY=; b=fnB3/FaZrL9z2GoKveYI0uyxnRrC0znRC2R1azlPI5wmN2fyoQkpEzrURHUKCxcjt8 gDWxOS0B8ArfIMZo5xw9t5wokpFMZeQ6ii6euU8BTqGvfDq1P6Xa48NH0O6nT4Wwz1yD gFQ9EOtbZX6RHY6XYx1nx03vK/5JQ02BQMpAGBtjztN17zj6IA0X7MbLpclhKDEka968 YSMJ/jVmKOCZ4PZVL1I10DY4eYGNT86AfCEdODJJNwhxfCxAmofx+eymXvJCU3MbrkJ0 SDcFCaiyHxghL8MgN591fRIcCFFwDqXEwo72WA5l346ZxpBjY1G8noUnUC095Yb1aRj9 HXaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SCc+ZHMb; 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 qk7si6360343ejb.600.2020.11.23.15.34.59; Mon, 23 Nov 2020 15:35:21 -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=SCc+ZHMb; 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 S1731129AbgKWMcr (ORCPT + 99 others); Mon, 23 Nov 2020 07:32:47 -0500 Received: from mail.kernel.org ([198.145.29.99]:43774 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730996AbgKWMcZ (ORCPT ); Mon, 23 Nov 2020 07:32:25 -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 D4F9A21534; Mon, 23 Nov 2020 12:32:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606134744; bh=xj65otxT7u7gMA4A125Id7Rf9hy682WQH4WdP7oOkVU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SCc+ZHMb/Uml0CE3cajlOTw4PmHyvms1dOP6frureF71BnMRUuoL4LV6rBwlwniGk cmnqaWqmPPY+WeorkChqlj+HSn+iBzB2wRjKEshW1GZ+5/n0m6oqpmN8rZIeISa19y eMFxNfrsC3ahJ43zXOCl7kGoh3z4OT3r5ZnRxxv0= 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 4.19 65/91] libfs: fix error cast of negative value in simple_attr_write() Date: Mon, 23 Nov 2020 13:22:25 +0100 Message-Id: <20201123121812.480471445@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201123121809.285416732@linuxfoundation.org> References: <20201123121809.285416732@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 02158618f4c99..be57e64834e5a 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -868,7 +868,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; @@ -886,7 +886,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