Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp238971pxb; Wed, 11 Nov 2020 02:22:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJywQS0eefjjhiYQKeiFBYPx67yjqc3ue5hGv6BxtlU4IIAyBHR86/6odwMb/acxMh5YAjGx X-Received: by 2002:a05:6402:16ca:: with SMTP id r10mr4320467edx.380.1605090162013; Wed, 11 Nov 2020 02:22:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605090162; cv=none; d=google.com; s=arc-20160816; b=OlbHjKyQWmILhbkID74re4lQob+kaAj0ub6qrIB4SGZyUMwkqQXCfOV24giJIdHVDP g2WrgRqg9cqxgcqpOPK6z03BGz98pY0Bnd5l5GlregR532hhTsuk8di93TCO37Yuk2Ok FHWcAJ0qumN1HS+Vw6X4m8vGh/w7o1vrmLhPANmzKo9UzPUQj0R9gvRZh+JHVeftCu9O EYvlymfraNo/JoSXuNahqpGRtPj3yu1z58iAoV2Fgm4e3He08+v6Wl592aK2K5yUy9Gf IRTBUfsWggI4MzjOrOG71Z1XEdsBnt7qrvvq3BBHmMziBtSqd3AGkqL9TNYjG2JPFTg5 a+0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject; bh=HDhO8YGTwvunN980LzpE1XmQNWL56kRcLkxcDWAPsJk=; b=d6qhTkXozQknZ6H2mxKEOQN3U/APMnjuQstOj5nZehnxW0Z7VBElZMM3QFrMieqUVe s0oOlSTU4KOLwAn9joLUPbPukresnG/ekmzN6/EhvdqOIbbTz4Oie72X9V6/KINALZmJ whOi5ikY5kSFMEuEX63yJoSdMycDPHmvKGk4+LZ1L6s9LWy8yC3z7fYvQKqRpFAMNdgH S/yf5qldFI6Lms+sx/KCM3U4Oymd0+ZNySag8AjM+sm5lUMJpnJpHoDW1zmBT0SU3cI3 00LQOVRZNRSzB1D/i5HbLlHwHilHiTe/mIPDIIioSz7FH6oLYsOWPOlh5HltzAkkQYtU BYCg== 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 t12si1611315edc.181.2020.11.11.02.22.17; Wed, 11 Nov 2020 02:22:42 -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 S1727287AbgKKKSk (ORCPT + 99 others); Wed, 11 Nov 2020 05:18:40 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:7881 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726557AbgKKKSj (ORCPT ); Wed, 11 Nov 2020 05:18:39 -0500 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4CWLKc4TR8z6xQ3; Wed, 11 Nov 2020 18:18:28 +0800 (CST) Received: from [10.65.58.147] (10.65.58.147) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.487.0; Wed, 11 Nov 2020 18:18:28 +0800 Subject: Re: [RESEND PATCH] libfs: fix error cast of negative value in simple_attr_write() To: Andrew Morton References: <1605000324-7428-1-git-send-email-yangyicong@hisilicon.com> <20201110111842.1bc76e9def94279d4453ff67@linux-foundation.org> CC: , , , , , From: Yicong Yang Message-ID: <0b3954a4-1ac9-c454-a0ea-1fa1be5975b8@hisilicon.com> Date: Wed, 11 Nov 2020 18:18:31 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 MIME-Version: 1.0 In-Reply-To: <20201110111842.1bc76e9def94279d4453ff67@linux-foundation.org> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.65.58.147] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Thanks for reviewing this. On 2020/11/11 3:18, Andrew Morton wrote: > On Tue, 10 Nov 2020 17:25:24 +0800 Yicong Yang wrote: > >> 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. >> >> ... >> >> --- 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, &val); >> + if (ret) >> + goto out; >> ret = attr->set(attr->data, val); >> if (ret == 0) >> ret = len; /* on success, claim we got the whole input */ > kstrtoull() takes an `unsigned long long *', but `val' is a u64. > > I think this probably works OK on all architectures (ie, no 64-bit > architectures are using `unsigned long' for u64). But perhaps `val' > should have type `unsigned long long'? the attr->set() takes 'val' as u64, so maybe we can stay it unchanged here if it works well. Thanks, Yicong > . >