Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1688454ybi; Wed, 17 Jul 2019 20:09:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqzUSD+tVEpHsnAk7jq44waaXigm+C4ibzn0sOj/fzBx92PrvypQUcq3OxLWC4yS2uklX8rq X-Received: by 2002:a17:902:1125:: with SMTP id d34mr47379913pla.40.1563419379179; Wed, 17 Jul 2019 20:09:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563419379; cv=none; d=google.com; s=arc-20160816; b=xdabZibWhmzaz7DVFIVvgnKCcNUXf2Qv6D2DLb16GLY5MhT1sdEE81nDK/AKEvYdYk UGzsUPDSCLfe0zAL0Jh0Izq1ll59wKz2vLM32jV7q13FCE1q1c7g3GaV1ld5Gg+lffw7 pB9NhzST9oQ2LxkbnsOQGTnbp1UcUmb07B+ic8xnfKIDGBcuNnYIsSL9f5x9QUBEHZ2d 1lall9Rfk7hkIHxhydt7SVMQTBkLvTZk5jtqdn/hZLXx+dYXxJUECIqnRJgSvh/zgGxl fZ4xz3T0kOw+tDtnshGrJ5YuUt78b3YVzIAvZSWBhWbeIg1ekHBxGfPOCRqolFXFYqZ3 cstQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ZPX0TEvy7lsdprIuDANJhHmkfvRR3uc9nXFjD1DUYMM=; b=Qq9owfWJ6iNvi26bblOdFPx0Dqh3w5vdMnxW47K6gRL3Ysleg5ELKWoYOrWdye8ooA KVQU2g9QL/COrH0HTZFALyVVMJB2fEPr+1CCtOPVS373kQDo2tCtIjVJIuoAxDjW5OP/ m+cPuXcrLpp6JWavte0LlgeZkXk2Uk+hs9IsmddYQjUrALSGuDRLlNo4oaIy4WRXOa0C 2rKntB7n7c3vPENS76pqvaIwDsq+xo2cKsFPcZS9VKGlHmOWAh5G/8Q4zHnFXs6yndKq eWX7uH7IjJpDHiSxKIsiGd2k/u5mRBh62B+jngLa4DkijkBYWDdxwymYlO98Uvs/5axN 9AaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LpYFFwfS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 91si910938plb.39.2019.07.17.20.09.22; Wed, 17 Jul 2019 20:09:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LpYFFwfS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390662AbfGRDIM (ORCPT + 99 others); Wed, 17 Jul 2019 23:08:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:40006 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390648AbfGRDIJ (ORCPT ); Wed, 17 Jul 2019 23:08:09 -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 94D412077C; Thu, 18 Jul 2019 03:08:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563419288; bh=Rco+cMlzC9IAhIErmrGsZyUHE87YUacoyF9rlYIfRL8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LpYFFwfS1Y4BbTtszo8nu71hnaZ1AWl/bv9nZziJCW1Ps0qQMGnJY1jT8rs+5Rkr6 Kaz+G1MZBU+B+bzbb0dg6Cu2hm/Ef6d34rwkcTVXlCx1KY/GMxz4eEi/M0Nm8WPNA4 lQOqd8UIVlTMG7qJPPx1ZfDY6tkCJoRJ7wVpjWFs= 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.19 29/47] linux/kernel.h: fix overflow for DIV_ROUND_UP_ULL Date: Thu, 18 Jul 2019 12:01:43 +0900 Message-Id: <20190718030051.200640741@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190718030045.780672747@linuxfoundation.org> References: <20190718030045.780672747@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 3d83ebb302cf..f6f94e54ab96 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -118,7 +118,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