RDMA/bnxt_re: Fix input validation and lifetime bugs
Subsystems (2)
Selvin Xavier
maintainercover RDMA/bnxt_re: Fix input validation and lifetime bugs
This series fixes some of the bugs found while auditing bnxt_re's handling of user-supplied values and object/device lifetimes.
Please review and apply the series.
Thanks,
Selvin Xavier
Selvin Xavier (8):
RDMA/bnxt_re: Reject executable mappings of the DBR and toggle pages RDMA/bnxt_re: Detect wrong sge_len passed for inline RDMA/bnxt_re: Validate num_sge in bnxt_re_post_srq_recv() RDMA/bnxt_re: Validate SRQ max_sge at create time RDMA/bnxt_re: Fix rdev lifetime races in suspend/resume/shutdown RDMA/bnxt_re: Fix the PD and DPI table size
RDMA/bnxt_re: Use bnxt_ext_stats_supported for counter count selection RDMA/bnxt_re: Check is_in_used before trusting RCFW completion
drivers/infiniband/hw/bnxt_re/hw_counters.c | 6 ++-- drivers/infiniband/hw/bnxt_re/ib_verbs.c | 28 ++++++++++++++---- drivers/infiniband/hw/bnxt_re/main.c | 32 ++++++++++++++++----- drivers/infiniband/hw/bnxt_re/qplib_rcfw.c | 12 +++++--- drivers/infiniband/hw/bnxt_re/qplib_res.c | 9 +++--- drivers/infiniband/hw/bnxt_re/qplib_sp.c | 2 +- 6 files changed, 65 insertions(+), 24 deletions(-)
Signature · 1 line
2.39.3
Selvin Xavier
maintainerPATCH 1/8 RDMA/bnxt_re: Reject executable mappings of the DBR and toggle pages
The BNXT_RE_MMAP_DBR_PAGE and BNXT_RE_MMAP_TOGGLE_PAGE cases of bnxt_re_mmap() hand out kernel pages that userspace is only supposed to read. VM_WRITE was already rejected, but VM_EXEC was not, so userspace could map these kernel pages executable. Reject VM_EXEC as well. Also, return EPERM instead of EFAULT.
--- drivers/infiniband/hw/bnxt_re/ib_verbs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/infiniband/hw/bnxt_re/ib_verbs.c +4 -4
@@ -5057,11 +5057,11 @@ int bnxt_re_mmap(struct ib_ucontext *ib_uctx, struct vm_area_struct *vma)break ;case BNXT_RE_MMAP_DBR_PAGE :case BNXT_RE_MMAP_TOGGLE_PAGE : -/* Driver doesn't expect write access for user space */ -if (vma->vm_flags &VM_WRITE ) { - ret = -EFAULT ; +/* Driver doesn't expect write and exec access for user space */ +if (vma->vm_flags & (VM_WRITE |VM_EXEC )) { + ret = -EPERM ; }else { -vm_flags_clear (vma,VM_MAYWRITE ); +vm_flags_clear (vma,VM_MAYWRITE |VM_MAYEXEC ); ret =vm_insert_page (vma, vma->vm_start,virt_to_page ((void *)bnxt_entry->mem_offset)); }
Signature · 1 line
2.39.3
Re: [PATCH for-rc 1/8] RDMA/bnxt_re: Reject executable mappings of the DBR and toggle pages
Quoted 21 lines · Selvin Xavier
The
BNXT_RE_MMAP_DBR_PAGEandBNXT_RE_MMAP_TOGGLE_PAGEcases ofbnxt_re_mmap()hand out kernel pages that userspace is only supposed to read.VM_WRITEwas already rejected, butVM_EXECwas not, so userspace could map these kernel pages executable. RejectVM_EXECas well. Also, return EPERM instead of EFAULT.Fixes 9b66c9af7172 ("RDMA/bnxt_re: Clear VM_MAYWRITE on DBR/toggle page mmap")CC Yousef Alhouseen <[email protected]>Reviewed-by Kalesh AP <[email protected]>Signed-off-by Selvin Xavier <[email protected]>--- drivers/infiniband/hw/bnxt_re/ib_verbs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/infiniband/hw/bnxt_re/ib_verbs.c +0
-0@@ -5057,11 +5057,11 @@ int bnxt_re_mmap(struct ib_ucontext *ib_uctx, struct vm_area_struct *vma)break ;case BNXT_RE_MMAP_DBR_PAGE :
drivers/infiniband/hw/bnxt_re/ib_verbs.c int bnxt_re_mmap(struct ib_ucontext *ib_uctx, struct vm_area_struct *vma) · line 5064
Quoted 10 lines
drivers/infiniband/hw/bnxt_re/ib_verbs.c +4
-4case BNXT_RE_MMAP_TOGGLE_PAGE : -/* Driver doesn't expect write access for user space */ -if (vma->vm_flags &VM_WRITE ) { - ret = -EFAULT ; +/* Driver doesn't expect write and exec access for user space */ +if (vma->vm_flags & (VM_WRITE |VM_EXEC )) { + ret = -EPERM ; }else { -vm_flags_clear (vma,VM_MAYWRITE ); +vm_flags_clear (vma,VM_MAYWRITE |VM_MAYEXEC );
This is an opposite to 10bf13c33450 ("RDMA/mlx5: Remove MAYEXEC flag") commit.
Thanks
Quoted 6 lines
drivers/infiniband/hw/bnxt_re/ib_verbs.c +0
-0ret =vm_insert_page (vma, vma->vm_start,virt_to_page ((void *)bnxt_entry->mem_offset)); }Signature · 1 line
2.39.3
Selvin Xavier
maintainerRe: [PATCH for-rc 1/8] RDMA/bnxt_re: Reject executable mappings of the DBR and toggle pages
Quoted 37 lines · Leon Romanovsky
Quoted 7 lines · Selvin Xavier
The
BNXT_RE_MMAP_DBR_PAGEandBNXT_RE_MMAP_TOGGLE_PAGEcases ofbnxt_re_mmap()hand out kernel pages that userspace is only supposed to read.VM_WRITEwas already rejected, butVM_EXECwas not, so userspace could map these kernel pages executable. RejectVM_EXECas well. Also, return EPERM instead of EFAULT.Fixes 9b66c9af7172 ("RDMA/bnxt_re: Clear VM_MAYWRITE on DBR/toggle pagemmap")
Review
Quoted 8 lines
CC Yousef Alhouseen <[email protected]>Reviewed-by Kalesh AP <[email protected]>Signed-off-by Selvin Xavier <[email protected]>--- drivers/infiniband/hw/bnxt_re/ib_verbs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)(quoted diff) +0
-0
b/drivers/infiniband/hw/bnxt_re/ib_verbs.cdrivers/infiniband/hw/bnxt_re/ib_verbs.c int bnxt_re_mmap(struct ib_ucontext *ib_uctx,
Quoted 4 lines
index
ccd2702db78b..e39f99434923100644drivers/infiniband/hw/bnxt_re/ib_verbs.c +0
-0@@ -5057,11 +5057,11 @@ int bnxt_re_mmap(struct ib_ucontext *ib_uctx,struct
vm_area_struct*vma)drivers/infiniband/hw/bnxt_re/ib_verbs.c int bnxt_re_mmap(struct ib_ucontext *ib_uctx, struct vm_area_struct *vma)
Quoted 7 lines
drivers/infiniband/hw/bnxt_re/ib_verbs.c +1
-3break ;case BNXT_RE_MMAP_DBR_PAGE :case BNXT_RE_MMAP_TOGGLE_PAGE : -/* Driver doesn't expect write access for user space */ -if (vma->vm_flags &VM_WRITE ) { - ret = -EFAULT ; +/* Driver doesn't expect write and exec access for user space */
drivers/infiniband/hw/bnxt_re/ib_verbs.c int bnxt_re_mmap(struct ib_ucontext *ib_uctx, struct vm_area_struct *vma) · line 5064
Quoted 5 lines
drivers/infiniband/hw/bnxt_re/ib_verbs.c +3
-1+if (vma->vm_flags & (VM_WRITE |VM_EXEC )) { + ret = -EPERM ; }else { -vm_flags_clear (vma,VM_MAYWRITE ); +vm_flags_clear (vma,VM_MAYWRITE |VM_MAYEXEC );
Quoted 5 lines
This is an opposite to
10bf13c33450("RDMA/mlx5: Remove MAYEXEC flag") commit.Thanks
ok.. will remove this and post v2.
Quoted 9 lines
drivers/infiniband/hw/bnxt_re/ib_verbs.c int bnxt_re_mmap(struct ib_ucontext *ib_uctx, · line 5066
Quoted 3 lines
drivers/infiniband/hw/bnxt_re/ib_verbs.c +0
-0ret = vm_insert_page(vma, vma->vm_start, virt_to_page((void*)bnxt_entry->mem_offset));
Quoted 4 lines
drivers/infiniband/hw/bnxt_re/ib_verbs.c +0
-1} --2.39.3
Re: [PATCH for-rc 1/8] RDMA/bnxt_re: Reject executable mappings of the DBR and toggle pages
In reply to Leon RomanovskyQuoted 27 lines · Leon Romanovsky
Quoted 26 lines · Selvin Xavier
The
BNXT_RE_MMAP_DBR_PAGEandBNXT_RE_MMAP_TOGGLE_PAGEcases ofbnxt_re_mmap()hand out kernel pages that userspace is only supposed to read.VM_WRITEwas already rejected, butVM_EXECwas not, so userspace could map these kernel pages executable. RejectVM_EXECas well. Also, return EPERM instead of EFAULT.Fixes 9b66c9af7172 ("RDMA/bnxt_re: Clear VM_MAYWRITE on DBR/toggle page mmap")CC Yousef Alhouseen <[email protected]>Reviewed-by Kalesh AP <[email protected]>Signed-off-by Selvin Xavier <[email protected]>--- drivers/infiniband/hw/bnxt_re/ib_verbs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/infiniband/hw/bnxt_re/ib_verbs.c +1
-3@@ -5057,11 +5057,11 @@ int bnxt_re_mmap(struct ib_ucontext *ib_uctx, struct vm_area_struct *vma)break ;case BNXT_RE_MMAP_DBR_PAGE :case BNXT_RE_MMAP_TOGGLE_PAGE : -/* Driver doesn't expect write access for user space */ -if (vma->vm_flags &VM_WRITE ) { - ret = -EFAULT ; +/* Driver doesn't expect write and exec access for user space */
Quoted 8 lines
drivers/infiniband/hw/bnxt_re/ib_verbs.c int bnxt_re_mmap(struct ib_ucontext *ib_uctx, struct vm_area_struct *vma) · line 5064
Quoted 5 lines
drivers/infiniband/hw/bnxt_re/ib_verbs.c +3
-1+if (vma->vm_flags & (VM_WRITE |VM_EXEC )) { + ret = -EPERM ; }else { -vm_flags_clear (vma,VM_MAYWRITE ); +vm_flags_clear (vma,VM_MAYWRITE |VM_MAYEXEC );This is an opposite to
10bf13c33450("RDMA/mlx5: Remove MAYEXEC flag") commit.
Why did we do that? These MMIO mmap should never be executable
Jason
Re: [PATCH for-rc 1/8] RDMA/bnxt_re: Reject executable mappings of the DBR and toggle pages
Quoted 37 lines · Jason Gunthorpe
Quoted 27 lines · Leon Romanovsky
Quoted 26 lines · Selvin Xavier
The
BNXT_RE_MMAP_DBR_PAGEandBNXT_RE_MMAP_TOGGLE_PAGEcases ofbnxt_re_mmap()hand out kernel pages that userspace is only supposed to read.VM_WRITEwas already rejected, butVM_EXECwas not, so userspace could map these kernel pages executable. RejectVM_EXECas well. Also, return EPERM instead of EFAULT.Fixes 9b66c9af7172 ("RDMA/bnxt_re: Clear VM_MAYWRITE on DBR/toggle page mmap")CC Yousef Alhouseen <[email protected]>Reviewed-by Kalesh AP <[email protected]>Signed-off-by Selvin Xavier <[email protected]>--- drivers/infiniband/hw/bnxt_re/ib_verbs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/infiniband/hw/bnxt_re/ib_verbs.c +1
-3@@ -5057,11 +5057,11 @@ int bnxt_re_mmap(struct ib_ucontext *ib_uctx, struct vm_area_struct *vma)break ;case BNXT_RE_MMAP_DBR_PAGE :case BNXT_RE_MMAP_TOGGLE_PAGE : -/* Driver doesn't expect write access for user space */ -if (vma->vm_flags &VM_WRITE ) { - ret = -EFAULT ; +/* Driver doesn't expect write and exec access for user space */ Quoted 8 lines
drivers/infiniband/hw/bnxt_re/ib_verbs.c int bnxt_re_mmap(struct ib_ucontext *ib_uctx, struct vm_area_struct *vma) · line 5064
Quoted 5 lines
drivers/infiniband/hw/bnxt_re/ib_verbs.c +3
-1+if (vma->vm_flags & (VM_WRITE |VM_EXEC )) { + ret = -EPERM ; }else { -vm_flags_clear (vma,VM_MAYWRITE ); +vm_flags_clear (vma,VM_MAYWRITE |VM_MAYEXEC );This is an opposite to
10bf13c33450("RDMA/mlx5: Remove MAYEXEC flag") commit.
Quoted 1 line
Why did we do that? These MMIO mmap should never be executable
I don't remember the rationale, but if I understood my findings correctly, clearing VM_MAYEXEC broke memcopy.
Thanks
Re: [PATCH for-rc 1/8] RDMA/bnxt_re: Reject executable mappings of the DBR and toggle pages
Quoted 38 lines · Leon Romanovsky
Quoted 37 lines · Jason Gunthorpe
Quoted 35 lines · Leon Romanovsky
Quoted 21 lines · Selvin Xavier
The
BNXT_RE_MMAP_DBR_PAGEandBNXT_RE_MMAP_TOGGLE_PAGEcases ofbnxt_re_mmap()hand out kernel pages that userspace is only supposed to read.VM_WRITEwas already rejected, butVM_EXECwas not, so userspace could map these kernel pages executable. RejectVM_EXECas well. Also, return EPERM instead of EFAULT.Fixes 9b66c9af7172 ("RDMA/bnxt_re: Clear VM_MAYWRITE on DBR/toggle page mmap")CC Yousef Alhouseen <[email protected]>Reviewed-by Kalesh AP <[email protected]>Signed-off-by Selvin Xavier <[email protected]>--- drivers/infiniband/hw/bnxt_re/ib_verbs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/infiniband/hw/bnxt_re/ib_verbs.c +0
-0@@ -5057,11 +5057,11 @@ int bnxt_re_mmap(struct ib_ucontext *ib_uctx, struct vm_area_struct *vma)break ;case BNXT_RE_MMAP_DBR_PAGE :drivers/infiniband/hw/bnxt_re/ib_verbs.c int bnxt_re_mmap(struct ib_ucontext *ib_uctx, struct vm_area_struct *vma) · line 5064
Quoted 10 lines
drivers/infiniband/hw/bnxt_re/ib_verbs.c +4
-4case BNXT_RE_MMAP_TOGGLE_PAGE : -/* Driver doesn't expect write access for user space */ -if (vma->vm_flags &VM_WRITE ) { - ret = -EFAULT ; +/* Driver doesn't expect write and exec access for user space */ +if (vma->vm_flags & (VM_WRITE |VM_EXEC )) { + ret = -EPERM ; }else { -vm_flags_clear (vma,VM_MAYWRITE ); +vm_flags_clear (vma,VM_MAYWRITE |VM_MAYEXEC );This is an opposite to
10bf13c33450("RDMA/mlx5: Remove MAYEXEC flag") commit.
Quoted 4 lines
Quoted 1 line
Why did we do that? These MMIO mmap should never be executable
I don't remember the rationale, but if I understood my findings correctly, clearing
VM_MAYEXECbroke memcopy.
That doesn't make sense..
Jason
Selvin Xavier
maintainerRe: [PATCH for-rc 1/8] RDMA/bnxt_re: Reject executable mappings of the DBR and toggle pages
Quoted 40 lines · Jason Gunthorpe
Quoted 38 lines · Leon Romanovsky
Quoted 37 lines · Jason Gunthorpe
Quoted 35 lines · Leon Romanovsky
Quoted 21 lines · Selvin Xavier
The
BNXT_RE_MMAP_DBR_PAGEandBNXT_RE_MMAP_TOGGLE_PAGEcases ofbnxt_re_mmap()hand out kernel pages that userspace is only supposed to read.VM_WRITEwas already rejected, butVM_EXECwas not, so userspace could map these kernel pages executable. RejectVM_EXECas well. Also, return EPERM instead of EFAULT.Fixes 9b66c9af7172 ("RDMA/bnxt_re: Clear VM_MAYWRITE on DBR/toggle page mmap")CC Yousef Alhouseen <[email protected]>Reviewed-by Kalesh AP <[email protected]>Signed-off-by Selvin Xavier <[email protected]>--- drivers/infiniband/hw/bnxt_re/ib_verbs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/infiniband/hw/bnxt_re/ib_verbs.c +0
-0@@ -5057,11 +5057,11 @@ int bnxt_re_mmap(struct ib_ucontext *ib_uctx, struct vm_area_struct *vma)break ;case BNXT_RE_MMAP_DBR_PAGE :drivers/infiniband/hw/bnxt_re/ib_verbs.c int bnxt_re_mmap(struct ib_ucontext *ib_uctx, struct vm_area_struct *vma) · line 5064
Quoted 10 lines
drivers/infiniband/hw/bnxt_re/ib_verbs.c +4
-4case BNXT_RE_MMAP_TOGGLE_PAGE : -/* Driver doesn't expect write access for user space */ -if (vma->vm_flags &VM_WRITE ) { - ret = -EFAULT ; +/* Driver doesn't expect write and exec access for user space */ +if (vma->vm_flags & (VM_WRITE |VM_EXEC )) { + ret = -EPERM ; }else { -vm_flags_clear (vma,VM_MAYWRITE ); +vm_flags_clear (vma,VM_MAYWRITE |VM_MAYEXEC );This is an opposite to
10bf13c33450("RDMA/mlx5: Remove MAYEXEC flag") commit.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Why did we do that? These MMIO mmap should never be executable
I don't remember the rationale, but if I understood my findings correctly, clearing
VM_MAYEXECbroke memcopy.That doesn't make sense..
Shall i post a v3 series with v1 contents again?
Thanks,
Selvin
Quoted 2 lines
Jason
Selvin Xavier
maintainerRe: [PATCH for-rc 1/8] RDMA/bnxt_re: Reject executable mappings of the DBR and toggle pages
Quoted 42 lines · Selvin Xavier
Quoted 40 lines · Jason Gunthorpe
Quoted 38 lines · Leon Romanovsky
Quoted 37 lines · Jason Gunthorpe
Quoted 35 lines · Leon Romanovsky
Quoted 21 lines · Selvin Xavier
The
BNXT_RE_MMAP_DBR_PAGEandBNXT_RE_MMAP_TOGGLE_PAGEcases ofbnxt_re_mmap()hand out kernel pages that userspace is only supposed to read.VM_WRITEwas already rejected, butVM_EXECwas not, so userspace could map these kernel pages executable. RejectVM_EXECas well. Also, return EPERM instead of EFAULT.Fixes 9b66c9af7172 ("RDMA/bnxt_re: Clear VM_MAYWRITE on DBR/toggle page mmap")CC Yousef Alhouseen <[email protected]>Reviewed-by Kalesh AP <[email protected]>Signed-off-by Selvin Xavier <[email protected]>--- drivers/infiniband/hw/bnxt_re/ib_verbs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/infiniband/hw/bnxt_re/ib_verbs.c +0
-0@@ -5057,11 +5057,11 @@ int bnxt_re_mmap(struct ib_ucontext *ib_uctx, struct vm_area_struct *vma)break ;case BNXT_RE_MMAP_DBR_PAGE :drivers/infiniband/hw/bnxt_re/ib_verbs.c int bnxt_re_mmap(struct ib_ucontext *ib_uctx, struct vm_area_struct *vma) · line 5064
Quoted 10 lines
drivers/infiniband/hw/bnxt_re/ib_verbs.c +4
-4case BNXT_RE_MMAP_TOGGLE_PAGE : -/* Driver doesn't expect write access for user space */ -if (vma->vm_flags &VM_WRITE ) { - ret = -EFAULT ; +/* Driver doesn't expect write and exec access for user space */ +if (vma->vm_flags & (VM_WRITE |VM_EXEC )) { + ret = -EPERM ; }else { -vm_flags_clear (vma,VM_MAYWRITE ); +vm_flags_clear (vma,VM_MAYWRITE |VM_MAYEXEC );This is an opposite to
10bf13c33450("RDMA/mlx5: Remove MAYEXEC flag") commit.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Why did we do that? These MMIO mmap should never be executable
I don't remember the rationale, but if I understood my findings correctly, clearing
VM_MAYEXECbroke memcopy.That doesn't make sense..
Shall i post a v3 series with v1 contents again?
Sashiko review mentioned to clear VM_MAYEXEC also. For your reference.
https://sashiko.dev/#/message/20260909084241.570431F00A3A%40smtp.kernel.org
Quoted 5 lines
Thanks,
SelvinQuoted 2 lines
Jason
Re: [PATCH for-rc 1/8] RDMA/bnxt_re: Reject executable mappings of the DBR and toggle pages
Quoted 46 lines · Selvin Xavier
Quoted 44 lines · Selvin Xavier
Quoted 42 lines · Jason Gunthorpe
Quoted 40 lines · Leon Romanovsky
Quoted 38 lines · Jason Gunthorpe
Quoted 27 lines · Leon Romanovsky
Quoted 26 lines · Selvin Xavier
The
BNXT_RE_MMAP_DBR_PAGEandBNXT_RE_MMAP_TOGGLE_PAGEcases ofbnxt_re_mmap()hand out kernel pages that userspace is only supposed to read.VM_WRITEwas already rejected, butVM_EXECwas not, so userspace could map these kernel pages executable. RejectVM_EXECas well. Also, return EPERM instead of EFAULT.Fixes 9b66c9af7172 ("RDMA/bnxt_re: Clear VM_MAYWRITE on DBR/toggle page mmap")CC Yousef Alhouseen <[email protected]>Reviewed-by Kalesh AP <[email protected]>Signed-off-by Selvin Xavier <[email protected]>--- drivers/infiniband/hw/bnxt_re/ib_verbs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/infiniband/hw/bnxt_re/ib_verbs.c +1
-3@@ -5057,11 +5057,11 @@ int bnxt_re_mmap(struct ib_ucontext *ib_uctx, struct vm_area_struct *vma)break ;case BNXT_RE_MMAP_DBR_PAGE :case BNXT_RE_MMAP_TOGGLE_PAGE : -/* Driver doesn't expect write access for user space */ -if (vma->vm_flags &VM_WRITE ) { - ret = -EFAULT ; +/* Driver doesn't expect write and exec access for user space */ Quoted 8 lines
drivers/infiniband/hw/bnxt_re/ib_verbs.c int bnxt_re_mmap(struct ib_ucontext *ib_uctx, struct vm_area_struct *vma) · line 5064
Quoted 5 lines
drivers/infiniband/hw/bnxt_re/ib_verbs.c +3
-1+if (vma->vm_flags & (VM_WRITE |VM_EXEC )) { + ret = -EPERM ; }else { -vm_flags_clear (vma,VM_MAYWRITE ); +vm_flags_clear (vma,VM_MAYWRITE |VM_MAYEXEC );This is an opposite to
10bf13c33450("RDMA/mlx5: Remove MAYEXEC flag") commit.Why did we do that? These MMIO mmap should never be executable
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
I don't remember the rationale, but if I understood my findings correctly, clearing
VM_MAYEXECbroke memcopy.That doesn't make sense..
Shall i post a v3 series with v1 contents again?
Sashiko review mentioned to clear
VM_MAYEXECalso. For your reference.
https://sashiko.dev/#/message/20260909084241.570431F00A3A%40smtp.kernel.org
I lost track of it too. Anyway, if you repost it, could you check whether this can be handled in the core code so that it applies to all devices?
Thanks
Quoted 5 lines
Quoted 5 lines
Thanks,
SelvinQuoted 2 lines
Jason
Selvin Xavier
maintainerRe: [PATCH for-rc 1/8] RDMA/bnxt_re: Reject executable mappings of the DBR and toggle pages
Quoted 51 lines · Leon Romanovsky
Quoted 49 lines · Selvin Xavier
Quoted 47 lines · Selvin Xavier
Quoted 45 lines · Jason Gunthorpe
Quoted 42 lines · Leon Romanovsky
Quoted 37 lines · Jason Gunthorpe
Quoted 27 lines · Leon Romanovsky
Quoted 26 lines · Selvin Xavier
The
BNXT_RE_MMAP_DBR_PAGEandBNXT_RE_MMAP_TOGGLE_PAGEcases ofbnxt_re_mmap()hand out kernel pages that userspace is only supposed to read.VM_WRITEwas already rejected, butVM_EXECwas not, so userspace could map these kernel pages executable. RejectVM_EXECas well. Also, return EPERM instead of EFAULT.Fixes 9b66c9af7172 ("RDMA/bnxt_re: Clear VM_MAYWRITE on DBR/toggle page mmap")CC Yousef Alhouseen <[email protected]>Reviewed-by Kalesh AP <[email protected]>Signed-off-by Selvin Xavier <[email protected]>--- drivers/infiniband/hw/bnxt_re/ib_verbs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/infiniband/hw/bnxt_re/ib_verbs.c +1
-3@@ -5057,11 +5057,11 @@ int bnxt_re_mmap(struct ib_ucontext *ib_uctx, struct vm_area_struct *vma)break ;case BNXT_RE_MMAP_DBR_PAGE :case BNXT_RE_MMAP_TOGGLE_PAGE : -/* Driver doesn't expect write access for user space */ -if (vma->vm_flags &VM_WRITE ) { - ret = -EFAULT ; +/* Driver doesn't expect write and exec access for user space */ Quoted 8 lines
drivers/infiniband/hw/bnxt_re/ib_verbs.c int bnxt_re_mmap(struct ib_ucontext *ib_uctx, struct vm_area_struct *vma) · line 5064
Quoted 5 lines
drivers/infiniband/hw/bnxt_re/ib_verbs.c +3
-1+if (vma->vm_flags & (VM_WRITE |VM_EXEC )) { + ret = -EPERM ; }else { -vm_flags_clear (vma,VM_MAYWRITE ); +vm_flags_clear (vma,VM_MAYWRITE |VM_MAYEXEC );This is an opposite to
10bf13c33450("RDMA/mlx5: Remove MAYEXEC flag") commit.Quoted 1 line
Why did we do that? These MMIO mmap should never be executable
I don't remember the rationale, but if I understood my findings correctly, clearing
VM_MAYEXECbroke memcopy.
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
That doesn't make sense..
Shall i post a v3 series with v1 contents again?
Sashiko review mentioned to clear
VM_MAYEXECalso. For your reference.
https://sashiko.dev/#/message/20260909084241.570431F00A3A%40smtp.kernel.orgI lost track of it too. Anyway, if you repost it, could you check whether this can be handled in the core code so that it applies to all devices?
Okay, I'll drop this patch from my bug fix series then. I will
explore the core code change and repost it.
Thanks
Quoted 9 lines
Thanks
Quoted 5 lines
Quoted 5 lines
Thanks,
SelvinQuoted 2 lines
Jason
Selvin Xavier
maintainerPATCH 2/8 RDMA/bnxt_re: Detect wrong sge_len passed for inline
In reply to Selvin XavierAvoid handling wrong sge_len by adding extra check to see if the passed length is more than the inline size supported.
--- drivers/infiniband/hw/bnxt_re/ib_verbs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/infiniband/hw/bnxt_re/ib_verbs.c +3 -2
@@ -3168,8 +3168,9 @@ static int bnxt_re_copy_inline_data(struct bnxt_re_dev *rdev, wr->sg_list[i].addr; sge_len = wr->sg_list[i].length; -if ((sge_len + wqe->inline_len) > -BNXT_QPLIB_SWQE_MAX_INLINE_LENGTH ) { +if (sge_len >BNXT_QPLIB_SWQE_MAX_INLINE_LENGTH || + ((sge_len + wqe->inline_len) > +BNXT_QPLIB_SWQE_MAX_INLINE_LENGTH )) {ibdev_err (&rdev->ibdev,"Inline data size requested > supported value" );return -EINVAL ;
Signature · 1 line
2.39.3
Selvin Xavier
maintainerPATCH 3/8 RDMA/bnxt_re: Validate num_sge in bnxt_re_post_srq_recv()
In reply to Selvin XavierAdd a check if max sge for SRQ is exceeding the device maximum.
--- drivers/infiniband/hw/bnxt_re/ib_verbs.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/infiniband/hw/bnxt_re/ib_verbs.c +7 -0
@@ -2389,6 +2389,13 @@ int bnxt_re_post_srq_recv(struct ib_srq *ib_srq, const struct ib_recv_wr *wr,while (wr) {/* Transcribe each ib_recv_wr to qplib_swqe */ wqe.num_sge = wr->num_sge; +if (wr->num_sge > srq->qplib_srq.max_sge) { +ibdev_err (&srq->rdev->ibdev, +"Limit exceeded for SRQ Receive SGEs" ); + rc = -EINVAL ; + *bad_wr = wr; +break ; + }bnxt_re_build_sgl (wr->sg_list, wqe.sg_list, wr->num_sge); wqe.wr_id = wr->wr_id; wqe.type =BNXT_QPLIB_SWQE_TYPE_RECV ;
Signature · 1 line
2.39.3
Selvin Xavier
maintainerPATCH 4/8 RDMA/bnxt_re: Validate SRQ max_sge at create time
In reply to Selvin Xavierbnxt_re_create_srq() validates attr.max_wr but copies attr.max_sge into srq->qplib_srq.max_sge unvalidated. This lets an unprivileged user request an arbitrarily large max_sge, defeating the num_sge check added in bnxt_re_post_srq_recv() and overflowing the fixed 13-entry (BNXT_VAR_MAX_SGE) sg_list[] array in bnxt_re_build_sgl().
Reject max_sge > dev_attr->max_srq_sges at create time, as create_qp already does for QP send/recv SGEs. Also clamp max_srq_sges itself in bnxt_qplib_get_dev_attr() to BNXT_STATIC_MAX_SGE (6), the actual max SGEs an SRQ ring entry supports, since it was taken straight from firmware with no bound.
--- drivers/infiniband/hw/bnxt_re/ib_verbs.c | 8 ++++++++ drivers/infiniband/hw/bnxt_re/qplib_sp.c | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-)
drivers/infiniband/hw/bnxt_re/ib_verbs.c +8 -0
@@ -2235,6 +2235,14 @@ int bnxt_re_create_srq(struct ib_srq *ib_srq, goto exit; } +if (srq_init_attr->attr.max_sge > dev_attr->max_srq_sges) { +ibdev_err (&rdev->ibdev, +"Create SRQ failed - max_sge %d exceeds supported %d" , + srq_init_attr->attr.max_sge, dev_attr->max_srq_sges); + rc = -EINVAL ; + goto exit; + } +if (srq_init_attr->srq_type !=IB_SRQT_BASIC ) { rc = -EOPNOTSUPP ; goto exit;
drivers/infiniband/hw/bnxt_re/qplib_sp.c +1 -1
@@ -160,7 +160,7 @@ int bnxt_qplib_get_dev_attr(struct bnxt_qplib_rcfw *rcfw) attr->max_srq =le16_to_cpu (sb->max_srq); attr->max_srq_wqes =le32_to_cpu (sb->max_srq_wr) -1 ; - attr->max_srq_sges = sb->max_srq_sge; + attr->max_srq_sges =min_t (u32, sb->max_srq_sge,BNXT_STATIC_MAX_SGE ); attr->max_pkey =1 ; attr->max_inline_data = attr->max_qp_sges *sizeof (struct sq_sge );if (!bnxt_qplib_is_chip_gen_p7 (rcfw->res->cctx))
Signature · 1 line
2.39.3
Selvin Xavier
maintainerPATCH 5/8 RDMA/bnxt_re: Fix rdev lifetime races in suspend/resume/shutdown
In reply to Selvin Xavieren_info->rdev is read by unlocked L2 ULP callbacks (bnxt_re_stop_irq/start_irq/async_notifier), which rely on rdev being cleared before it is freed, not after. bnxt_re_add_device() cleared it too late on a bnxt_re_dev_init() failure and bnxt_re_resume() didn't check the return value, risking a use-after-free/NULL deref. bnxt_re_suspend() froze and freed rdev before clearing en_info->rdev, opening the same UAF window. bnxt_re_shutdown() took no lock, never checked rdev for NULL, never cleared en_info->rdev, and never freed rdev at all.
Fix the ordering in bnxt_re_add_device()/bnxt_re_suspend(), add the missing return-value check in bnxt_re_resume(), and rewrite bnxt_re_shutdown() to take the lock, check for NULL, and reuse bnxt_re_remove_device() with the same clear-before-free ordering.
--- drivers/infiniband/hw/bnxt_re/main.c | 32 ++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 7 deletions(-)
drivers/infiniband/hw/bnxt_re/main.c +25 -7
@@ -2433,11 +2433,14 @@ static int bnxt_re_add_device(struct auxiliary_device *adev, u8 op_type)bnxt_re_update_en_info_rdev (rdev, en_info, adev); rc =bnxt_re_dev_init (rdev, op_type); -if (rc) +if (rc) { +bnxt_re_update_en_info_rdev (NULL , en_info, adev); goto re_dev_dealloc; + } rc =bnxt_re_ib_init (rdev);if (rc) { +bnxt_re_update_en_info_rdev (NULL , en_info, adev);pr_err ("Failed to register with IB: %s" , aux_priv->aux_dev.name); goto re_dev_uninit;
@@ -2448,7 +2451,6 @@ static int bnxt_re_add_device(struct auxiliary_device *adev, u8 op_type)return 0 ; re_dev_uninit: -bnxt_re_update_en_info_rdev (NULL , en_info, adev);bnxt_re_dev_uninit (rdev,BNXT_RE_COMPLETE_REMOVE ); re_dev_dealloc:ib_dealloc_device (&rdev->ibdev);
@@ -2517,9 +2519,13 @@ static int bnxt_re_suspend(struct auxiliary_device *adev, pm_message_t state)struct bnxt_en_dev *en_dev;struct bnxt_re_dev *rdev; +mutex_lock (&bnxt_re_mutex); rdev = en_info->rdev; +if (!rdev) { +mutex_unlock (&bnxt_re_mutex); +return 0 ; + } en_dev = en_info->en_dev; -mutex_lock (&bnxt_re_mutex);ibdev_info (&rdev->ibdev,"Handle device suspend call" );/* Check the current device state from bnxt_en_dev and move the
@@ -2539,8 +2545,9 @@ static int bnxt_re_suspend(struct auxiliary_device *adev, pm_message_t state)ibdev_info (&rdev->ibdev,"%s: L2 driver notified to stop en_state 0x%lx" , __func__, en_dev->en_state); -bnxt_re_remove_device (rdev,BNXT_RE_PRE_RECOVERY_REMOVE , adev); +bnxt_re_update_en_info_rdev (NULL , en_info, adev); +bnxt_re_remove_device (rdev,BNXT_RE_PRE_RECOVERY_REMOVE , adev);mutex_unlock (&bnxt_re_mutex);return 0 ;
@@ -2550,9 +2557,14 @@ static int bnxt_re_resume(struct auxiliary_device *adev) {struct bnxt_re_en_dev_info *en_info =auxiliary_get_drvdata (adev);struct bnxt_re_dev *rdev; +int rc;mutex_lock (&bnxt_re_mutex); -bnxt_re_add_device (adev,BNXT_RE_POST_RECOVERY_INIT ); + rc =bnxt_re_add_device (adev,BNXT_RE_POST_RECOVERY_INIT ); +if (rc) { +mutex_unlock (&bnxt_re_mutex); +return rc; + } rdev = en_info->rdev;ibdev_info (&rdev->ibdev,"Device resume completed" );mutex_unlock (&bnxt_re_mutex);
@@ -2565,9 +2577,15 @@ static void bnxt_re_shutdown(struct auxiliary_device *adev)struct bnxt_re_en_dev_info *en_info =auxiliary_get_drvdata (adev);struct bnxt_re_dev *rdev; +mutex_lock (&bnxt_re_mutex); rdev = en_info->rdev; -ib_unregister_device (&rdev->ibdev); -bnxt_re_dev_uninit (rdev,BNXT_RE_COMPLETE_REMOVE ); +if (!rdev) + goto out; + +bnxt_re_update_en_info_rdev (NULL , en_info, adev); +bnxt_re_remove_device (rdev,BNXT_RE_COMPLETE_REMOVE , adev); +out: +mutex_unlock (&bnxt_re_mutex); }static const struct auxiliary_device_id bnxt_re_id_table[] = {
Signature · 1 line
2.39.3
Selvin Xavier
maintainerPATCH 6/8 RDMA/bnxt_re: Fix the PD and DPI table size
In reply to Selvin XavierThe PD and DPI bitmaps were sized as max >> 3 (bytes), but bitmap ops (set_bit(), clear_bit(), find_first_bit(), test_and_set_bit()) operate on whole unsigned long words, so whenever max isn't a multiple of BITS_PER_LONG,
the buffer under-allocates and the top word's bitops read/write past the end of the kmalloc()'d buffer. Most exposed on the DPI table, since dpit->max comes from the firmware-reported dev_attr->max_dpi with no alignment guarantee.
Fix the size both allocations with BITS_TO_LONGS(max) * sizeof(unsigned long).
--- drivers/infiniband/hw/bnxt_re/qplib_res.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/infiniband/hw/bnxt_re/qplib_res.c +5 -4
@@ -45,6 +45,7 @@#include <linux/dma-mapping.h> #include <linux/if_vlan.h> #include <linux/vmalloc.h> +#include <linux/bitops.h> #include <rdma/ib_verbs.h> #include <rdma/iter.h>
@@ -668,9 +669,9 @@ static int bnxt_qplib_alloc_pd_tbl(struct bnxt_qplib_res *res, {u32 bytes; - bytes = max >>3 ; + bytes =BITS_TO_LONGS (max) *sizeof (unsigned long );if (!bytes) - bytes =1 ; + bytes =sizeof (unsigned long ); pdt->tbl =kmalloc (bytes,GFP_KERNEL );if (!pdt->tbl)return -ENOMEM ;
@@ -848,9 +849,9 @@ static int bnxt_qplib_alloc_dpi_tbl(struct bnxt_qplib_res *res,if (!dpit->app_tbl)return -ENOMEM ; - bytes = dpit->max >>3 ; + bytes =BITS_TO_LONGS (dpit->max) *sizeof (unsigned long );if (!bytes) - bytes =1 ; + bytes =sizeof (unsigned long ); dpit->tbl =kmalloc (bytes,GFP_KERNEL );if (!dpit->tbl) {
Signature · 1 line
2.39.3
Selvin Xavier
maintainerPATCH 7/8 RDMA/bnxt_re: Use bnxt_ext_stats_supported for counter count selection
In reply to Selvin XavierSelecting between BNXT_RE_NUM_EXT_COUNTERS and BNXT_RE_NUM_STD_COUNTERS relied only on bnxt_qplib_is_chip_gen_p5_p7(), which doesn't account for the extended stats capability flag or the PF/VF restriction. Use bnxt_ext_stats_supported() instead, matching the check already used to populate the extended stats, so the counter count stays consistent with what gets filled in.
--- drivers/infiniband/hw/bnxt_re/hw_counters.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/infiniband/hw/bnxt_re/hw_counters.c +4 -2
@@ -413,7 +413,8 @@ int bnxt_re_ib_get_hw_stats(struct ib_device *ibdev, } done: -return bnxt_qplib_is_chip_gen_p5_p7 (rdev->chip_ctx) ? +return bnxt_ext_stats_supported (rdev->chip_ctx, rdev->dev_attr->dev_cap_flags, + rdev->is_virtfn) ?BNXT_RE_NUM_EXT_COUNTERS :BNXT_RE_NUM_STD_COUNTERS ; }
@@ -423,7 +424,8 @@ struct rdma_hw_stats *bnxt_re_ib_alloc_hw_port_stats(struct ib_device *ibdev,struct bnxt_re_dev *rdev =to_bnxt_re_dev (ibdev, ibdev);int num_counters =0 ; -if (bnxt_qplib_is_chip_gen_p5_p7 (rdev->chip_ctx)) +if (bnxt_ext_stats_supported (rdev->chip_ctx, rdev->dev_attr->dev_cap_flags, + rdev->is_virtfn)) num_counters =BNXT_RE_NUM_EXT_COUNTERS ;else num_counters =BNXT_RE_NUM_STD_COUNTERS ;
Signature · 1 line
2.39.3
Selvin Xavier
maintainerPATCH 8/8 RDMA/bnxt_re: Check is_in_used before trusting RCFW completion
In reply to Selvin XavierGate the crsqe->resp memcpy in bnxt_qplib_process_qp_event() on is_in_used in addition to is_waiter_alive, since a late/duplicate completion for an already-retired cookie could still write through a stale resp pointer.
Also disarm the waiter and clear resp when a wait call bails out early on ERR_DEVICE_DETACHED, and require is_in_used before re-triggering __destroy_timedout_ah(), closing the same stale-cookie exposure elsewhere in the completion path.
--- drivers/infiniband/hw/bnxt_re/qplib_rcfw.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/infiniband/hw/bnxt_re/qplib_rcfw.c +8 -4
@@ -511,14 +511,16 @@ static int __bnxt_qplib_rcfw_send_message(struct bnxt_qplib_rcfw *rcfw,else rc =__poll_for_resp (rcfw, cookie); -if (rc) { +if (rc ||test_bit (ERR_DEVICE_DETACHED , &rcfw->cmdq.flags)) {spin_lock_bh (&rcfw->cmdq.hwq.lock); crsqe = &rcfw->crsqe_tbl[cookie]; crsqe->is_waiter_alive = false; + crsqe->resp =NULL ;if (rc == -ENODEV )set_bit (FIRMWARE_STALL_DETECTED , &rcfw->cmdq.flags);spin_unlock_bh (&rcfw->cmdq.hwq.lock); -return -ETIMEDOUT ; +if (rc) +return -ETIMEDOUT ; }if (evnt->status) {
@@ -627,6 +629,7 @@ static int bnxt_qplib_process_qp_event(struct bnxt_qplib_rcfw *rcfw,struct bnxt_qplib_qp *qp;u16 cookie, blocked =0 ;bool is_waiter_alive; +bool is_in_used;struct pci_dev *pdev;u32 wait_cmds =0 ;int rc =0 ;
@@ -682,7 +685,7 @@ static int bnxt_qplib_process_qp_event(struct bnxt_qplib_rcfw *rcfw,if (crsqe->is_internal_cmd && !qp_event->status)atomic_dec (&rcfw->timeout_send); -if (crsqe->is_waiter_alive) { +if (crsqe->is_waiter_alive && crsqe->is_in_used) {if (crsqe->resp) {memcpy (crsqe->resp, qp_event,sizeof (*qp_event));/* Insert write memory barrier to ensure that
@@ -697,6 +700,7 @@ static int bnxt_qplib_process_qp_event(struct bnxt_qplib_rcfw *rcfw, req_size = crsqe->req_size; is_waiter_alive = crsqe->is_waiter_alive; + is_in_used = crsqe->is_in_used; crsqe->req_size =0 ;if (!is_waiter_alive)
@@ -718,7 +722,7 @@ static int bnxt_qplib_process_qp_event(struct bnxt_qplib_rcfw *rcfw,* resource leak and relatively not critical + unlikely * scenario. Current design is not to handle such case. */ -if (!is_waiter_alive && !qp_event->status && +if (is_in_used && !is_waiter_alive && !qp_event->status && qp_event->event ==CREQ_QP_EVENT_EVENT_CREATE_AH ) __destroy_timedout_ah(rcfw, (struct creq_create_ah_resp *)
Signature · 1 line
2.39.3