Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1020923pxb; Fri, 13 Nov 2020 02:00:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJzH3flfnYya5FZCFHcgLpIJiJ8oXB/NHxqdjcO/ADY48Ub4sn/8Xh3J5DD9mopYlNbpuy6B X-Received: by 2002:a17:906:d8b0:: with SMTP id qc16mr1123522ejb.268.1605261608114; Fri, 13 Nov 2020 02:00:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605261608; cv=none; d=google.com; s=arc-20160816; b=u7TC3oTfoAPs04arlPJIFPx2xVRoNc+o+NwlWCsguofYjM/shTODnYWwZrGgbAkJhR mC5ffzhkb/afGMlY8joiHFXCX4VbCMj4iDpu74FfJKPvrhKmFzwst8COY32ETKqngRN5 b7qdjE/8gNCKISrQ6M8QKjlfIxAjjjmbCLPQv6YDiU0fvNO3xAzMJtijHT3L4+7LSWTY +2Q7hjuTc4iGd9mrAbtT3OAZJ0yKKZ4C9fA5J0uYHW858FzhufGsa92xYeeC6lYcErBv lh/HfinY0KgrUYW0ruYppF5rmURzPGo4xpXKwgIF9vADSRYWPEAuv5W+nkEMONq8IaI8 m35w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=6k/YjzIjqcox9DmCsgqbvi2YSbQI2pZs86pQmgrWJDY=; b=DZiBAkPDoTtkTpR7rrFvuSWd25uF15RUd3jvKOStyufihuLwNcSTkxHA8HgWbFynyY vOzfazZ+G7WSCV1zSHqYtT1ia5eRu7wEzJeNoJeRDPjsyvxbLkeGHlP21Lr3sl2TVlgd 4Nx2kae6LfGSILRtM/rrw7A+JZZPMNPQ76KOieQVf6MNxrL2DsrO2bZH04BR9oCaM/fB 9W7C8MR+i6riiDm3nixH+eNU0WQ3PjMAwuOKuf/7mE//ToXaMiYzIjOwrkSbQvfM4y0Z AeLaRg3fkP3t8a2pJLUrmgdiY0TTJjg/lYWDoVJS09NKc8W9LFi13e14N2Df2uO7bLel nMiQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u14si6116730edq.494.2020.11.13.01.59.42; Fri, 13 Nov 2020 02:00:08 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726267AbgKMJ5v (ORCPT + 99 others); Fri, 13 Nov 2020 04:57:51 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:8081 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726176AbgKMJ5v (ORCPT ); Fri, 13 Nov 2020 04:57:51 -0500 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CXYmZ04sBzLt9q; Fri, 13 Nov 2020 17:57:34 +0800 (CST) Received: from localhost.localdomain (10.67.165.24) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.487.0; Fri, 13 Nov 2020 17:57:42 +0800 From: Yicong Yang To: , , CC: , , , , Subject: [PATCH v2] libfs: fix error cast of negative value in simple_attr_write() Date: Fri, 13 Nov 2020 17:56:09 +0800 Message-ID: <1605261369-551-1-git-send-email-yangyicong@hisilicon.com> X-Mailer: git-send-email 2.8.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.165.24] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Fixes: f7b88631a897 ("fs/libfs.c: fix simple_attr_write() on 32bit machines") Signed-off-by: Yicong Yang --- Change since v1: - address the compile warning for non-64 bit platform fs/libfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/libfs.c b/fs/libfs.c index fc34361..3a0d99c 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -977,7 +977,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, (unsigned long long *)&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.8.1