From patchwork Tue Oct 18 09:03:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13010181 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A774C433FE for ; Tue, 18 Oct 2022 09:03:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EDC646B0072; Tue, 18 Oct 2022 05:03:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E8BD46B0075; Tue, 18 Oct 2022 05:03:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D2D346B0078; Tue, 18 Oct 2022 05:03:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id C0D506B0072 for ; Tue, 18 Oct 2022 05:03:33 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 78F85120EEC for ; Tue, 18 Oct 2022 09:03:33 +0000 (UTC) X-FDA: 80033481906.07.5DC980A Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by imf12.hostedemail.com (Postfix) with ESMTP id 088BB40036 for ; Tue, 18 Oct 2022 09:03:32 +0000 (UTC) Received: by mail-pl1-f169.google.com with SMTP id o21so10804725ple.5 for ; Tue, 18 Oct 2022 02:03:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=PCPU7pjQsz2sISTfhiNbNnCu1P7dpEEV5lOobjZTacw=; b=gZGBjepH5r2X+kIH//9LW2XXDTFAYAsaVgXEYEJK60U8oTCCVoxBMnaYlbtC9+tU6J XkHOloaO+NzRJd6URyy702ekQTbvE4YcYM/hIXgfgmb5Wa5L6BKj8ftW/974Z5oeZxtB bYeSUZGddQ2ZQcyNnHg59O6hqF7mUHWYr4c5I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=PCPU7pjQsz2sISTfhiNbNnCu1P7dpEEV5lOobjZTacw=; b=BZpVPEanp3XbV6FvCjle/2A75tTjJeEdakLziW1vsUhvXcISyJhDuOHpZP75A0Tdtr EoUbuc4uL5Qfy3CmMAni2RgjjxajhcjvFAcjJCS5YJN1g67zFVo9WZjg2C093ALsnPfU dvVVMiiYAokWS3ze1S0aq2O6ZbrMD/iTCSgaPG7YJM+6MJs/rBEEWhdcWE/XFk5QNp96 HkaSrpMyElMlLZPOSKgTvWpgylrf/0+F7JtWlpA4rwCgpPMT58fMs5kx3bD+HueosGiA 2CS48P92k+D1TaO2a+6D3+TEqfLsKmMp0BkEjOPiOAsHZuTrm+/1Hq7u12NF+0cuoECY NvEw== X-Gm-Message-State: ACrzQf2T3z41hCyQA+QPpfQYjdZTQ4CzHevNjFj3pvKcqaSN6sd6L3Ez ADuWO8o1QRNZcApkWzx24z22xA== X-Google-Smtp-Source: AMsMyM5Tl9lIxuUj+N7gpJfouylM1Fk3M8j58mbVynyHz69C5+DaYz5jhwd5MS8ldzPFdZ+TWZRM3g== X-Received: by 2002:a17:903:22c1:b0:184:983f:11b2 with SMTP id y1-20020a17090322c100b00184983f11b2mr2253510plg.40.1666083811925; Tue, 18 Oct 2022 02:03:31 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id 185-20020a6206c2000000b00562677968aesm8643891pfg.72.2022.10.18.02.03.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Oct 2022 02:03:31 -0700 (PDT) From: Kees Cook To: Andrew Morton Cc: Kees Cook , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH] mempool: Use kmalloc_size_roundup() to match ksize() usage Date: Tue, 18 Oct 2022 02:03:29 -0700 Message-Id: <20221018090323.never.897-kees@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=821; h=from:subject:message-id; bh=1Gas3SCsMDWgBChil0VwFgY9Fr6zuZgi/zbZ+v/amZU=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBjTmvhvbPT002El9aaoLE6dlJ1BcKpLWc+O7EYysMd Ev7i92uJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCY05r4QAKCRCJcvTf3G3AJogxD/ 9d7YYM6vgBMsPh9pT1fJNW7vfocSmAMT8F3ueYojz9WVnJcdTz4G6UTlzKEPMXnTFQ+Ikut04037AM NUphveN6gJG094sCiDV2QDpK0kSqR6i7v6d6JeEajHqk5ivmQuvl9Xxk5BIJiPOmxHyNojFSxrbbKN e+iRyuL5xpsUHfuXFiVK0dMJ/+9l3C80nyNzHE/HuonrrNoDkxZgc2J+fAq0Ash3kPcaXvhVvIXUju nP4346E5t2mcJcm6cR52lLSW/eTUcB6UiGgAIcsnXGFXO9NSn8gUnQFuQhQ1mrSrxWLvco/+1mp3cU V+KrcVbRpWH2rtSgi8OU6xC1Api7QyYLEyq6a9VTlimKmoIlM75cXkj4tARmB4UueSbM/ARefUaCG1 6PWRHihJ/gxr8+HP+Q1FlPGSHxjZxnDsDP2uXwL0tpQnXxsR4aASftsIDiqAgek3isv+EW/3JwfxNa B3hLlwkMxfNlFx78NJJUJgdWYarJnoEAwlhdTBKZhIR1A5sNolKb4rYi15jpco36fD0UwkE4PRujGx gdztNv0oTxBVRojBwTlF5bdFd21CMoDhzP46Yr84bu9hTWmmu7QADa563bPM4L8LcFHkBdsoeGOoO8 0YrAD3OFWESSnxBCgesvoy18zdneTz5LKHqQN/Tu7YHczc0sxrLOnwSVXuWw== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666083813; a=rsa-sha256; cv=none; b=g39vexuO75zA0/OkzqGCdRF8/43vA7LPaEZzZzeXqNjRS2IdF5+XJZAOAzIxMRKha8C2F6 nv/IQAST3eg8XH8w3tl6yJ7WqfBHS3zOemRI+QK5T9TCyI9I2wMq0h+dvpjikWU9iX3K/C Lg3bp+gKmqii5WnYZEEu8QO1ZZ3XFew= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=gZGBjepH; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf12.hostedemail.com: domain of keescook@chromium.org designates 209.85.214.169 as permitted sender) smtp.mailfrom=keescook@chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666083813; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=PCPU7pjQsz2sISTfhiNbNnCu1P7dpEEV5lOobjZTacw=; b=azxHrg6wWWyF6I4LC6yI/Dbfx6CPcDFyVcvA9C9jo6QPSGpNwddWL2bK5T2qd046DvDvCr zQCpLV5/gRCGT1B0h0+F7d/f4MjtkYcRxQZdMrhRtY7uL1txlmPJhlemrZ0WvPNQ2d8CDu uNlWQfp8DVm3IFV0gERjWeJLqQZoosU= X-Rspamd-Queue-Id: 088BB40036 Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=gZGBjepH; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf12.hostedemail.com: domain of keescook@chromium.org designates 209.85.214.169 as permitted sender) smtp.mailfrom=keescook@chromium.org X-Rspam-User: X-Rspamd-Server: rspam08 X-Stat-Signature: f87yrbfkq6apsm5sbu5tz63x1htw6ih8 X-HE-Tag: 1666083812-610624 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Round up allocations with kmalloc_size_roundup() so that mempool's use of ksize() is always accurate and no special handling of the memory is needed by KASAN, UBSAN_BOUNDS, nor FORTIFY_SOURCE. Cc: Andrew Morton Cc: linux-mm@kvack.org Signed-off-by: Kees Cook --- mm/mempool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/mempool.c b/mm/mempool.c index 96488b13a1ef..0f3107b28e6b 100644 --- a/mm/mempool.c +++ b/mm/mempool.c @@ -526,7 +526,7 @@ EXPORT_SYMBOL(mempool_free_slab); */ void *mempool_kmalloc(gfp_t gfp_mask, void *pool_data) { - size_t size = (size_t)pool_data; + size_t size = kmalloc_size_roundup((size_t)pool_data); return kmalloc(size, gfp_mask); } EXPORT_SYMBOL(mempool_kmalloc);