The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH rdma-rc] RDMA/rxe: Zero struct rxe_mmap_info on allocation
@ 2026-11-23 14:06 Andrew Stellman
  2026-11-24 21:41 ` Zhu Yanjun
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Stellman @ 2026-11-23 14:06 UTC (permalink / raw)
  To: Zhu Yanjun
  Cc: Zhu Yanjun, Jason Gunthorpe, Leon Romanovsky, linux-rdma,
	linux-kernel

rxe_create_mmap_info() allocates the structure with kmalloc_obj() and
does not set info.pad. do_mmap_info() copies ip->info to userspace with
copy_to_user(), so the 4 pad bytes of struct mminfo come from
uninitialized kernel heap memory.

On x86_64 v7.4-rc3 under QEMU with init_on_alloc=0, an unprivileged
user (CapEff 0) issued 300 CQ_CREATE ioctls on rxe0 and read the driver
response. After the guest had run ls -lR on /proc and /sys and read
/proc/*/status and /proc/*/stat, 101 of the 300 pads were nonzero. In a
separate boot with slub_debug=P, all 300 pads were 0x6b6b6b6b. With
this patch, all 300 pads were zero in both configurations.

Allocate the structure with kzalloc_obj() so the pad is zero.

The issue was found by Claude Opus 5.5 running Quality Playbook, an LLM-driven code review tool:
https://github.com/andrewstellman/quality-playbook
The fix and this changelog were drafted with Claude Sonnet 5.5 and reviewed by me.

Fixes: 8700e3e7c485 ("Soft RoCE driver")
Signed-off-by: Andrew Stellman <astellman@stellman-greene.com>
---
A reproducer is available on request.

 drivers/infiniband/sw/rxe/rxe_mmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/infiniband/sw/rxe/rxe_mmap.c b/drivers/infiniband/sw/rxe/rxe_mmap.c
index a4ead89cc..ac851f245 100644
--- a/drivers/infiniband/sw/rxe/rxe_mmap.c
+++ b/drivers/infiniband/sw/rxe/rxe_mmap.c
@@ -102,7 +102,7 @@ struct rxe_mmap_info *rxe_create_mmap_info(struct rxe_dev *rxe, u32 size,
 	if (!udata)
 		return ERR_PTR(-EINVAL);
 
-	ip = kmalloc_obj(*ip);
+	ip = kzalloc_obj(*ip);
 	if (!ip)
 		return ERR_PTR(-ENOMEM);
 
-- 
2.43.0


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

* Re: [PATCH rdma-rc] RDMA/rxe: Zero struct rxe_mmap_info on allocation
  2026-11-23 14:06 [PATCH rdma-rc] RDMA/rxe: Zero struct rxe_mmap_info on allocation Andrew Stellman
@ 2026-11-24 21:41 ` Zhu Yanjun
  2026-11-24 21:46   ` Andrew Stellman
  0 siblings, 1 reply; 3+ messages in thread
From: Zhu Yanjun @ 2026-11-24 21:41 UTC (permalink / raw)
  To: Andrew Stellman, Zhu Yanjun, yanjun.zhu@linux.dev
  Cc: Jason Gunthorpe, Leon Romanovsky, linux-rdma, linux-kernel

在 2026/11/23 6:06, Andrew Stellman 写道:
> rxe_create_mmap_info() allocates the structure with kmalloc_obj() and
> does not set info.pad. do_mmap_info() copies ip->info to userspace with
> copy_to_user(), so the 4 pad bytes of struct mminfo come from
> uninitialized kernel heap memory.
> 
> On x86_64 v7.4-rc3 under QEMU with init_on_alloc=0, an unprivileged
> user (CapEff 0) issued 300 CQ_CREATE ioctls on rxe0 and read the driver
> response. After the guest had run ls -lR on /proc and /sys and read
> /proc/*/status and /proc/*/stat, 101 of the 300 pads were nonzero. In a
> separate boot with slub_debug=P, all 300 pads were 0x6b6b6b6b. With
> this patch, all 300 pads were zero in both configurations.
> 
> Allocate the structure with kzalloc_obj() so the pad is zero.
> 
> The issue was found by Claude Opus 5.5 running Quality Playbook, an LLM-driven code review tool:
> https://github.com/andrewstellman/quality-playbook
> The fix and this changelog were drafted with Claude Sonnet 5.5 and reviewed by me.
> 
> Fixes: 8700e3e7c485 ("Soft RoCE driver")
> Signed-off-by: Andrew Stellman <astellman@stellman-greene.com>
> ---
> A reproducer is available on request.
> 
>   drivers/infiniband/sw/rxe/rxe_mmap.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/infiniband/sw/rxe/rxe_mmap.c b/drivers/infiniband/sw/rxe/rxe_mmap.c
> index a4ead89cc..ac851f245 100644
> --- a/drivers/infiniband/sw/rxe/rxe_mmap.c
> +++ b/drivers/infiniband/sw/rxe/rxe_mmap.c
> @@ -102,7 +102,7 @@ struct rxe_mmap_info *rxe_create_mmap_info(struct rxe_dev *rxe, u32 size,
>   	if (!udata)
>   		return ERR_PTR(-EINVAL);
>   
> -	ip = kmalloc_obj(*ip);
> +	ip = kzalloc_obj(*ip);

Nice catch, thanks a lot. Could you also check for other unzeroed memory 
allocations like this and fix them?

Reviewed-by: Zhu Yanjun <yanjun.zhu@linux.dev>

Zhu Yanjun

>   	if (!ip)
>   		return ERR_PTR(-ENOMEM);
>   


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

* Re: [PATCH rdma-rc] RDMA/rxe: Zero struct rxe_mmap_info on allocation
  2026-11-24 21:41 ` Zhu Yanjun
