* [PATCH] ksmbd: ipc: use kzalloc_flex and __counted_by
@ 2026-03-06 6:35 Rosen Penev
2026-03-25 5:03 ` Namjae Jeon
2026-03-25 6:26 ` Namjae Jeon
0 siblings, 2 replies; 4+ messages in thread
From: Rosen Penev @ 2026-03-06 6:35 UTC (permalink / raw)
To: linux-cifs
Cc: Namjae Jeon, Steve French, Sergey Senozhatsky, Tom Talpey,
Kees Cook, Gustavo A. R. Silva, open list,
open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b
The former is just a nice macro and the latter allows runtime analysis
of the allocation and its size.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
fs/smb/server/transport_ipc.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/fs/smb/server/transport_ipc.c b/fs/smb/server/transport_ipc.c
index 2dbabe2d8005..f7aa427a06fe 100644
--- a/fs/smb/server/transport_ipc.c
+++ b/fs/smb/server/transport_ipc.c
@@ -55,7 +55,7 @@ static bool ksmbd_ipc_validate_version(struct genl_info *m)
struct ksmbd_ipc_msg {
unsigned int type;
unsigned int sz;
- unsigned char payload[];
+ unsigned char payload[] __counted_by(sz);
};
struct ipc_msg_table_entry {
@@ -242,9 +242,8 @@ static void ipc_update_last_active(void)
static struct ksmbd_ipc_msg *ipc_msg_alloc(size_t sz)
{
struct ksmbd_ipc_msg *msg;
- size_t msg_sz = sz + sizeof(struct ksmbd_ipc_msg);
- msg = kvzalloc(msg_sz, KSMBD_DEFAULT_GFP);
+ msg = kvzalloc_flex(*msg, payload, sz, KSMBD_DEFAULT_GFP);
if (msg)
msg->sz = sz;
return msg;
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] ksmbd: ipc: use kzalloc_flex and __counted_by
2026-03-06 6:35 [PATCH] ksmbd: ipc: use kzalloc_flex and __counted_by Rosen Penev
@ 2026-03-25 5:03 ` Namjae Jeon
2026-03-25 6:26 ` Namjae Jeon
1 sibling, 0 replies; 4+ messages in thread
From: Namjae Jeon @ 2026-03-25 5:03 UTC (permalink / raw)
To: Rosen Penev
Cc: linux-cifs, Steve French, Sergey Senozhatsky, Tom Talpey,
Kees Cook, Gustavo A. R. Silva, open list,
open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b
On Fri, Mar 6, 2026 at 3:35 PM Rosen Penev <rosenp@gmail.com> wrote:
>
> The former is just a nice macro and the latter allows runtime analysis
> of the allocation and its size.
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
Applied it to #ksmbd-for-next-next.
Thanks!
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ksmbd: ipc: use kzalloc_flex and __counted_by
2026-03-06 6:35 [PATCH] ksmbd: ipc: use kzalloc_flex and __counted_by Rosen Penev
2026-03-25 5:03 ` Namjae Jeon
@ 2026-03-25 6:26 ` Namjae Jeon
2026-03-25 6:27 ` Rosen Penev
1 sibling, 1 reply; 4+ messages in thread
From: Namjae Jeon @ 2026-03-25 6:26 UTC (permalink / raw)
To: Rosen Penev
Cc: linux-cifs, Steve French, Sergey Senozhatsky, Tom Talpey,
Kees Cook, Gustavo A. R. Silva, open list,
open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b
On Fri, Mar 6, 2026 at 3:35 PM Rosen Penev <rosenp@gmail.com> wrote:
>
> The former is just a nice macro and the latter allows runtime analysis
> of the allocation and its size.
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
> fs/smb/server/transport_ipc.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/fs/smb/server/transport_ipc.c b/fs/smb/server/transport_ipc.c
> index 2dbabe2d8005..f7aa427a06fe 100644
> --- a/fs/smb/server/transport_ipc.c
> +++ b/fs/smb/server/transport_ipc.c
> @@ -55,7 +55,7 @@ static bool ksmbd_ipc_validate_version(struct genl_info *m)
> struct ksmbd_ipc_msg {
> unsigned int type;
> unsigned int sz;
> - unsigned char payload[];
> + unsigned char payload[] __counted_by(sz);
> };
>
> struct ipc_msg_table_entry {
> @@ -242,9 +242,8 @@ static void ipc_update_last_active(void)
> static struct ksmbd_ipc_msg *ipc_msg_alloc(size_t sz)
> {
> struct ksmbd_ipc_msg *msg;
> - size_t msg_sz = sz + sizeof(struct ksmbd_ipc_msg);
>
> - msg = kvzalloc(msg_sz, KSMBD_DEFAULT_GFP);
> + msg = kvzalloc_flex(*msg, payload, sz, KSMBD_DEFAULT_GFP);
> if (msg)
> msg->sz = sz;
We don't need to manually set msg->sz if the flexible array member is
properly annotated with __counted_by(sz) ?
kvmalloc_flex() automatically sets the counter via internal
__set_flex_counter().
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] ksmbd: ipc: use kzalloc_flex and __counted_by
2026-03-25 6:26 ` Namjae Jeon
@ 2026-03-25 6:27 ` Rosen Penev
0 siblings, 0 replies; 4+ messages in thread
From: Rosen Penev @ 2026-03-25 6:27 UTC (permalink / raw)
To: Namjae Jeon
Cc: linux-cifs, Steve French, Sergey Senozhatsky, Tom Talpey,
Kees Cook, Gustavo A. R. Silva, open list,
open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b
On Tue, Mar 24, 2026 at 11:26 PM Namjae Jeon <linkinjeon@kernel.org> wrote:
>
> On Fri, Mar 6, 2026 at 3:35 PM Rosen Penev <rosenp@gmail.com> wrote:
> >
> > The former is just a nice macro and the latter allows runtime analysis
> > of the allocation and its size.
> >
> > Signed-off-by: Rosen Penev <rosenp@gmail.com>
> > ---
> > fs/smb/server/transport_ipc.c | 5 ++---
> > 1 file changed, 2 insertions(+), 3 deletions(-)
> >
> > diff --git a/fs/smb/server/transport_ipc.c b/fs/smb/server/transport_ipc.c
> > index 2dbabe2d8005..f7aa427a06fe 100644
> > --- a/fs/smb/server/transport_ipc.c
> > +++ b/fs/smb/server/transport_ipc.c
> > @@ -55,7 +55,7 @@ static bool ksmbd_ipc_validate_version(struct genl_info *m)
> > struct ksmbd_ipc_msg {
> > unsigned int type;
> > unsigned int sz;
> > - unsigned char payload[];
> > + unsigned char payload[] __counted_by(sz);
> > };
> >
> > struct ipc_msg_table_entry {
> > @@ -242,9 +242,8 @@ static void ipc_update_last_active(void)
> > static struct ksmbd_ipc_msg *ipc_msg_alloc(size_t sz)
> > {
> > struct ksmbd_ipc_msg *msg;
> > - size_t msg_sz = sz + sizeof(struct ksmbd_ipc_msg);
> >
> > - msg = kvzalloc(msg_sz, KSMBD_DEFAULT_GFP);
> > + msg = kvzalloc_flex(*msg, payload, sz, KSMBD_DEFAULT_GFP);
> > if (msg)
> > msg->sz = sz;
> We don't need to manually set msg->sz if the flexible array member is
> properly annotated with __counted_by(sz) ?
> kvmalloc_flex() automatically sets the counter via internal
> __set_flex_counter().
Needs GCC15.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-03-25 6:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-06 6:35 [PATCH] ksmbd: ipc: use kzalloc_flex and __counted_by Rosen Penev
2026-03-25 5:03 ` Namjae Jeon
2026-03-25 6:26 ` Namjae Jeon
2026-03-25 6:27 ` Rosen Penev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox