From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754788AbbINJTa (ORCPT ); Mon, 14 Sep 2015 05:19:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43873 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753603AbbINJT3 (ORCPT ); Mon, 14 Sep 2015 05:19:29 -0400 From: Vitaly Kuznetsov To: James Bottomley Cc: "linux\@rasmusvillemoes.dk" , "andriy.shevchenko\@linux.intel.com" , "linux-kernel\@vger.kernel.org" , "akpm\@linux-foundation.org" , "kys\@microsoft.com" Subject: Re: [PATCH] lib/string_helpers.c: fix infinite loop in string_get_size() References: <1441371393-15030-1-git-send-email-vkuznets@redhat.com> <1441934529.13610.4.camel@Odin.com> Date: Mon, 14 Sep 2015 11:19:26 +0200 In-Reply-To: <1441934529.13610.4.camel@Odin.com> (James Bottomley's message of "Fri, 11 Sep 2015 01:22:43 +0000") Message-ID: <878u891hpd.fsf@vitty.brq.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org James Bottomley writes: > On Fri, 2015-09-04 at 14:56 +0200, Vitaly Kuznetsov wrote: >> string_get_size(1, 512, 0, ..., ...) call results in an infinite loop. The >> problem is that if size == 0 when we start calculating sf_cap this loop >> will never end. >> >> The caller causing the issue is sd_read_capacity(), the problem was noticed >> on Hyper-V. >> >> Signed-off-by: Vitaly Kuznetsov >> --- >> lib/string_helpers.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/lib/string_helpers.c b/lib/string_helpers.c >> index c98ae81..a155c7b 100644 >> --- a/lib/string_helpers.c >> +++ b/lib/string_helpers.c >> @@ -76,7 +76,7 @@ void string_get_size(u64 size, u64 blk_size, const enum string_size_units units, >> i++; >> } >> >> - sf_cap = size; >> + sf_cap = size ? size : 1; > > If size can become zero after the scale adjustment, then there's a fault > in the algorithm, and this probably isn't the right fix. However, I did > a brief calculation, and I can't see how size becomes zero ... ... but it does ... > it might be that I haven't looked at this long enough (I am on holiday). The function itself looks over complicated to me but you're probably right and I'll try to find the root cause of the issue in the algorythm. Thanks, > > James > >> for (j = 0; sf_cap*10 < 1000; j++) >> sf_cap *= 10; >> -- Vitaly