public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: compression: Adjust cb->compressed_folios allocation type
@ 2025-04-26  6:23 Kees Cook
  2025-04-26  6:28 ` Qu Wenruo
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Kees Cook @ 2025-04-26  6:23 UTC (permalink / raw)
  To: Chris Mason
  Cc: Kees Cook, Josef Bacik, David Sterba, linux-btrfs, linux-kernel,
	linux-hardening

In preparation for making the kmalloc family of allocators type aware,
we need to make sure that the returned type from the allocation matches
the type of the variable being assigned. (Before, the allocator would
always return "void *", which can be implicitly cast to any pointer type.)

The assigned type is "struct folio **" but the returned type will be
"struct page **". These are the same allocation size (pointer size), but
the types don't match. Adjust the allocation type to match the assignment.

Signed-off-by: Kees Cook <kees@kernel.org>
---
Cc: Chris Mason <clm@fb.com>
Cc: Josef Bacik <josef@toxicpanda.com>
Cc: David Sterba <dsterba@suse.com>
Cc: <linux-btrfs@vger.kernel.org>
---
 fs/btrfs/compression.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index e7f8ee5d48a4..7f11ef559be6 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -606,7 +606,7 @@ void btrfs_submit_compressed_read(struct btrfs_bio *bbio)
 	free_extent_map(em);
 
 	cb->nr_folios = DIV_ROUND_UP(compressed_len, PAGE_SIZE);
-	cb->compressed_folios = kcalloc(cb->nr_folios, sizeof(struct page *), GFP_NOFS);
+	cb->compressed_folios = kcalloc(cb->nr_folios, sizeof(struct folio *), GFP_NOFS);
 	if (!cb->compressed_folios) {
 		ret = BLK_STS_RESOURCE;
 		goto out_free_bio;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] btrfs: compression: Adjust cb->compressed_folios allocation type
  2025-04-26  6:23 [PATCH] btrfs: compression: Adjust cb->compressed_folios allocation type Kees Cook
@ 2025-04-26  6:28 ` Qu Wenruo
  2025-04-26  6:55 ` Gustavo A. R. Silva
  2025-04-28 15:02 ` David Sterba
  2 siblings, 0 replies; 5+ messages in thread
From: Qu Wenruo @ 2025-04-26  6:28 UTC (permalink / raw)
  To: Kees Cook, Chris Mason
  Cc: Josef Bacik, David Sterba, linux-btrfs, linux-kernel,
	linux-hardening



在 2025/4/26 15:53, Kees Cook 写道:
> In preparation for making the kmalloc family of allocators type aware,
> we need to make sure that the returned type from the allocation matches
> the type of the variable being assigned. (Before, the allocator would
> always return "void *", which can be implicitly cast to any pointer type.)
> 
> The assigned type is "struct folio **" but the returned type will be
> "struct page **". These are the same allocation size (pointer size), but
> the types don't match. Adjust the allocation type to match the assignment.
> 
> Signed-off-by: Kees Cook <kees@kernel.org>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu

> ---
> Cc: Chris Mason <clm@fb.com>
> Cc: Josef Bacik <josef@toxicpanda.com>
> Cc: David Sterba <dsterba@suse.com>
> Cc: <linux-btrfs@vger.kernel.org>
> ---
>   fs/btrfs/compression.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
> index e7f8ee5d48a4..7f11ef559be6 100644
> --- a/fs/btrfs/compression.c
> +++ b/fs/btrfs/compression.c
> @@ -606,7 +606,7 @@ void btrfs_submit_compressed_read(struct btrfs_bio *bbio)
>   	free_extent_map(em);
>   
>   	cb->nr_folios = DIV_ROUND_UP(compressed_len, PAGE_SIZE);
> -	cb->compressed_folios = kcalloc(cb->nr_folios, sizeof(struct page *), GFP_NOFS);
> +	cb->compressed_folios = kcalloc(cb->nr_folios, sizeof(struct folio *), GFP_NOFS);
>   	if (!cb->compressed_folios) {
>   		ret = BLK_STS_RESOURCE;
>   		goto out_free_bio;


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] btrfs: compression: Adjust cb->compressed_folios allocation type
  2025-04-26  6:23 [PATCH] btrfs: compression: Adjust cb->compressed_folios allocation type Kees Cook
  2025-04-26  6:28 ` Qu Wenruo
@ 2025-04-26  6:55 ` Gustavo A. R. Silva
  2025-04-30 19:02   ` Kees Cook
  2025-04-28 15:02 ` David Sterba
  2 siblings, 1 reply; 5+ messages in thread
From: Gustavo A. R. Silva @ 2025-04-26  6:55 UTC (permalink / raw)
  To: Kees Cook, Chris Mason
  Cc: Josef Bacik, David Sterba, linux-btrfs, linux-kernel,
	linux-hardening



