* [RESEND PATCH] ext4: Annotate struct fname with __counted_by()
@ 2024-11-04 23:42 Thorsten Blum
2024-11-05 9:52 ` Greg KH
0 siblings, 1 reply; 5+ messages in thread
From: Thorsten Blum @ 2024-11-04 23:42 UTC (permalink / raw)
To: Theodore Ts'o, Andreas Dilger, Kees Cook, Gustavo A. R. Silva
Cc: Thorsten Blum, Jan Kara, linux-ext4, linux-kernel,
linux-hardening
Add the __counted_by compiler attribute to the flexible array member
name to improve access bounds-checking via CONFIG_UBSAN_BOUNDS and
CONFIG_FORTIFY_SOURCE.
Inline and use struct_size() to calculate the number of bytes to
allocate for new_fn and remove the local variable len.
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
fs/ext4/dir.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
index ef6a3c8f3a9a..02d47a64e8d1 100644
--- a/fs/ext4/dir.c
+++ b/fs/ext4/dir.c
@@ -418,7 +418,7 @@ struct fname {
__u32 inode;
__u8 name_len;
__u8 file_type;
- char name[];
+ char name[] __counted_by(name_len);
};
/*
@@ -471,14 +471,13 @@ int ext4_htree_store_dirent(struct file *dir_file, __u32 hash,
struct rb_node **p, *parent = NULL;
struct fname *fname, *new_fn;
struct dir_private_info *info;
- int len;
info = dir_file->private_data;
p = &info->root.rb_node;
/* Create and allocate the fname structure */
- len = sizeof(struct fname) + ent_name->len + 1;
- new_fn = kzalloc(len, GFP_KERNEL);
+ new_fn = kzalloc(struct_size(new_fn, name, ent_name->len + 1),
+ GFP_KERNEL);
if (!new_fn)
return -ENOMEM;
new_fn->hash = hash;
--
2.47.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [RESEND PATCH] ext4: Annotate struct fname with __counted_by()
2024-11-04 23:42 [RESEND PATCH] ext4: Annotate struct fname with __counted_by() Thorsten Blum
@ 2024-11-05 9:52 ` Greg KH
2024-11-05 10:17 ` Thorsten Blum
0 siblings, 1 reply; 5+ messages in thread
From: Greg KH @ 2024-11-05 9:52 UTC (permalink / raw)
To: Thorsten Blum
Cc: Theodore Ts'o, Andreas Dilger, Kees Cook, Gustavo A. R. Silva,
Jan Kara, linux-ext4, linux-kernel, linux-hardening
On Tue, Nov 05, 2024 at 12:42:14AM +0100, Thorsten Blum wrote:
> Add the __counted_by compiler attribute to the flexible array member
> name to improve access bounds-checking via CONFIG_UBSAN_BOUNDS and
> CONFIG_FORTIFY_SOURCE.
>
> Inline and use struct_size() to calculate the number of bytes to
> allocate for new_fn and remove the local variable len.
This is two different things, why not do this in two different patches?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RESEND PATCH] ext4: Annotate struct fname with __counted_by()
2024-11-05 9:52 ` Greg KH
@ 2024-11-05 10:17 ` Thorsten Blum
0 siblings, 0 replies; 5+ messages in thread
From: Thorsten Blum @ 2024-11-05 10:17 UTC (permalink / raw)
To: Greg KH
Cc: Theodore Ts'o, Andreas Dilger, Kees Cook, Gustavo A. R. Silva,
Jan Kara, linux-ext4, linux-kernel, linux-hardening
On 5. Nov 2024, at 10:52, Greg KH wrote:
> On Tue, Nov 05, 2024 at 12:42:14AM +0100, Thorsten Blum wrote:
>> Add the __counted_by compiler attribute to the flexible array member
>> name to improve access bounds-checking via CONFIG_UBSAN_BOUNDS and
>> CONFIG_FORTIFY_SOURCE.
>>
>> Inline and use struct_size() to calculate the number of bytes to
>> allocate for new_fn and remove the local variable len.
>
> This is two different things, why not do this in two different patches?
>
> thanks,
>
> greg k-h
No particular reason. I'll submit a v2 for the __counted_by() annotation
and a separate patch for struct_size().
I'll keep Jan's Reviewed-by: tag for both.
Thanks,
Thorsten
^ permalink raw reply [flat|nested] 5+ messages in thread
* [RESEND PATCH] ext4: Annotate struct fname with __counted_by()
@ 2024-10-22 7:52 Thorsten Blum
0 siblings, 0 replies; 5+ messages in thread
From: Thorsten Blum @ 2024-10-22 7:52 UTC (permalink / raw)
To: Theodore Ts'o, Andreas Dilger, Kees Cook, Gustavo A. R. Silva
Cc: Thorsten Blum, Jan Kara, linux-ext4, linux-kernel,
linux-hardening
Add the __counted_by compiler attribute to the flexible array member
name to improve access bounds-checking via CONFIG_UBSAN_BOUNDS and
CONFIG_FORTIFY_SOURCE.
Inline and use struct_size() to calculate the number of bytes to
allocate for new_fn and remove the local variable len.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Reviewed-by: Jan Kara <jack@suse.cz>
---
fs/ext4/dir.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
index ef6a3c8f3a9a..02d47a64e8d1 100644
--- a/fs/ext4/dir.c
+++ b/fs/ext4/dir.c
@@ -418,7 +418,7 @@ struct fname {
__u32 inode;
__u8 name_len;
__u8 file_type;
- char name[];
+ char name[] __counted_by(name_len);
};
/*
@@ -471,14 +471,13 @@ int ext4_htree_store_dirent(struct file *dir_file, __u32 hash,
struct rb_node **p, *parent = NULL;
struct fname *fname, *new_fn;
struct dir_private_info *info;
- int len;
info = dir_file->private_data;
p = &info->root.rb_node;
/* Create and allocate the fname structure */
- len = sizeof(struct fname) + ent_name->len + 1;
- new_fn = kzalloc(len, GFP_KERNEL);
+ new_fn = kzalloc(struct_size(new_fn, name, ent_name->len + 1),
+ GFP_KERNEL);
if (!new_fn)
return -ENOMEM;
new_fn->hash = hash;
--
2.47.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* [RESEND PATCH] ext4: Annotate struct fname with __counted_by()
@ 2024-10-07 13:07 Thorsten Blum
0 siblings, 0 replies; 5+ messages in thread
From: Thorsten Blum @ 2024-10-07 13:07 UTC (permalink / raw)
To: Theodore Ts'o, Andreas Dilger, Kees Cook, Gustavo A. R. Silva
Cc: Thorsten Blum, Jan Kara, linux-ext4, linux-kernel,
linux-hardening
Add the __counted_by compiler attribute to the flexible array member
name to improve access bounds-checking via CONFIG_UBSAN_BOUNDS and
CONFIG_FORTIFY_SOURCE.
Inline and use struct_size() to calculate the number of bytes to
allocate for new_fn and remove the local variable len.
Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
Reviewed-by: Jan Kara <jack@suse.cz>
---
fs/ext4/dir.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
index ef6a3c8f3a9a..02d47a64e8d1 100644
--- a/fs/ext4/dir.c
+++ b/fs/ext4/dir.c
@@ -418,7 +418,7 @@ struct fname {
__u32 inode;
__u8 name_len;
__u8 file_type;
- char name[];
+ char name[] __counted_by(name_len);
};
/*
@@ -471,14 +471,13 @@ int ext4_htree_store_dirent(struct file *dir_file, __u32 hash,
struct rb_node **p, *parent = NULL;
struct fname *fname, *new_fn;
struct dir_private_info *info;
- int len;
info = dir_file->private_data;
p = &info->root.rb_node;
/* Create and allocate the fname structure */
- len = sizeof(struct fname) + ent_name->len + 1;
- new_fn = kzalloc(len, GFP_KERNEL);
+ new_fn = kzalloc(struct_size(new_fn, name, ent_name->len + 1),
+ GFP_KERNEL);
if (!new_fn)
return -ENOMEM;
new_fn->hash = hash;
--
2.46.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-11-05 10:17 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-04 23:42 [RESEND PATCH] ext4: Annotate struct fname with __counted_by() Thorsten Blum
2024-11-05 9:52 ` Greg KH
2024-11-05 10:17 ` Thorsten Blum
-- strict thread matches above, loose matches on Subject: below --
2024-10-22 7:52 Thorsten Blum
2024-10-07 13:07 Thorsten Blum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).