From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7AB5B324B35 for ; Fri, 14 Nov 2025 15:02:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763132535; cv=none; b=rhclycdEjYoUk6qNUKHeAljh+QT99TaEXgQC71D36uB5f0lw5W3wznxJU3g+IqZxhy7rGhwg+znM2AZkwaJ4SZfNu1E9E7hWS0Wf9qI/E5uL4RDAlKpzlgMRE9zXoZWktKdZ4pwqHWrYTayudmkd9kjo2MD9fNyDUfWRHeWOUvs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763132535; c=relaxed/simple; bh=WsPVMmryO2QRx2Xp4l1oL5HQgH0irrFM+LGLFSthqWY=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AYEEDzl3ISRBYNf9vBWdrzYMYNQvg05qZk1uOuQxzQ7wnCd1Fs6VA4GsXqj4D8zLn71hCPhlpshiyGDzP0Oqg4saRMRHPY+CrC0Wd7QMWTgeBTng2JphiJwVbCa4ttQ3THCw7HScJaBcJp7qjVgwifVY6PkNwJ2JwhcmZZ9RYec= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=amFl/htq; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="amFl/htq" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4777a9aeedaso18980405e9.3 for ; Fri, 14 Nov 2025 07:02:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763132532; x=1763737332; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=ArZZMcVGxA/fyahR3ThATogsNHyENVsjurNGhgvKTQ0=; b=amFl/htqQHpI2IuAgtzE9qcGt/+eh1L6gstoOTaM6wEiSMWwF9VHQT/SvWNEGIhkEa qnSFjcNNHNeF7gof1rcbC+dbIpCZ1YjegS1bb0VF6e+NfmogoiS4MBjoduHPrasJYMth z13o2vsqwOiaBichtOkAbsVrfiqMxLG3iP8uRSX1feu2Z5D0KcH20fPDiblbnFKugyEV bINNMF5ki1ohfVgqEv/67L0TnTxh6V5VPaAWzXgxF32kEsK+9gVqrVgTS9utq096ZZU5 2nXozxppbX85YITxKhe7DvNgFPi0opPpwGsGw2n8w0IM6UzVo1xElNCHgG1SIFktpkkN khDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763132532; x=1763737332; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=ArZZMcVGxA/fyahR3ThATogsNHyENVsjurNGhgvKTQ0=; b=KKX4lB4Hyb2us36/W92z1gF+HzaSBc1ozGn7Ca7wTSzZqLM0LoOQ+kRTtKiQsFKXqB TeIXDTyq0TW0CLc4CWcWD7y/qKItwh7DycgzeEspbnorttKhopQxLpJ8WHxY8l4oopbA A8XYeGd/drTZfjXaHCjY7faCdyrV/OwggeRsVpgaOhdYiJXc6mkXUyk8JN4nbV8SJUHe akmd1n96u6NscoRP6wnTcvCMIoJcjzodl3ScVqJUzVWMzgn629BuWeOfR5HJiMcru+qn VAOGUesGS8UOSFGYr/i9qsZHrq2F+Za6fp6XJ8g5Lx1PDdCqbDP491zRMc6wU7obJ8tO 8Gww== X-Forwarded-Encrypted: i=1; AJvYcCWzIeLMwMeyTvZ+9fXnUzdXmqpPNULTfu5ilI3wSczhNWsG3y6l+lrM7wyM+OvjzFPfdk1mnFHGMxjGCWU=@vger.kernel.org X-Gm-Message-State: AOJu0Yw4mgK67hXQxlAROeIR63oEGnkZoNkIq4RG2TY7ixrIpEd8WgKh 21g8Xv+Kj+P+hdzXwtYQJZuLEUZy2E9rcXEY0cf2PjfhNcGphIjp+fgm X-Gm-Gg: ASbGncu/fAgtqhmmOQ5CE8Y6yB2gzjIKOZhahPep/pV/9chjk8NqUi+4xZwYBB5OcrR 9+TXZzW48Agao601wf6ii4pKV7avxHc0ZHW3+2sxIcWC+moHdvyaeBzD5608zCXb1RX5jJptsNX YFlPegOLwQGyNbpp5P9vOUOnDbXMZ4BbXNs0p2E0KAmGWlmRjgRlJbujATqGFa9DB7eSSEz25Cb UpHjGHkx8mNf6A6/Ipi6QdebsZI211IJMK1Woh01nUOpETrG+IYqotRZyvz1h4HfNEYfxVmWiNX yQwisBNqAqTzaI2YvhNzM0u7RJ/SDKXXr4W54uwoo4W2rbmn0ieMnmNd0lluqp8hClACZY5nGxZ eYt5+u5hhUk+sLlFmO6puXwkdBcMq0ndXDeu3utLWqdpK3PA+8qeqiACanmNVS6ydtH84KKR0oV wERK3NWf7gd181l9yYybJCEiUTlo+4wWxJe6TgQxQfSXTbgphNK4hZ500/DnGUjVf0+qZ2IT90O w== X-Google-Smtp-Source: AGHT+IFxB7cDW2rsqld9Yz9oqhMfcsoEwLrS/BP/u5dMUdlMLbed8X7koUFMcuWWEOnw7mvDGT1HGQ== X-Received: by 2002:a05:600c:4f53:b0:477:8985:4038 with SMTP id 5b1f17b1804b1-4778fe5e5a9mr30392615e9.13.1763132531255; Fri, 14 Nov 2025 07:02:11 -0800 (PST) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47787e43c2fsm146421585e9.6.2025.11.14.07.02.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Nov 2025 07:02:10 -0800 (PST) Date: Fri, 14 Nov 2025 15:02:09 +0000 From: David Laight To: Steven Rostedt Cc: Thorsten Blum , Josh Poimboeuf , Kees Cook , "Gustavo A. R. Silva" , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] unwind deferred: Annotate struct unwind_cache with __counted_by Message-ID: <20251114150209.27354ddd@pumpkin> In-Reply-To: <20251114085332.396aff85@gandalf.local.home> References: <20251114122748.222833-1-thorsten.blum@linux.dev> <20251114084346.6469edc0@gandalf.local.home> <20251114085332.396aff85@gandalf.local.home> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 14 Nov 2025 08:53:32 -0500 Steven Rostedt wrote: > On Fri, 14 Nov 2025 08:43:46 -0500 > Steven Rostedt wrote: > > > I need to add a comment here that entries is not bound by nr_entries. > > > > https://lore.kernel.org/all/20250730093249.4833be14@gandalf.local.home/ > > > > Maybe this?: > > Or better yet, if this compiles (I haven't tried): > > diff --git a/include/linux/unwind_deferred_types.h b/include/linux/unwind_deferred_types.h > index 33b62ac25c86..253a69b21e76 100644 > --- a/include/linux/unwind_deferred_types.h > +++ b/include/linux/unwind_deferred_types.h > @@ -2,10 +2,14 @@ > #ifndef _LINUX_UNWIND_USER_DEFERRED_TYPES_H > #define _LINUX_UNWIND_USER_DEFERRED_TYPES_H > > +/* Make the cache fit in a 4K page */ > +#define UNWIND_MAX_ENTRIES \ > + ((SZ_4K - offset_of(struct unwind_cache, entries)) / sizeof(long)) > + > struct unwind_cache { > unsigned long unwind_completed; > unsigned int nr_entries; > - unsigned long entries[]; > + unsigned long entries[UNWIND_MAX_ENTRIES]; That won't compile - I tried it. You could add __aligned(4096) to force the structure to be padded to 4k, and then define UNWIND_MAX_ENTRIES in terms of the structure size. David > }; > > /* > diff --git a/kernel/unwind/deferred.c b/kernel/unwind/deferred.c > index dc6040aae3ee..5dfd0ac264d1 100644 > --- a/kernel/unwind/deferred.c > +++ b/kernel/unwind/deferred.c > @@ -37,10 +37,6 @@ static inline bool try_assign_cnt(struct unwind_task_info *info, u32 cnt) > } > #endif > > -/* Make the cache fit in a 4K page */ > -#define UNWIND_MAX_ENTRIES \ > - ((SZ_4K - sizeof(struct unwind_cache)) / sizeof(long)) > - > /* Guards adding to or removing from the list of callbacks */ > static DEFINE_MUTEX(callback_mutex); > static LIST_HEAD(callbacks); > @@ -118,8 +114,7 @@ int unwind_user_faultable(struct unwind_stacktrace *trace) > return -EINVAL; > > if (!info->cache) { > - info->cache = kzalloc(struct_size(cache, entries, UNWIND_MAX_ENTRIES), > - GFP_KERNEL); > + info->cache = kzalloc(sizeof(*cache), GFP_KERNEL); > if (!info->cache) > return -ENOMEM; > } > > -- Steve >