From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751599AbbIKBWy (ORCPT ); Thu, 10 Sep 2015 21:22:54 -0400 Received: from mx2.parallels.com ([199.115.105.18]:56024 "EHLO mx2.parallels.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750786AbbIKBWx (ORCPT ); Thu, 10 Sep 2015 21:22:53 -0400 From: James Bottomley To: "vkuznets@redhat.com" 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() Thread-Topic: [PATCH] lib/string_helpers.c: fix infinite loop in string_get_size() Thread-Index: AQHQ5xElQ/AWGVePjEuqnLeWY03SE543B8SA Date: Fri, 11 Sep 2015 01:22:43 +0000 Message-ID: <1441934529.13610.4.camel@Odin.com> References: <1441371393-15030-1-git-send-email-vkuznets@redhat.com> In-Reply-To: <1441371393-15030-1-git-send-email-vkuznets@redhat.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: Evolution 3.12.11 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [151.124.179.37] Content-Type: text/plain; charset="utf-8" Content-ID: MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by mail.home.local id t8B1MxkX003363 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 ... it might be that I haven't looked at this long enough (I am on holiday). James > for (j = 0; sf_cap*10 < 1000; j++) > sf_cap *= 10; > {.n++%ݶw{.n+{G{ayʇڙ,jfhz_(階ݢj"mG?&~iOzv^m ?I