Re: mips gcc plugin issues

2024-06-19 Thread Arnd Bergmann
On Wed, Jun 19, 2024, at 23:17, Kees Cook wrote: > On Wed, Jun 19, 2024 at 11:12:25PM +0200, Arnd Bergmann wrote: >> On Wed, Jun 19, 2024, at 22:50, Kees Cook wrote: >> The problem here is that a gcc plugin links against the >> compiler, not against code produced by it. I'm linking the >> crosstoo

Re: [PATCH] remove AND operation in choose_random_kstack_offset()

2024-06-19 Thread liuyuntao (F)
On 2024/6/18 18:45, Mark Rutland wrote: Hi Arnd, On Mon, Jun 17, 2024 at 10:33:08PM +0200, Arnd Bergmann wrote: On Mon, Jun 17, 2024, at 20:22, Kees Cook wrote: On Mon, Jun 17, 2024 at 04:52:15PM +0100, Mark Rutland wrote: On Mon, Jun 17, 2024 at 01:37:21PM +, Yuntao Liu wrote: Since

Re: [PATCH] randomize_kstack: Remove non-functional per-arch entropy filtering

2024-06-19 Thread liuyuntao (F)
On 2024/6/20 5:47, Kees Cook wrote: An unintended consequence of commit 9c573cd31343 ("randomize_kstack: Improve entropy diffusion") was that the per-architecture entropy size filtering reduced how many bits were being added to the mix, rather than how many bits were being used during the offs

[PATCH] randomize_kstack: Remove non-functional per-arch entropy filtering

2024-06-19 Thread Kees Cook
An unintended consequence of commit 9c573cd31343 ("randomize_kstack: Improve entropy diffusion") was that the per-architecture entropy size filtering reduced how many bits were being added to the mix, rather than how many bits were being used during the offsetting. All architectures fell back to th

Re: [PATCH 1/2] Input: ims-pcu - annotate struct ims_pcu_flash_fmt with __counted_by

2024-06-19 Thread Gustavo A. R. Silva
On 19/06/24 23:13, Javier Carrasco wrote: Use the __counted_by compiler attribute for the data[] flexible array member to improve the results of array bound sanitizers. Signed-off-by: Javier Carrasco Reviewed-by: Gustavo A. R. Silva Thanks -- Gustavo --- drivers/input/misc/ims-pcu.c

Re: [PATCH] wifi: iwlwifi: mvm: Fix __counted_by usage in cfg80211_wowlan_nd_*

2024-06-19 Thread Gustavo A. R. Silva
On 19/06/24 23:12, Kees Cook wrote: Both struct cfg80211_wowlan_nd_match and struct cfg80211_wowlan_nd_info pre-allocate space for channels and matches, but then may end up using fewer that the full allocation. Shrink the associated counter (n_channels and n_matches) after counting the results

Re: [PATCH 2/2] Input: ims-pcu - drop repeated "input" in error message

2024-06-19 Thread Kees Cook
On Wed, Jun 19, 2024 at 11:13:22PM +0200, Javier Carrasco wrote: > This case of the common error message upon failure of > input_allocate_device() repeats the word "input". > > Drop one "input" from the error message. > > Signed-off-by: Javier Carrasco Reviewed-by: Kees Cook -- Kees Cook

Re: [PATCH 1/2] Input: ims-pcu - annotate struct ims_pcu_flash_fmt with __counted_by

2024-06-19 Thread Kees Cook
On Wed, Jun 19, 2024 at 11:13:21PM +0200, Javier Carrasco wrote: > Use the __counted_by compiler attribute for the data[] flexible array > member to improve the results of array bound sanitizers. > > Signed-off-by: Javier Carrasco Looks good to me. Thanks! Reviewed-by: Kees Cook -- Kees Cook

Re: mips gcc plugin issues

