Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp956557pxk; Fri, 25 Sep 2020 02:20:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydTL02c7PGdi4N0WtoEobvYTQM924rO/UgPvRr7rSD2mkGPL+rPl259M/MMSzLKPRDQWxp X-Received: by 2002:a17:906:4685:: with SMTP id a5mr1757300ejr.446.1601025609359; Fri, 25 Sep 2020 02:20:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601025609; cv=none; d=google.com; s=arc-20160816; b=cEQuiQ0vGCpKpfJ+Rm/+6usPXKXF1EhRBMgT3azpve4RZZc4E3bw1LkPJNqBfyDeVI OArFIfAswl+wxK0IY7EIoZoZZGCvY20hm4h7wwhJaJYgT/+e6c01aIjMdjSAownLi3X9 hiFInljLWjgGmN304lwxJMGL+EokCVqtHHF51i8BcwKcSqKAYFMfNz63kooCKZ4nGJOF B0v44P24eqth/vtmpawn0ICTOuUF9QfDwz8cyFVXTXjRMp7DyQIBlCoiKa0eD11zRpnq nWTBmLydqyRR7nEen2CO+BKThOMA7yhiP2e8K+19li95EndxkqH5VXhvqR7W2GMAr/mj jkCQ== 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=XiPINMDDoIa5Wlq7K76xxA053+l41YkTyHqqJWla/Do=; b=dZh+39/LLIXa10JQx2BLX+prASxhjC8OrTGzshWwhjyif0s9z77JRnCn3H2PjDhHQ3 mKTU5y20KF95mEfTn77TZcUJFpazg+5XyIDPzhvd5ouIWnwcxubqnEzTpnk6CzuF9NTZ +glXBoMHs/UiyBJvNHFaRO1dM4y+0K0B3CebRkZDj2en05k3voPBXrQD580i5Ffrzcx4 rMMDqd24KEZyRm0kbPl+0scF8HA9XOBdWXvamnmGfMyffq+N4U7Pxb+dEVsniUILR0hn 35lXpQ1MJjfe4uTwuxIdufI7W9XTI/m9FcgAlCMB4EnepbnA/HyJYHWyLrgO8Y8mG44r c9tw== 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 cb11si1374084edb.361.2020.09.25.02.19.45; Fri, 25 Sep 2020 02:20:09 -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; 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 S1727763AbgIYJQc (ORCPT + 99 others); Fri, 25 Sep 2020 05:16:32 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:14281 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726990AbgIYJQc (ORCPT ); Fri, 25 Sep 2020 05:16:32 -0400 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id C67FD8637E0A273CBC53; Fri, 25 Sep 2020 17:16:28 +0800 (CST) Received: from localhost.localdomain (10.67.165.24) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.487.0; Fri, 25 Sep 2020 17:16:21 +0800 From: Yicong Yang To: , , CC: , , , Subject: [PATCH] libfs: fix error cast of negative value in simple_attr_write() Date: Fri, 25 Sep 2020 17:15:08 +0800 Message-ID: <1601025308-28704-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 we use simple_strtoll() for doing the conversion. It will lead to the error cast if user inputs a negative value. Use kstrtoull() instead to resolve this issue, -EINVAL will be returned if a negative value is input. Fixes: f7b88631a897 ("fs/libfs.c: fix simple_attr_write() on 32bit machines") Signed-off-by: Yicong Yang --- fs/libfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/libfs.c b/fs/libfs.c index e0d42e9..803c439 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -975,7 +975,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.8.1