RDMA/mlx4: Do not allow the user to write to the clock page
Subsystems (2)
PATCH 1/1 RDMA/mlx4: Do not allow the user to write to the clock page
mlx4_ib_mmap() maps the internal clock page to userspace through rdma_user_mmap_io(), which does not restrict write access. Userspace can request PROT_WRITE directly, or upgrade a read-only mapping later with mprotect() because VM_MAYWRITE remains set.
Reject VM_WRITE and clear VM_MAYWRITE, applying the same read-only policy as commit c660133c339f ("RDMA/mlx5: Do not allow the user to write to the clock page"). The rdma-core mlx4 provider requests this mapping with PROT_READ, so its existing behavior is unchanged.
--- drivers/infiniband/hw/mlx4/main.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/infiniband/hw/mlx4/main.c +4 -0
@@ -1169,6 +1169,10 @@ static int mlx4_ib_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)struct mlx4_clock_params params;int ret; +if (vma->vm_flags &VM_WRITE ) +return -EPERM ; +vm_flags_clear (vma,VM_MAYWRITE ); + ret =mlx4_get_internal_clock_params (dev->dev, ¶ms);if (ret)return ret;
Signature · 1 line
2.34.1
[email protected]
AI reviewSashiko has reviewed this patch and found no issues. It looks great!
Quoted 5 lines
mlx4_ib_mmap()maps the internal clock page to userspace throughrdma_user_mmap_io(), which does not restrict write access. Userspace can requestPROT_WRITEdirectly, or upgrade a read-only mapping later withmprotect()becauseVM_MAYWRITEremains set.
Quoted 7 lines
Reject
VM_WRITEand clearVM_MAYWRITE, applying the same read-only policy as commitc660133c339f("RDMA/mlx5: Do not allow the user to write to the clock page"). The rdma-core mlx4 provider requests this mapping withPROT_READ, so its existing behavior is unchanged.Fixes 52033cfb5aab ("IB/mlx4: Add mmap call to map the hardware clock")Signed-off-by Jiale Yao <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 21 lines · Jiale Yao
mlx4_ib_mmap()maps the internal clock page to userspace throughrdma_user_mmap_io(), which does not restrict write access. Userspace can requestPROT_WRITEdirectly, or upgrade a read-only mapping later withmprotect()becauseVM_MAYWRITEremains set.Reject
VM_WRITEand clearVM_MAYWRITE, applying the same read-only policy as commitc660133c339f("RDMA/mlx5: Do not allow the user to write to the clock page"). The rdma-core mlx4 provider requests this mapping withPROT_READ, so its existing behavior is unchanged.Fixes 52033cfb5aab ("IB/mlx4: Add mmap call to map the hardware clock")Signed-off-by Jiale Yao <[email protected]>--- drivers/infiniband/hw/mlx4/main.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/infiniband/hw/mlx4/main.c +0
-0
drivers/infiniband/hw/mlx4/main.c static int mlx4_ib_mmap(struct ib_ucontext *context, struct vm_area_struct *vma) · line 1172
Quoted 4 lines
drivers/infiniband/hw/mlx4/main.c +1
-0@@ -1169,6 +1169,10 @@ static int mlx4_ib_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)struct mlx4_clock_params params;int ret; +if (vma->vm_flags &VM_WRITE )
It needs to be:
if (vma->vm_flags & (VM_WRITE | VM_EXEC))
I fixed it locally.
Thanks
Quoted 9 lines
drivers/infiniband/hw/mlx4/main.c +3
-0+return -EPERM ; +vm_flags_clear (vma,VM_MAYWRITE ); + ret =mlx4_get_internal_clock_params (dev->dev, ¶ms);if (ret)return ret;Signature · 1 line
2.34.1
Leon Romanovsky
AppliedQuoted 11 lines · Jiale Yao
mlx4_ib_mmap()maps the internal clock page to userspace throughrdma_user_mmap_io(), which does not restrict write access. Userspace can requestPROT_WRITEdirectly, or upgrade a read-only mapping later withmprotect()becauseVM_MAYWRITEremains set.Reject
VM_WRITEand clearVM_MAYWRITE, applying the same read-only policy as commitc660133c339f("RDMA/mlx5: Do not allow the user to write to the clock page"). The rdma-core mlx4 provider requests this mapping withPROT_READ, so its existing behavior is unchanged.[...]
Applied, thanks!
[1/1] RDMA/mlx4: Do not allow the user to write to the clock page
https://git.kernel.org/rdma/rdma/c/33db1d9683b8fb
Best regards,
Signature · 1 line
Leon Romanovsky <[email protected]>