2024-06-19 Thread Kees Cook
On Wed, Jun 19, 2024 at 11:12:25PM +0200, Arnd Bergmann wrote: > On Wed, Jun 19, 2024, at 22:50, Kees Cook wrote: > > On Tue, Jun 18, 2024 at 04:41:01PM -0700, Jeff Johnson wrote: > >> I see the following in my .config: > >> CONFIG_HAVE_GCC_PLUGINS=y > >> CONFIG_GCC_PLUGINS=y > >> CONFIG_GCC_PLUGIN

[PATCH 2/2] Input: ims-pcu - drop repeated "input" in error message

2024-06-19 Thread Javier Carrasco
This case of the common error message upon failure of input_allocate_device() repeats the word "input". Drop one "input" from the error message. Signed-off-by: Javier Carrasco --- drivers/input/misc/ims-pcu.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/input/mi

[PATCH 1/2] Input: ims-pcu - annotate struct ims_pcu_flash_fmt with __counted_by

2024-06-19 Thread Javier Carrasco
Use the __counted_by compiler attribute for the data[] flexible array member to improve the results of array bound sanitizers. Signed-off-by: Javier Carrasco --- drivers/input/misc/ims-pcu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/input/misc/ims-pcu.c b/driver

[PATCH 0/2] Input: ims-pcu - annotate struct ims_pcu_flash_fmt with __counted_by

2024-06-19 Thread Javier Carrasco
s(-) --- base-commit: 2102cb0d050d34d50b9642a3a50861787527e922 change-id: 20240619-ims-pcu-counted_by-7ff24a731073 Best regards, -- Javier Carrasco

[PATCH] wifi: iwlwifi: mvm: Fix __counted_by usage in cfg80211_wowlan_nd_*

2024-06-19 Thread Kees Cook
Both struct cfg80211_wowlan_nd_match and struct cfg80211_wowlan_nd_info pre-allocate space for channels and matches, but then may end up using fewer that the full allocation. Shrink the associated counter (n_channels and n_matches) after counting the results. This avoids compile-time (and run-time)

Re: mips gcc plugin issues

2024-06-19 Thread Arnd Bergmann
On Wed, Jun 19, 2024, at 22:50, Kees Cook wrote: > On Tue, Jun 18, 2024 at 04:41:01PM -0700, Jeff Johnson wrote: >> I see the following in my .config: >> CONFIG_HAVE_GCC_PLUGINS=y >> CONFIG_GCC_PLUGINS=y >> CONFIG_GCC_PLUGIN_LATENT_ENTROPY=y >> CONFIG_GCC_PLUGIN_RANDSTRUCT=y >> >> So I'll turn tho

Re: mips gcc plugin issues

2024-06-19 Thread Kees Cook
On Tue, Jun 18, 2024 at 04:41:01PM -0700, Jeff Johnson wrote: > I'm trying to do an allmodconfig build for ARCH=mips using: > https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/13.2.0/x86_64-gcc-13.2.0-nolibc-mips-linux.tar.gz > > This build dies quickly with: > CC scripts

Re: [PATCH v2 1/2] USB: serial: garmin_gps: annotate struct garmin_packet with __counted_by

2024-06-19 Thread Kees Cook
On Wed, Jun 19, 2024 at 09:42:44PM +0200, Javier Carrasco wrote: > Use the __counted_by compiler attribute for the data[] flexible array > member to improve the results of array bound sanitizers. > > Reviewed-by: Nathan Chancellor > Signed-off-by: Javier Carrasco Reviewed-by: Kees Cook -- Ke

Re: [PATCH v2 2/2] USB: serial: garmin_gps: use struct_size to allocate pkt

2024-06-19 Thread Kees Cook
On Wed, Jun 19, 2024 at 09:42:45PM +0200, Javier Carrasco wrote: > Use the struct_size macro to calculate the size of the pkt, which > includes a trailing flexible array. > > Suggested-by: Nathan Chancellor > Signed-off-by: Javier Carrasco Reviewed-by: Kees Cook -- Kees Cook