@ 2026-11-24 21:46   ` Andrew Stellman
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew Stellman @ 2026-11-24 21:46 UTC (permalink / raw)
  To: Zhu Yanjun
  Cc: Zhu Yanjun, Jason Gunthorpe, Leon Romanovsky, linux-rdma,
	linux-kernel

Thanks for the review. I'll go through rxe for other unzeroed
allocations and send anything I find as separate patches.

On Tue, Nov 24, 2026 at 4:41 PM Zhu Yanjun <yanjun.zhu@linux.dev> wrote:
>
> 在 2026/11/23 6:06, Andrew Stellman 写道:
> > rxe_create_mmap_info() allocates the structure with kmalloc_obj() and
> > does not set info.pad. do_mmap_info() copies ip->info to userspace with
> > copy_to_user(), so the 4 pad bytes of struct mminfo come from
> > uninitialized kernel heap memory.
> >
> > On x86_64 v7.4-rc3 under QEMU with init_on_alloc=0, an unprivileged
> > user (CapEff 0) issued 300 CQ_CREATE ioctls on rxe0 and read the driver
> > response. After the guest had run ls -lR on /proc and /sys and read
> > /proc/*/status and /proc/*/stat, 101 of the 300 pads were nonzero. In a
> > separate boot with slub_debug=P, all 300 pads were 0x6b6b6b6b. With
> > this patch, all 300 pads were zero in both configurations.
> >
> > Allocate the structure with kzalloc_obj() so the pad is zero.
> >
> > The issue was found by Claude Opus 5.5 running Quality Playbook, an LLM-driven code review tool:
> > https://github.com/andrewstellman/quality-playbook
> > The fix and this changelog were drafted with Claude Sonnet 5.5 and reviewed by me.
> >
> > Fixes: 8700e3e7c485 ("Soft RoCE driver")
> > Signed-off-by: Andrew Stellman <astellman@stellman-greene.com>
> > ---
> > A reproducer is available on request.
> >
> >   drivers/infiniband/sw/rxe/rxe_mmap.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/infiniband/sw/rxe/rxe_mmap.c b/drivers/infiniband/sw/rxe/rxe_mmap.c
> > index a4ead89cc..ac851f245 100644
> > --- a/drivers/infiniband/sw/rxe/rxe_mmap.c
> > +++ b/drivers/infiniband/sw/rxe/rxe_mmap.c
> > @@ -102,7 +102,7 @@ struct rxe_mmap_info *rxe_create_mmap_info(struct rxe_dev *rxe, u32 size,
> >       if (!udata)
> >               return ERR_PTR(-EINVAL);
> >
> > -     ip = kmalloc_obj(*ip);
> > +     ip = kzalloc_obj(*ip);
>
> Nice catch, thanks a lot. Could you also check for other unzeroed memory
> allocations like this and fix them?
>
> Reviewed-by: Zhu Yanjun <yanjun.zhu@linux.dev>
>
> Zhu Yanjun
>
> >       if (!ip)
> >               return ERR_PTR(-ENOMEM);
> >
>

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

end of thread, other threads:[~2026-11-24 21:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 14:06 [PATCH rdma-rc] RDMA/rxe: Zero struct rxe_mmap_info on allocation Andrew Stellman
2026-11-24 21:41 ` Zhu Yanjun
2026-11-24 21:46   ` Andrew Stellman

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