Received: by 2002:a05:7412:d024:b0:f9:90c9:de9f with SMTP id bd36csp59877rdb; Wed, 20 Dec 2023 06:20:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IG2byaNQwJDZVBsJtjDk2arVw4gN7HPqhNhMX7w4qxyIhoFm2bLB99xJi2MqbtThp5xseAl X-Received: by 2002:a05:6808:318f:b0:3ba:a3d:e8b5 with SMTP id cd15-20020a056808318f00b003ba0a3de8b5mr14109381oib.105.1703082029647; Wed, 20 Dec 2023 06:20:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703082029; cv=none; d=google.com; s=arc-20160816; b=TKrtLxAbFuFJQhUIPo87DAC99bFIDKlMa+KPA8OLCR5+OxWSsbWkV6A8etArPM06JU TM6cMtUyrdsl9SdPkcUprTF+d7uUqxojEfuwLz1TwwicY2/d9R/+UWl/mRiXeTSv69Rr WvmhOBNkHuojVctN2/p6QD7LLfsf+yAc8eFtsqiQPCBhkAeMEFtPtLsDt/633HBzHPQZ Q6Py7P8VseL5t+I06v5Nqbssiug9z+UlNb+/KawhKBHlVYMN6v4dBJj0rZmS0ZcYJbHM HXDHpt9+K8y0kc4fX0099mj79J81Wm/R2Pn0G6vzapRTwGpPG83vYfs9haZcN9DdS4Xr 8lfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=organization:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :message-id:subject:cc:to:from:date:dkim-signature; bh=xyGaoHHc1GqLyKY4sVvPPpCx3zUr8CzQRa2QmgqetlM=; fh=/A3PDs/LrIjNuD7ZXZEg0I7OMedBKskRmy7PH6TjfEI=; b=z6mrZq0UfUQRLhcirEca202j8tOolI5sFQh50crFSbHvmQPr6cEX3VpLIx4RKwVHyH nuRcXqwvzzOhm3QovNyfiWJrIqvs3ecH4sY3xXZ4jMQDJhai93c+fN3CMLEK8NiuO6Cn tu1GpWuM5ng8jc1zpbtKJQifBxGbfA5dFiVZkSi9OBZDxPVrA7iwLjJk1QLXGFf+FrgT 8x5zKTLIm1aH6iBWa0awGrgVMPlqeIhxc8NotRswjD/j4NDbBiO+XtZqeFs2Gfe+E8k1 0F3tuQv++Ocn3q9W+k/ZiFGaMBJmnRYM2yi2Syn4DU+Igfya6NDO+ylyJrAIop0at4in Jb9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QwhmbAbI; spf=pass (google.com: domain of linux-kernel+bounces-7051-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7051-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id az2-20020a056130038200b007cb0fdcec1csi4437228uab.74.2023.12.20.06.20.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 06:20:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-7051-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QwhmbAbI; spf=pass (google.com: domain of linux-kernel+bounces-7051-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7051-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 5E7481C23561 for ; Wed, 20 Dec 2023 14:20:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3AFF83AC02; Wed, 20 Dec 2023 14:20:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="QwhmbAbI" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1881B38F9B; Wed, 20 Dec 2023 14:20:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1703082006; x=1734618006; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=Cpy14Hdv+G05egV79hbRzIYlL3cC/Rq5mKgn8sI00YE=; b=QwhmbAbIRUIcwyczkN35Nd7r8M3X10De/maDN40E75kkr7ER6ftXsx3o yGjdKY1sOK/j2oOuxT50ppqG2ebLz36dx9elwqscR++FWgf4RtDYoJb/s POuIQ3GbwOi8Y0YpiYtla26ae4N4ssOxaYw7J4EHNUSzUBNF946tsURCa +YAJ0xmQbY2JrFHWjfkH0GqqSYngoWTjLDLug0AAjrTQmdzMxnbRf/o+i lhLe/4pKM+X65CL79Uzi3EgMl65vI/a5QgNOGid2ml+vbdjkjkWCrVHhe cNNUYf6UcLHEABgD9PAm83ygo4tI6MTZILuSu6vdLSzBOerO8wyGDKXx2 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10930"; a="375309623" X-IronPort-AV: E=Sophos;i="6.04,291,1695711600"; d="scan'208";a="375309623" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Dec 2023 06:20:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10930"; a="866987960" X-IronPort-AV: E=Sophos;i="6.04,291,1695711600"; d="scan'208";a="866987960" Received: from smile.fi.intel.com ([10.237.72.54]) by FMSMGA003.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Dec 2023 06:20:04 -0800 Received: from andy by smile.fi.intel.com with local (Exim 4.97) (envelope-from ) id 1rFxNz-00000007YVJ-2dru; Wed, 20 Dec 2023 16:17:23 +0200 Date: Wed, 20 Dec 2023 16:17:23 +0200 From: Andy Shevchenko To: Qu Wenruo Cc: linux-btrfs@vger.kernel.org, Andrew Morton , Christophe JAILLET , David Laight , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/2] lib/strtox: introduce kstrtoull_suffix() helper Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo On Wed, Dec 20, 2023 at 10:40:00AM +1030, Qu Wenruo wrote: > Just as mentioned in the comment of memparse(), the simple_stroull() > usage can lead to overflow all by itself. > > Furthermore, the suffix calculation is also super overflow prone because > that some suffix like "E" itself would eat 60bits, leaving only 4 bits > available. > > And that suffix "E" can also lead to confusion since it's using the same > char of hex Ox'E'. > > One simple example to expose all the problem is to use memparse() on > "25E". > The correct value should be 28823037615171174400, but the suffix E makes > it super simple to overflow, resulting the incorrect value > 10376293541461622784 (9E). > > So here we introduce a new helper to address the problem, > kstrtoull_suffix(): > > - Enhance _kstrtoull() > This allow _kstrtoull() to return even if it hits an invalid char, as > long as the optional parameter @retptr is provided. > > If @retptr is provided, _kstrtoull() would try its best to parse the > valid part, and leave the remaining to be handled by the caller. > > If @retptr is not provided, the behavior is not altered. > > - New kstrtoull_suffix() helper > This new helper utilize the new @retptr capability of _kstrtoull(), > and provides 2 new ability: > > * Allow certain suffixes to be chosen > The recommended suffix list is "KMGTP" (using the new unit_suffix > enum as a bitmap), excluding the overflow prone "E". > Undermost cases there is really no need to use "E" suffix anyway. > And for those who really need that exabytes suffix, they can enable > that suffix pretty easily. > > * Add overflow checks for the suffixes > If the original number string is fine, but with the extra left > shift overflow happens, then -EOVERFLOW is returned. NAK. Read the v1 discussion why. -- With Best Regards, Andy Shevchenko