[PATCH] fortify: Do not special-case 0-sized destinations

2024-06-19 Thread Kees Cook
All fake flexible arrays should have been removed now, so remove the special casing that was avoiding checking them. If a destination claims to be 0 sized, believe it. This is especially important for cases where __counted_by is in use and may have a 0 element count. Signed-off-by: Kees Cook ---

Re: [PATCH v2 1/2] USB: serial: garmin_gps: annotate struct garmin_packet with __counted_by

2024-06-19 Thread Gustavo A. R. Silva
On 19/06/24 21:42, Javier Carrasco wrote: Use the __counted_by compiler attribute for the data[] flexible array member to improve the results of array bound sanitizers. Reviewed-by: Nathan Chancellor Signed-off-by: Javier Carrasco Reviewed-by: Gustavo A. R. Silva Thanks -- Gustavo ---

Re: [PATCH v2 2/2] USB: serial: garmin_gps: use struct_size to allocate pkt

2024-06-19 Thread Gustavo A. R. Silva
On 19/06/24 21:42, Javier Carrasco wrote: Use the struct_size macro to calculate the size of the pkt, which includes a trailing flexible array. Suggested-by: Nathan Chancellor Signed-off-by: Javier Carrasco Reviewed-by: Gustavo A. R. Silva Thanks -- Gustavo --- drivers/usb/serial/ga

[PATCH v2 2/2] USB: serial: garmin_gps: use struct_size to allocate pkt

2024-06-19 Thread Javier Carrasco
Use the struct_size macro to calculate the size of the pkt, which includes a trailing flexible array. Suggested-by: Nathan Chancellor Signed-off-by: Javier Carrasco --- drivers/usb/serial/garmin_gps.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/usb/serial/garmi

[PATCH v2 1/2] USB: serial: garmin_gps: annotate struct garmin_packet with __counted_by

2024-06-19 Thread Javier Carrasco
Use the __counted_by compiler attribute for the data[] flexible array member to improve the results of array bound sanitizers. Reviewed-by: Nathan Chancellor Signed-off-by: Javier Carrasco --- drivers/usb/serial/garmin_gps.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dr

[PATCH v2 0/2] USB: serial: garmin_gps: annotate struct garmin_packet with __counted_by

2024-06-19 Thread Javier Carrasco
://lore.kernel.org/r/20240619-garmin_gps_counted_by-v1-1-d8d816f08...@gmail.com --- Javier Carrasco (2): USB: serial: garmin_gps: annotate struct garmin_packet with __counted_by USB: serial: garmin_gps: use struct_size to allocate pkt drivers/usb/serial/garmin_gps.c | 5 ++--- 1 file changed, 2

[PATCH v5 5/6] ipc, msg: Use dedicated slab buckets for alloc_msg()

2024-06-19 Thread Kees Cook
The msg subsystem is a common target for exploiting[1][2][3][4][5][6][7] use-after-free type confusion flaws in the kernel for both read and write primitives. Avoid having a user-controlled dynamically-size allocation share the global kmalloc cache by using a separate set of kmalloc buckets via the

[PATCH v5 6/6] mm/util: Use dedicated slab buckets for memdup_user()

2024-06-19 Thread Kees Cook
Both memdup_user() and vmemdup_user() handle allocations that are regularly used for exploiting use-after-free type confusion flaws in the kernel (e.g. prctl() PR_SET_VMA_ANON_NAME[1] and setxattr[2][3][4] respectively). Since both are designed for contents coming from userspace, it allows for use

[PATCH v5 4/6] mm/slab: Introduce kmem_buckets_create() and family

2024-06-19 Thread Kees Cook
Dedicated caches are available for fixed size allocations via kmem_cache_alloc(), but for dynamically sized allocations there is only the global kmalloc API's set of buckets available. This means it isn't possible to separate specific sets of dynamically sized allocations into a separate collection

[PATCH v5 3/6] mm/slab: Introduce kvmalloc_buckets_node() that can take kmem_buckets argument

