From mboxrd@z Thu Jan 1 00:00:00 1970 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=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 9147EC76192 for ; Thu, 18 Jul 2019 03:11:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 64B6E2053B for ; Thu, 18 Jul 2019 03:11:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563419464; bh=Y2HbY6nMTyaVNBvYYnjLTL+BRCTxKa+hPrWPXEPUo+s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=WWdF6ak/jOaWlkCdLE14yyEeCXR1G8Sr6SDLawydbt4aTPAwIHM4N7vFgBuuTv4Me 9b0f6UK5r/5TuSed1BuD6NG1PD9a4uSupZ198W1cnqVkHf2wTUVWfGAp4e6y2rPz7v 6hFfaNqq5BPjUE7b9hynd1ZBBhznXLinpsNbmHNQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389698AbfGRDLD (ORCPT ); Wed, 17 Jul 2019 23:11:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:44542 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390808AbfGRDLC (ORCPT ); Wed, 17 Jul 2019 23:11:02 -0400 Received: from localhost (115.42.148.210.bf.2iij.net [210.148.42.115]) (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 1900B205F4; Thu, 18 Jul 2019 03:11:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563419462; bh=Y2HbY6nMTyaVNBvYYnjLTL+BRCTxKa+hPrWPXEPUo+s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MzfKpe2vY3G6wzHdC20ahT4MampRs4J70eqM4clCDtnFTSGYsRez7sx2nKppM00I3 07n5E5haGV6oVBkUCld08vpLMHo420UtywsaGPCllB1eLGHEeSZ4IMsT5Cc8JaVKDm 7CvZoChGNgkT1/vkkiiUheAzLuwm40Lr/9nbI1WU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vinod Koul , Andrew Morton , Bjorn Andersson , Randy Dunlap , Linus Torvalds , Sasha Levin Subject: [PATCH 4.14 73/80] linux/kernel.h: fix overflow for DIV_ROUND_UP_ULL Date: Thu, 18 Jul 2019 12:02:04 +0900 Message-Id: <20190718030105.125331132@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190718030058.615992480@linuxfoundation.org> References: <20190718030058.615992480@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org [ Upstream commit 8f9fab480c7a87b10bb5440b5555f370272a5d59 ] DIV_ROUND_UP_ULL adds the two arguments and then invokes DIV_ROUND_DOWN_ULL. But on a 32bit system the addition of two 32 bit values can overflow. DIV_ROUND_DOWN_ULL does it correctly and stashes the addition into a unsigned long long so cast the result to unsigned long long here to avoid the overflow condition. [akpm@linux-foundation.org: DIV_ROUND_UP_ULL must be an rval] Link: http://lkml.kernel.org/r/20190625100518.30753-1-vkoul@kernel.org Signed-off-by: Vinod Koul Reviewed-by: Andrew Morton Cc: Bjorn Andersson Cc: Randy Dunlap Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- include/linux/kernel.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 1c5469adaa85..bb7baecef002 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -101,7 +101,8 @@ #define DIV_ROUND_DOWN_ULL(ll, d) \ ({ unsigned long long _tmp = (ll); do_div(_tmp, d); _tmp; }) -#define DIV_ROUND_UP_ULL(ll, d) DIV_ROUND_DOWN_ULL((ll) + (d) - 1, (d)) +#define DIV_ROUND_UP_ULL(ll, d) \ + DIV_ROUND_DOWN_ULL((unsigned long long)(ll) + (d) - 1, (d)) #if BITS_PER_LONG == 32 # define DIV_ROUND_UP_SECTOR_T(ll,d) DIV_ROUND_UP_ULL(ll, d) -- 2.20.1