From patchwork Sun Nov 22 06:17:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 11923777 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71F68C6379D for ; Sun, 22 Nov 2020 06:17:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 20FCA208D5 for ; Sun, 22 Nov 2020 06:17:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="YcGUnQou" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 20FCA208D5 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B49F66B0078; Sun, 22 Nov 2020 01:17:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AD66E6B007B; Sun, 22 Nov 2020 01:17:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 973DC6B007D; Sun, 22 Nov 2020 01:17:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0210.hostedemail.com [216.40.44.210]) by kanga.kvack.org (Postfix) with ESMTP id 644EE6B0078 for ; Sun, 22 Nov 2020 01:17:21 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 083F9180ACEEB for ; Sun, 22 Nov 2020 06:17:21 +0000 (UTC) X-FDA: 77511047082.14.hate83_0f138882735a Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin14.hostedemail.com (Postfix) with ESMTP id DEFFB1822987A for ; Sun, 22 Nov 2020 06:17:20 +0000 (UTC) X-HE-Tag: hate83_0f138882735a X-Filterd-Recvd-Size: 3070 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf31.hostedemail.com (Postfix) with ESMTP for ; Sun, 22 Nov 2020 06:17:20 +0000 (UTC) Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (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 6A7E120885; Sun, 22 Nov 2020 06:17:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1606025839; bh=/2Crv0yoiGPOCLVKKOZFGvlgsyX0gwPsx26XT6y4Hic=; h=Date:From:To:Subject:In-Reply-To:From; b=YcGUnQouy7cmjuVazzFinG4TubZQzc6mgE9014ANI+Of0Wzyf2V1rIVgZM64BropQ emsoNSDV1Mc+8webiTxV/YzxwhXOs90vCz4xScg1y7HC11cWADZd7kZtf3OjSrmuiL umyGQwpqdqLc8Mhmvbkepf0mbOSh/gmVkTr/8zKY= Date: Sat, 21 Nov 2020 22:17:19 -0800 From: Andrew Morton To: akpm@linux-foundation.org, linux-mm@kvack.org, mm-commits@vger.kernel.org, torvalds@linux-foundation.org, viro@zeniv.linux.org.uk, yangyicong@hisilicon.com Subject: [patch 7/8] libfs: fix error cast of negative value in simple_attr_write() Message-ID: <20201122061719.7voMbHRfP%akpm@linux-foundation.org> In-Reply-To: <20201121221631.948ae4655e913a319d61700a@linux-foundation.org> User-Agent: s-nail v14.8.16 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Yicong Yang Subject: libfs: fix error cast of negative value in simple_attr_write() 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. Link: https://lkml.kernel.org/r/1605341356-11872-1-git-send-email-yangyicong@hisilicon.com Fixes: f7b88631a897 ("fs/libfs.c: fix simple_attr_write() on 32bit machines") Signed-off-by: Yicong Yang Cc: Al Viro Signed-off-by: Andrew Morton --- fs/libfs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/fs/libfs.c~libfs-fix-error-cast-of-negative-value-in-simple_attr_write +++ a/fs/libfs.c @@ -959,7 +959,7 @@ ssize_t simple_attr_write(struct file *f size_t len, loff_t *ppos) { struct simple_attr *attr; - u64 val; + unsigned long long val; size_t size; ssize_t ret; @@ -977,7 +977,9 @@ ssize_t simple_attr_write(struct file *f 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 */