2024-06-19 Thread Kees Cook
Plumb kmem_buckets arguments through kvmalloc_node_noprof() so it is possible to provide an API to perform kvmalloc-style allocations with a particular set of buckets. Introduce kvmalloc_buckets_node() that takes a kmem_buckets argument. Signed-off-by: Kees Cook --- include/linux/slab.h | 4 +++-

[PATCH v5 2/6] mm/slab: Plumb kmem_buckets into __do_kmalloc_node()

2024-06-19 Thread Kees Cook
Introduce CONFIG_SLAB_BUCKETS which provides the infrastructure to support separated kmalloc buckets (in the following kmem_buckets_create() patches and future codetag-based separation). Since this will provide a mitigation for a very common case of exploits, enable it by default. To be able to ch

[PATCH v5 1/6] mm/slab: Introduce kmem_buckets typedef

2024-06-19 Thread Kees Cook
Encapsulate the concept of a single set of kmem_caches that are used for the kmalloc size buckets. Redefine kmalloc_caches as an array of these buckets (for the different global cache buckets). Signed-off-by: Kees Cook --- include/linux/slab.h | 5 +++-- mm/slab_common.c | 3 +-- 2 files cha

[PATCH v5 0/6] slab: Introduce dedicated bucket allocator

2024-06-19 Thread Kees Cook
Hi, v5: - Use vbabka's macros for optional arguments (thank you! I added a Co-developed-by and S-o-b) - Do not make Kconfig "default y", but recommend that it be enabled (vbabka) - Do not check for NULL before kmem_cache_destroy() on error path (horms) - Adjust size/bucket argument or

Re: [PATCH] USB: serial: garmin_gps: annotate struct garmin_packet with __counted_by

2024-06-19 Thread Javier Carrasco
On 19/06/2024 16:43, Nathan Chancellor wrote: > On Wed, Jun 19, 2024 at 11:40:57AM +0200, Javier Carrasco wrote: >> Use the __counted_by compiler attribute for the data[] flexible array member >> to improve the results of array bound sanitizers. >> >> Signed-off-by: Javier Carrasco >> --- >> The s

Re: [PATCH] USB: serial: garmin_gps: annotate struct garmin_packet with __counted_by

2024-06-19 Thread Gustavo A. R. Silva
On 19/06/24 16:43, Nathan Chancellor wrote: On Wed, Jun 19, 2024 at 11:40:57AM +0200, Javier Carrasco wrote: Use the __counted_by compiler attribute for the data[] flexible array member to improve the results of array bound sanitizers. Signed-off-by: Javier Carrasco --- The size is assigned

Re: [PATCH] USB: serial: garmin_gps: annotate struct garmin_packet with __counted_by

2024-06-19 Thread Nathan Chancellor
size; > - __u8 data[]; > + __u8 data[] __counted_by(size); > }; > > /* structure used to keep the current state of the driver */ > > --- > base-commit: 0c52056d9f77508cb6d4d68d3fc91c6c08ec71af > change-id: 20240619-garmin_gps_counted_by-376545960353 > > Best regards, > -- > Javier Carrasco >

Linux Sysadmin Offering Assistance in Kernel Security - Ready to Collaborate!

2024-06-19 Thread Nicolas Bianconi
Hello everyone, My name is Nicolas Bianconi, and I'm excited to join this community. You can learn more about me on my website: https://nicolasbianconi.com. To summarize my experience, I’ve been using Linux on both servers and desktops for over 7 years and have worked as a Linux systems adminis

[PATCH] USB: serial: garmin_gps: annotate struct garmin_packet with __counted_by

2024-06-19 Thread Javier Carrasco
eep the current state of the driver */ --- base-commit: 0c52056d9f77508cb6d4d68d3fc91c6c08ec71af change-id: 20240619-garmin_gps_counted_by-376545960353 Best regards, -- Javier Carrasco