From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757700AbbJ2Qa7 (ORCPT ); Thu, 29 Oct 2015 12:30:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35437 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756132AbbJ2Qa5 (ORCPT ); Thu, 29 Oct 2015 12:30:57 -0400 From: Vitaly Kuznetsov To: Andrew Morton Cc: Rasmus Villemoes , Andy Shevchenko , Ulf Hansson , James Bottomley , Kees Cook , linux-kernel@vger.kernel.org Subject: [PATCH v3 2/4] lib/string_helpers.c: protect string_get_size() against blk_size=0 Date: Thu, 29 Oct 2015 17:30:48 +0100 Message-Id: <1446136250-11507-3-git-send-email-vkuznets@redhat.com> In-Reply-To: <1446136250-11507-1-git-send-email-vkuznets@redhat.com> References: <1446136250-11507-1-git-send-email-vkuznets@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Division by zero happens if blk_size=0 is supplied to string_get_size(). Add WARN_ON() and set size to 0 to report '0 B'. Signed-off-by: Vitaly Kuznetsov --- lib/string_helpers.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/string_helpers.c b/lib/string_helpers.c index f6c27dc..ff3575b 100644 --- a/lib/string_helpers.c +++ b/lib/string_helpers.c @@ -50,6 +50,11 @@ void string_get_size(u64 size, u32 blk_size, const enum string_size_units units, tmp[0] = '\0'; i = 0; + + /* Calling string_get_size() with blk_size=0 is wrong! */ + if (WARN_ON(!blk_size)) + size = 0; + if (!size) goto out; -- 2.4.3