Message ID | 20220922031013.2150682-9-keescook@chromium.org (mailing list archive) |
---|---|
State | New |
Headers | show
Return-Path: <owner-linux-mm@kvack.org> 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 D2394C6FA8E for <linux-mm@archiver.kernel.org>; Thu, 22 Sep 2022 03:10:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1B3EE8000F; Wed, 21 Sep 2022 23:10:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 13D078000E; Wed, 21 Sep 2022 23:10:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ED28B8000F; Wed, 21 Sep 2022 23:10:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id D117C8000E for <linux-mm@kvack.org>; Wed, 21 Sep 2022 23:10:30 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B4BBD1C6AB8 for <linux-mm@kvack.org>; Thu, 22 Sep 2022 03:10:30 +0000 (UTC) X-FDA: 79938243420.29.1AD48D3 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by imf01.hostedemail.com (Postfix) with ESMTP id 62BA040004 for <linux-mm@kvack.org>; Thu, 22 Sep 2022 03:10:30 +0000 (UTC) Received: by mail-pl1-f182.google.com with SMTP id w13so7558435plp.1 for <linux-mm@kvack.org>; Wed, 21 Sep 2022 20:10:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=TDASAml4kCnGP6A0dhCkNjKPm18x/T6dZyC75aPZacc=; b=WPgEF+jupR4SGB4DLno2k2bBCbZ8b8f+ZrlxKcIQeEbCtj5WBgsCFhiT+NIX1Fpq8q RVzdxz0WZY9Xy+TjHVDvowfkPuPW/OFy/IlUhIW+WjLJlx/oYe632OrUVLWT43o6LOap J1uHENSlV+a7neJtjBRovZ5eH4VN/4Sv8DcCs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=TDASAml4kCnGP6A0dhCkNjKPm18x/T6dZyC75aPZacc=; b=nNGrFFKrEeQswjqrf5xLdpankUnM8CYZ3iWtzGCOkvrupjuHCH6RpGXO+cIyzXerdU y9RDFN30FLBE3+u9VCQqL7Y4rs+za7q0wZ3pTyDUH/cMB0EkmgEWwVEizOQBtpTJC69m T8FY7/yoCnNE+TA3K9MiwiEPid3Ve4CQEUyA9HYl34gAtpEBs/8OYxODHyZXGuosquhz 3rYa/aGbDu1vjTbfqqQnUzKy+y/rm6kSAsJrtc4oX6cBCxytn7Tb+4OLeddllZOy7jui lUZ2FpoEnjxmUO5ed2cS2QAwt5PeN8xjIZr9ORdIecPgbrm9nd8Wqtv+B1h3hYr1qciK hSBQ== X-Gm-Message-State: ACrzQf0Hmi9sqM8auafj8EJ7LQuWkJLeJWFp71mq1m68K/cikZBaxDrK bHXpPLwP54Bm/7fkVkdyaxBxOw== X-Google-Smtp-Source: AMsMyM6FwJ0f+Bofi6cEtpiWEB7NdUhtmrkt85vC8m03N7qUc6HActCoKwZbZiJ520VUx/+qozuRZA== X-Received: by 2002:a17:902:ec85:b0:178:8a69:45fb with SMTP id x5-20020a170902ec8500b001788a6945fbmr1346743plg.130.1663816229473; Wed, 21 Sep 2022 20:10:29 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id t11-20020a170902e84b00b001782a6fbcacsm2768353plg.101.2022.09.21.20.10.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Sep 2022 20:10:26 -0700 (PDT) From: Kees Cook <keescook@chromium.org> To: Vlastimil Babka <vbabka@suse.cz> Cc: Kees Cook <keescook@chromium.org>, Pravin B Shelar <pshelar@ovn.org>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, netdev@vger.kernel.org, dev@openvswitch.org, Pekka Enberg <penberg@kernel.org>, David Rientjes <rientjes@google.com>, Joonsoo Kim <iamjoonsoo.kim@lge.com>, Andrew Morton <akpm@linux-foundation.org>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Nick Desaulniers <ndesaulniers@google.com>, Alex Elder <elder@kernel.org>, Josef Bacik <josef@toxicpanda.com>, David Sterba <dsterba@suse.com>, Sumit Semwal <sumit.semwal@linaro.org>, =?utf-8?q?Christian_K=C3=B6nig?= <christian.koenig@amd.com>, Jesse Brandeburg <jesse.brandeburg@intel.com>, Daniel Micay <danielmicay@gmail.com>, Yonghong Song <yhs@fb.com>, Marco Elver <elver@google.com>, Miguel Ojeda <ojeda@kernel.org>, Jacob Shin <jacob.shin@amd.com>, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-btrfs@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-fsdevel@vger.kernel.org, intel-wired-lan@lists.osuosl.org, x86@kernel.org, linux-wireless@vger.kernel.org, llvm@lists.linux.dev, linux-hardening@vger.kernel.org Subject: [PATCH 08/12] openvswitch: Proactively round up to kmalloc bucket size Date: Wed, 21 Sep 2022 20:10:09 -0700 Message-Id: <20220922031013.2150682-9-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220922031013.2150682-1-keescook@chromium.org> References: <20220922031013.2150682-1-keescook@chromium.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1419; h=from:subject; bh=BnVOhrGnWnn0qmsrneuatz5VZroW3iZYMrlDdw6WzZA=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBjK9ITSglsXN14oMtyaHSvyKAfYqb/jU+ua3WQ3QDI +BCEy4WJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCYyvSEwAKCRCJcvTf3G3AJuckD/ 0fC2DD7jgGoKpFD7s52Imf5skay/p4qVmK0rvZNjkGAmNGvUFsTnir5GI3TMV3p/FWB9oxlzjn3lRJ YbQuqElrhpv1aHtZF5nq2pNe2WeidRtExDsumfRW/9rwf58N/wfxbElAY9GHoqVRc3lUIV9oQYeOhK 1kJwstuo1zV2TYN4g0iYTTSXNQhbPXQ513gM0PP9l/YiITmzLOgjZgDFaN+QjDNsRclDp6Yt0t3KK0 u44yaM81Tj4s/G/cazw7Jsf6TLb2WBPqCt8tdGe27UEsHIqsFjpRY7nmsAAp8iG8Xem8x+/oYI/Wbk HgMgUuw1m5UkfchSrwCJfeis+j1yNloKfOqqnWkCkG+hSthHxri16TT3gYtEK81SyX7qdZEi0YzWC1 HzPQNdrH6o3PN6vMQOI+fCDeICkvey7UrPwFg21Eqq5d0i1Q/IjdJkPIS5rxpe10rGou2R7M83TPCj g7LmoCyTxmRqFzEzRuBHtLLGVMHa5PjJy+FD8ubMoYHOzgg+Mw1qV+65O4LUccNAhythMxiYUkwGsA 5/JlFokXB6JtqWVHa5OTlymJF5c70uDllOyQsXSHJV/6Th+1UpurayKJIgQFsm/OxxbzV0XgUK3Dam UhsIlzfHslsALppIqri1WH09qAL4uxlG1Se3WTFKlmYiDtPENjS7L1iOMWDg== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663816230; a=rsa-sha256; cv=none; b=k/XDZaGW0xNzYrdWMAlyzIfBFPtBgQVIEiOATg85XiKKGAcsiv8WRTla9rNUBHzjJDSm1j kjIBysiKy0elbZPcrwoKMrZWvuo7Ejq4MG9j+HAZpRuhfWYFaqBWEF+W1uytXt0tWFaNjS FwZ7xQ1MzBZrfak7FDGQwr9IegWTdPQ= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=WPgEF+ju; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf01.hostedemail.com: domain of keescook@chromium.org designates 209.85.214.182 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=1663816230; 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:in-reply-to:references:references:dkim-signature; bh=TDASAml4kCnGP6A0dhCkNjKPm18x/T6dZyC75aPZacc=; b=UgKvcTRLJUcANZMzsv5370XBr5AgbvAgXQnMV5fHbA50sI+UqcsFiSVGEygSSuGefJNPXr A+T1N6Wdq8iOhrVhhQPJFNhdsCNBaaLoBSNDfANBAnTakzaxxSUfWqqJoImDtYw9JmmlmP 0+dIIaXHCJZBA48apnQy8q8TOlQPk2I= X-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 62BA040004 Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=WPgEF+ju; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf01.hostedemail.com: domain of keescook@chromium.org designates 209.85.214.182 as permitted sender) smtp.mailfrom=keescook@chromium.org X-Stat-Signature: 54a6dy3z8mxzmqmxc3f5h8sfeosm5hyf X-HE-Tag: 1663816230-604901 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: <linux-mm.kvack.org> |
Series |
slab: Introduce kmalloc_size_roundup()
|
expand
|
diff --git a/net/openvswitch/flow_netlink.c b/net/openvswitch/flow_netlink.c index 4c09cf8a0ab2..11b2e2c94c7e 100644 --- a/net/openvswitch/flow_netlink.c +++ b/net/openvswitch/flow_netlink.c @@ -2306,10 +2306,12 @@ int ovs_nla_put_mask(const struct sw_flow *flow, struct sk_buff *skb) static struct sw_flow_actions *nla_alloc_flow_actions(int size) { struct sw_flow_actions *sfa; + int alloc_size; WARN_ON_ONCE(size > MAX_ACTIONS_BUFSIZE); - sfa = kmalloc(sizeof(*sfa) + size, GFP_KERNEL); + alloc_size = kmalloc_size_roundup(sizeof(*sfa) + size); + sfa = kmalloc(alloc_size, GFP_KERNEL); if (!sfa) return ERR_PTR(-ENOMEM);
Instead of having a mismatch between the requested allocation size and the actual kmalloc bucket size, which is examined later via ksize(), round up proactively so the allocation is explicitly made for the full size, allowing the compiler to correctly reason about the resulting size of the buffer through the existing __alloc_size() hint. Cc: Pravin B Shelar <pshelar@ovn.org> Cc: "David S. Miller" <davem@davemloft.net> Cc: Eric Dumazet <edumazet@google.com> Cc: Jakub Kicinski <kuba@kernel.org> Cc: Paolo Abeni <pabeni@redhat.com> Cc: netdev@vger.kernel.org Cc: dev@openvswitch.org Signed-off-by: Kees Cook <keescook@chromium.org> --- net/openvswitch/flow_netlink.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)