On 26/04/25 00:23, Kees Cook wrote:
> In preparation for making the kmalloc family of allocators type aware,
> we need to make sure that the returned type from the allocation matches
> the type of the variable being assigned. (Before, the allocator would
> always return "void *", which can be implicitly cast to any pointer type.)
> 
> The assigned type is "struct folio **" but the returned type will be
> "struct page **". These are the same allocation size (pointer size), but
> the types don't match. Adjust the allocation type to match the assignment.
> 
> Signed-off-by: Kees Cook <kees@kernel.org>
> ---
> Cc: Chris Mason <clm@fb.com>
> Cc: Josef Bacik <josef@toxicpanda.com>
> Cc: David Sterba <dsterba@suse.com>
> Cc: <linux-btrfs@vger.kernel.org>
> ---
>   fs/btrfs/compression.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
> index e7f8ee5d48a4..7f11ef559be6 100644
> --- a/fs/btrfs/compression.c
> +++ b/fs/btrfs/compression.c
> @@ -606,7 +606,7 @@ void btrfs_submit_compressed_read(struct btrfs_bio *bbio)
>   	free_extent_map(em);
>   
>   	cb->nr_folios = DIV_ROUND_UP(compressed_len, PAGE_SIZE);
> -	cb->compressed_folios = kcalloc(cb->nr_folios, sizeof(struct page *), GFP_NOFS);
> +	cb->compressed_folios = kcalloc(cb->nr_folios, sizeof(struct folio *), GFP_NOFS);

Why not `sizeof(*cb->compressed_folios)` as in other patches? :)

-Gustavo


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] btrfs: compression: Adjust cb->compressed_folios allocation type
  2025-04-26  6:23 [PATCH] btrfs: compression: Adjust cb->compressed_folios allocation type Kees Cook
  2025-04-26  6:28 ` Qu Wenruo
  2025-04-26  6:55 ` Gustavo A. R. Silva
@ 2025-04-28 15:02 ` David Sterba
  2 siblings, 0 replies; 5+ messages in thread
From: David Sterba @ 2025-04-28 15:02 UTC (permalink / raw)
  To: Kees Cook
  Cc: Chris Mason, Josef Bacik, David Sterba, linux-btrfs, linux-kernel,
	linux-hardening

On Fri, Apr 25, 2025 at 11:23:29PM -0700, Kees Cook wrote:
> In preparation for making the kmalloc family of allocators type aware,
> we need to make sure that the returned type from the allocation matches
> the type of the variable being assigned. (Before, the allocator would
> always return "void *", which can be implicitly cast to any pointer type.)
> 
> The assigned type is "struct folio **" but the returned type will be
> "struct page **". These are the same allocation size (pointer size), but
> the types don't match. Adjust the allocation type to match the assignment.
> 
> Signed-off-by: Kees Cook <kees@kernel.org>

Added to for-next, thanks.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] btrfs: compression: Adjust cb->compressed_folios allocation type
  2025-04-26  6:55 ` Gustavo A. R. Silva
@ 2025-04-30 19:02   ` Kees Cook
  0 siblings, 0 replies; 5+ messages in thread
From: Kees Cook @ 2025-04-30 19:02 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Chris Mason, Josef Bacik, David Sterba, linux-btrfs, linux-kernel,
	linux-hardening

On Sat, Apr 26, 2025 at 12:55:21AM -0600, Gustavo A. R. Silva wrote:
> 
> 
> On 26/04/25 00:23, Kees Cook wrote:
> > In preparation for making the kmalloc family of allocators type aware,
> > we need to make sure that the returned type from the allocation matches
> > the type of the variable being assigned. (Before, the allocator would
> > always return "void *", which can be implicitly cast to any pointer type.)
> > 
> > The assigned type is "struct folio **" but the returned type will be
> > "struct page **". These are the same allocation size (pointer size), but
> > the types don't match. Adjust the allocation type to match the assignment.
> > 
> > Signed-off-by: Kees Cook <kees@kernel.org>
> > ---
> > Cc: Chris Mason <clm@fb.com>
> > Cc: Josef Bacik <josef@toxicpanda.com>
> > Cc: David Sterba <dsterba@suse.com>
> > Cc: <linux-btrfs@vger.kernel.org>
> > ---
> >   fs/btrfs/compression.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
> > index e7f8ee5d48a4..7f11ef559be6 100644
> > --- a/fs/btrfs/compression.c
> > +++ b/fs/btrfs/compression.c
> > @@ -606,7 +606,7 @@ void btrfs_submit_compressed_read(struct btrfs_bio *bbio)
> >   	free_extent_map(em);
> >   	cb->nr_folios = DIV_ROUND_UP(compressed_len, PAGE_SIZE);
> > -	cb->compressed_folios = kcalloc(cb->nr_folios, sizeof(struct page *), GFP_NOFS);
> > +	cb->compressed_folios = kcalloc(cb->nr_folios, sizeof(struct folio *), GFP_NOFS);
> 
> Why not `sizeof(*cb->compressed_folios)` as in other patches? :)

I generally trying to match the coding style of each instance, though
sometimes it wasn't possible. Here, since a type is named for the
sizeof(), I followed that style.

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-04-30 19:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-26  6:23 [PATCH] btrfs: compression: Adjust cb->compressed_folios allocation type Kees Cook
2025-04-26  6:28 ` Qu Wenruo
2025-04-26  6:55 ` Gustavo A. R. Silva
2025-04-30 19:02   ` Kees Cook
2025-04-28 15:02 ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox