[PATCH] mlx5: bound raw flow rule match parameter copies
From: Pengpeng Hou
Date: Sat Mar 21 2026 - 23:19:58 EST
`_create_raw_flow_rule()` copies user-supplied match data and matcher
mask bytes directly into the fixed `mlx5_flow_spec` arrays. The UAPI
allows up to `MLX5_IB_DW_MATCH_PARAM` bytes for the input attributes,
but the kernel object only allocates
`MLX5_ST_SZ_DW(fte_match_param)` bytes for each buffer.
Validate the sizes before copying so oversized verbs requests cannot
corrupt the spec object.
Signed-off-by: Pengpeng Hou <pengpeng@xxxxxxxxxxx>
---
drivers/infiniband/hw/mlx5/fs.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/infiniband/hw/mlx5/fs.c b/drivers/infiniband/hw/mlx5/fs.c
index cbccb0b9ac10..b5194f674c65 100644
--- a/drivers/infiniband/hw/mlx5/fs.c
+++ b/drivers/infiniband/hw/mlx5/fs.c
@@ -2069,6 +2069,12 @@ _create_raw_flow_rule(struct mlx5_ib_dev *dev,
INIT_LIST_HEAD(&handler->list);
+ if (inlen > sizeof(spec->match_value) ||
+ fs_matcher->mask_len > sizeof(spec->match_criteria)) {
+ err = -EINVAL;
+ goto free;
+ }
+
memcpy(spec->match_value, cmd_in, inlen);
memcpy(spec->match_criteria, fs_matcher->matcher_mask.match_params,
fs_matcher->mask_len);
--
2.50.1 (Apple Git-155)