From patchwork Tue Mar 5 10:10:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13581913 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 AB72CC54798 for ; Tue, 5 Mar 2024 10:10:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 01EAD6B0095; Tue, 5 Mar 2024 05:10:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EC6146B009A; Tue, 5 Mar 2024 05:10:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C03356B0096; Tue, 5 Mar 2024 05:10:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 9B96E6B0099 for ; Tue, 5 Mar 2024 05:10:35 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 6471B160CA8 for ; Tue, 5 Mar 2024 10:10:35 +0000 (UTC) X-FDA: 81862566030.07.93AF800 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by imf09.hostedemail.com (Postfix) with ESMTP id 70477140008 for ; Tue, 5 Mar 2024 10:10:33 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=U7LDummB; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf09.hostedemail.com: domain of keescook@chromium.org designates 209.85.210.174 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=1709633433; 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=W6tSmWQUz9mHEs7KKdtWRSqXpZBjknnUveJhwT+v2FU=; b=lFK59U2oYv4hGan1UcJWqMWKV/jW/2FlcjlmwWjPsDtX7W32UOdXCMj+IV60AyQ7QoEgOY JgiZaUDCpAgjaYvNVFZL9BT9cObDan/I1rOeI4zqDVi3yqAbXmu4yB/+N3aEuTgv8oVlss uTyp764RW9t1r6Z4Rj3gRIuzp4pMFo4= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=U7LDummB; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf09.hostedemail.com: domain of keescook@chromium.org designates 209.85.210.174 as permitted sender) smtp.mailfrom=keescook@chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709633433; a=rsa-sha256; cv=none; b=0rEquFoiBY1vGhnQwlE2WAoAag4lZ0+kkys/hOiYaR4SvbkwL0XaKvZ4eDUVtvFOcWZVIr L28/giOIOhkF+U0auU3Dss+uXtYyundbAPHz9LonkjA53MYzSS3tgwlwRWXodOxufBgZjb ssfq4c95uTq4F9ccjue4HthCcTpLLh4= Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-6e5dddd3b95so2349453b3a.1 for ; Tue, 05 Mar 2024 02:10:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1709633432; x=1710238232; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=W6tSmWQUz9mHEs7KKdtWRSqXpZBjknnUveJhwT+v2FU=; b=U7LDummBLlnsabgDIUYq/Ksj7IOxE2Fo1ebHUuLZmryeeGpVzWgwtOey24kVqdP4HS UJ1thtbxUuRYzIb9GjrtSTvF8cFwDZRxQbUjm7umjKuRaLWpJMO8Y+kE90J6GDY2uZCr qdCNTT/Fsy+AZwR7D2fqAWEiTF7M246A/vd8c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709633432; x=1710238232; 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:message-id:reply-to; bh=W6tSmWQUz9mHEs7KKdtWRSqXpZBjknnUveJhwT+v2FU=; b=FP0YEh6I9W7wUQqzR4wE0X0IKJLDcMub9RCRm1TuqICVBtZEUXgh2B8bLghs7+ld0a O3gcJWX5yAL7DHQO7VQHb65Hr6dMjj/k0iRQ8apE/xn00iqzaSGY1ie7plwlrkPUleWa XHjbBS2ckcihhIoEZwm1BtBRGpEieFRnSlL0+dIoFkb8R/gdmEvdAqfJC79MGLxko9uf YzEz/2iT0uu5BDjcpp2TpqiQT5JJfaHFish9oEwMT89ASlAm8cecHoNpmiN6eiHEJr3v e7zrrI7MLqCajgzfJX1/96MNnmZvAY+dSCDPNWc7ah0mEAJmKcWmXresyrK7ZVW18rAI uniA== X-Forwarded-Encrypted: i=1; AJvYcCVruBJ4fH6Wl4HcShZvf5EMvnWLRsAAn/F5u2d8wkq8SsCP5Z5wva4Uuv2Pu6DPiHmEghM70nbhx2wqcwWl5XPtU5g= X-Gm-Message-State: AOJu0Yyh5gY1gJHllbxxKtJ2QBcqBv/9+iW8v9GyWWZ/pnlXCuC5NVQ+ Lj2GqexbTvXiEjZ7Pp3ZEfGoGjPYe1eU6LuQ2nSR7WIvWrvvH8KPRrvZAMHVOg== X-Google-Smtp-Source: AGHT+IGioGxnLf58krzooyXRSux/Zxx7hWwNEvHeCXchceFMByRkqxZ+PaMIxnsL+kY8mFgOqRxI3w== X-Received: by 2002:a05:6a20:729a:b0:1a1:3b27:4f3f with SMTP id o26-20020a056a20729a00b001a13b274f3fmr1585251pzk.2.1709633432471; Tue, 05 Mar 2024 02:10:32 -0800 (PST) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id m7-20020a62f207000000b006e580678dfbsm8485054pfh.193.2024.03.05.02.10.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Mar 2024 02:10:30 -0800 (PST) From: Kees Cook To: Vlastimil Babka Cc: Kees Cook , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-mm@kvack.org, "GONG, Ruiqi" , Xiu Jianfeng , Suren Baghdasaryan , Kent Overstreet , Jann Horn , Matteo Rizzo , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH v2 6/9] slub: Introduce kmem_buckets_alloc_track_caller() Date: Tue, 5 Mar 2024 02:10:22 -0800 Message-Id: <20240305101026.694758-6-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240305100933.it.923-kees@kernel.org> References: <20240305100933.it.923-kees@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2914; i=keescook@chromium.org; h=from:subject; bh=5+bllf7wQXoQ1iiymcQxAaVJUnLpEaTtP4WhLyfCGPk=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBl5u+Q9Fez113NbGGVqjvVTslyLAH8TI+6Wb4a3 UHTy9ESMGeJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZebvkAAKCRCJcvTf3G3A Jum0D/9tfCyWy09BzH1L9P4M66z0u2ctSfRJPeQ1x4bgaEnW38mkbjG41ME6e+R5Zj0gpmBgZ+L BVNaHnefEXko8smuTRzZ4FGGksACNwKf0+N86253pNgtssxWUfgfa3aQ1EA8XEBCMceHWGnr84H h34x9bAbwoUCp96M4lvRDs8cKxVlleF0jjCvDpvMT3T1ZAyvoPvNHYpvj6mth+oFIZTSkt3Wz+X 919IaLbl/IDuiJVd9rtpALExUWOh+KXL6FuuwYZHWN+SaSa712xlgG/5pLuJ+2l8Ub1IJiEQVWp r/4azSgELrhUJFvtIbkEWWKreqYhRzNs/rKZUmxW7K1gGKiGdDk4ZDqhqhclVbw3MMBNLZbLerx rSCyI/khhcdBGZYwjg6IFEY/vpFVkrL44xPf13VdK07PEsrsff7tXBBEX59HFI2KvQG5OsvWVhP aHHbbGxMkh8n+z9aHH4WpY49kUBjUPRrASB5fIz5FsMzXVgyemQHiUSYTVdkJ3aT34AdKNF6pks Immb98LUo/rCvKgXzxq/u49qS0zQkVpV4BWtD/SwK4MuhHIOU8Rm9ytXz8ZSxeZ0v1pYc89qObI o3aW/HpIQI7IY2DuYh0+o+TW5k0hDDZa00o0vGiCTiQIKa61gmW3pYCwmM5FPO2U0gagUkJ30W6 V9QFinQCp7WdukA== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 70477140008 X-Stat-Signature: rdh87f9ogkbemeun1ycbez5wiz5r3o4e X-HE-Tag: 1709633433-48609 X-HE-Meta: U2FsdGVkX1/RwxIst/cEyXmtc6HlC5m8NfYNhCiXNdAredDmPNq9A4oJa7BJi5AiI7UcZbdQZX2G1hSq4xj39OVfhym2c6AfsQQjdOPdNdaN3dz+szZkfTNx1q97KYBdn5sy59Sk2RaioM35/CDrP+Xgzt1YbNpEx3gLSRG5CdjxUP6/yRo9IV6GXtU8BMDBa96+E7yAduL5zPtz87xDW4DO3eQD7xcyd/JYxwbtofj0Hh5pbMuhLAEBzG6pn57d7S4brQUoWqPtsqg/ffHOkzXzosP+chTSC67lZhe6z8w61cqRIJFFCImqsM2/nmX7R72l7iQ6tCXXKvLdCNkl/MRg1iuA65/MDF2D1XDAKg8kutxKum/DsJy8EYqArS+d+Fj319eog2liH6L1rPHF+wwjI4zDaCWaOa5w2yvpmAvIszY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5VHu1KK28WpQYEsMjt33RIRExGXflH/93ZhjYFKmkHFpBYKJ37TaCbYW/ZnGcYRJgDweD0eVztoKqdn6XrMSO8Fg7GmLQqxOPv+6p9iF8MFdNIzIPOTmEK3Ez90sa2YFGU6fOWBO0Dz3xwixmJFJLP8Q2T3T3aSg46jtOqEJO++/rhDi25XHpe2ngIu/ST7JK7VOX6zTMFuNOufuJoXQx1JWEPzhD4PqlNZ4W/i7agogWv8C2wNk2I3j1vztUPYdPW8dOMR36w15jPWktmEAxl71/30MsTcV29N/0rYb64yHkHVtbHOgvtdB0MKEb/qQS/9wWIReLSdaUNzpflFyh+k+S60s= 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: List-Subscribe: List-Unsubscribe: For better capturing the caller details for allocation wrappers, introduce kmem_buckets_alloc_track_caller() by plumbing the buckets into the existing *_track_caller() interfaces. Signed-off-by: Kees Cook --- Cc: Vlastimil Babka Cc: Christoph Lameter Cc: Pekka Enberg Cc: David Rientjes Cc: Joonsoo Kim Cc: Andrew Morton Cc: Roman Gushchin Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com> Cc: linux-mm@kvack.org --- include/linux/slab.h | 11 +++++++---- mm/slub.c | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/include/linux/slab.h b/include/linux/slab.h index 08d248f9a1ba..7d84f875dcf4 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -606,6 +606,9 @@ void *kmem_buckets_alloc(kmem_buckets *b, size_t size, gfp_t flags) return __kmalloc_node(b, size, flags, NUMA_NO_NODE); } +#define kmem_buckets_alloc_track_caller(b, size, flags) \ + __kmalloc_node_track_caller(b, size, flags, NUMA_NO_NODE, _RET_IP_) + static __always_inline __alloc_size(1) void *kmalloc_node(size_t size, gfp_t flags, int node) { if (__builtin_constant_p(size) && size) { @@ -670,10 +673,10 @@ static inline __alloc_size(1, 2) void *kcalloc(size_t n, size_t size, gfp_t flag return kmalloc_array(n, size, flags | __GFP_ZERO); } -void *__kmalloc_node_track_caller(size_t size, gfp_t flags, int node, - unsigned long caller) __alloc_size(1); +void *__kmalloc_node_track_caller(kmem_buckets *b, size_t size, gfp_t flags, int node, + unsigned long caller) __alloc_size(2); #define kmalloc_node_track_caller(size, flags, node) \ - __kmalloc_node_track_caller(size, flags, node, \ + __kmalloc_node_track_caller(NULL, size, flags, node, \ _RET_IP_) /* @@ -685,7 +688,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t flags, int node, * request comes from. */ #define kmalloc_track_caller(size, flags) \ - __kmalloc_node_track_caller(size, flags, \ + __kmalloc_node_track_caller(NULL, size, flags, \ NUMA_NO_NODE, _RET_IP_) static inline __alloc_size(1, 2) void *kmalloc_array_node(size_t n, size_t size, gfp_t flags, diff --git a/mm/slub.c b/mm/slub.c index 71220b4b1f79..ae54ec452a11 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -3995,10 +3995,10 @@ void *__kmalloc(size_t size, gfp_t flags) } EXPORT_SYMBOL(__kmalloc); -void *__kmalloc_node_track_caller(size_t size, gfp_t flags, +void *__kmalloc_node_track_caller(kmem_buckets *b, size_t size, gfp_t flags, int node, unsigned long caller) { - return __do_kmalloc_node(NULL, size, flags, node, caller); + return __do_kmalloc_node(b, size, flags, node, caller); } EXPORT_SYMBOL(__kmalloc_node_track_caller);