vdpa/mlx5: Fix possible failure in umem size calculation
Subsystems (2)
PATCH 2/2 vdpa/mlx5: Fix possible failure in umem size calculation
umem size is a 32 bit unsigned value so assigning it to an int could cause false failures. Set the calculated value inside the function and modify function name to reflect the fact it updates the size.
--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +5 -10
@@ -610,8 +610,8 @@ static void cq_destroy(struct mlx5_vdpa_net *ndev, u16 idx)mlx5_db_free (ndev->mvdev.mdev, &vcq->db); } -static int umem_size (struct mlx5_vdpa_net *ndev,struct mlx5_vdpa_virtqueue *mvq,int num, -struct mlx5_vdpa_umem **umemp) +static void set_umem_size (struct mlx5_vdpa_net *ndev,struct mlx5_vdpa_virtqueue *mvq,int num, +struct mlx5_vdpa_umem **umemp) {struct mlx5_core_dev *mdev = ndev->mvdev.mdev;int p_a;
@@ -634,7 +634,7 @@ static int umem_size(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq *umemp = &mvq->umem3;break ; } -return p_a * mvq->num_ent + p_b; + (*umemp)->size = p_a * mvq->num_ent + p_b; }static void umem_frag_buf_free (struct mlx5_vdpa_net *ndev,struct mlx5_vdpa_umem *umem)
@@ -650,15 +650,10 @@ static int create_umem(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvoid *in;int err;__be64 *pas; -int size;struct mlx5_vdpa_umem *umem; - size =umem_size (ndev, mvq, num, &umem); -if (size <0 ) -return size; - - umem->size = size; - err =umem_frag_buf_alloc (ndev, umem, size); +set_umem_size (ndev, mvq, num, &umem); + err =umem_frag_buf_alloc (ndev, umem, umem->size);if (err)return err;
Signature · 1 line
2.31.1
Michael S. Tsirkin
maintainerQuoted 6 lines · Eli Cohen
umem size is a 32 bit unsigned value so assigning it to an int could cause false failures. Set the calculated value inside the function and modify function name to reflect the fact it updates the size.
Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")Signed-off-by Eli Cohen <[email protected]>
could you clarify the impact of the bug please?
Quoted 48 lines
--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)drivers/vdpa/mlx5/net/mlx5_vnet.c +5
-10@@ -610,8 +610,8 @@ static void cq_destroy(struct mlx5_vdpa_net *ndev, u16 idx)mlx5_db_free (ndev->mvdev.mdev, &vcq->db); } -static int umem_size (struct mlx5_vdpa_net *ndev,struct mlx5_vdpa_virtqueue *mvq,int num, -struct mlx5_vdpa_umem **umemp) +static void set_umem_size (struct mlx5_vdpa_net *ndev,struct mlx5_vdpa_virtqueue *mvq,int num, +struct mlx5_vdpa_umem **umemp) {struct mlx5_core_dev *mdev = ndev->mvdev.mdev;int p_a;@@ -634,7 +634,7 @@ static int umem_size(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq *umemp = &mvq->umem3;break ; } -return p_a * mvq->num_ent + p_b; + (*umemp)->size = p_a * mvq->num_ent + p_b; }static void umem_frag_buf_free (struct mlx5_vdpa_net *ndev,struct mlx5_vdpa_umem *umem)@@ -650,15 +650,10 @@ static int create_umem(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvoid *in;int err;__be64 *pas; -int size;struct mlx5_vdpa_umem *umem; - size =umem_size (ndev, mvq, num, &umem); -if (size <0 ) -return size; - - umem->size = size; - err =umem_frag_buf_alloc (ndev, umem, size); +set_umem_size (ndev, mvq, num, &umem); + err =umem_frag_buf_alloc (ndev, umem, umem->size);if (err)return err;Signature · 1 line
2.31.1
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Quoted 10 lines · Michael S. Tsirkin
Quoted 6 lines · Eli Cohen
umem size is a 32 bit unsigned value so assigning it to an int could cause false failures. Set the calculated value inside the function and modify function name to reflect the fact it updates the size.
Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")Signed-off-by Eli Cohen <[email protected]>could you clarify the impact of the bug please?
This was found by code revew. I did not see it causing trouble becuase umem sizes are small enough to fit in int. Nevertheless it's a bug that deserves a fix.
Quoted 50 lines
Quoted 49 lines
--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)drivers/vdpa/mlx5/net/mlx5_vnet.c +5
-10@@ -610,8 +610,8 @@ static void cq_destroy(struct mlx5_vdpa_net *ndev, u16 idx)mlx5_db_free (ndev->mvdev.mdev, &vcq->db); } -static int umem_size (struct mlx5_vdpa_net *ndev,struct mlx5_vdpa_virtqueue *mvq,int num, -struct mlx5_vdpa_umem **umemp) +static void set_umem_size (struct mlx5_vdpa_net *ndev,struct mlx5_vdpa_virtqueue *mvq,int num, +struct mlx5_vdpa_umem **umemp) {struct mlx5_core_dev *mdev = ndev->mvdev.mdev;int p_a;@@ -634,7 +634,7 @@ static int umem_size(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq *umemp = &mvq->umem3;break ; } -return p_a * mvq->num_ent + p_b; + (*umemp)->size = p_a * mvq->num_ent + p_b; }static void umem_frag_buf_free (struct mlx5_vdpa_net *ndev,struct mlx5_vdpa_umem *umem)@@ -650,15 +650,10 @@ static int create_umem(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvoid *in;int err;__be64 *pas; -int size;struct mlx5_vdpa_umem *umem; - size =umem_size (ndev, mvq, num, &umem); -if (size <0 ) -return size; - - umem->size = size; - err =umem_frag_buf_alloc (ndev, umem, size); +set_umem_size (ndev, mvq, num, &umem); + err =umem_frag_buf_alloc (ndev, umem, umem->size);if (err)return err;Signature · 1 line
2.31.1
Michael S. Tsirkin
maintainerQuoted 9 lines · Eli Cohen
Quoted 8 lines · Michael S. Tsirkin
Quoted 6 lines · Eli Cohen
umem size is a 32 bit unsigned value so assigning it to an int could cause false failures. Set the calculated value inside the function and modify function name to reflect the fact it updates the size.
Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")Signed-off-by Eli Cohen <[email protected]>
Quoted 6 lines
Quoted 2 lines
could you clarify the impact of the bug please?
This was found by code revew. I did not see it causing trouble becuase umem sizes are small enough to fit in int. Nevertheless it's a bug that deserves a fix.
ok pls include this info in the commit log.
Quoted 50 lines
Quoted 50 lines
Quoted 49 lines
--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)drivers/vdpa/mlx5/net/mlx5_vnet.c +5
-10@@ -610,8 +610,8 @@ static void cq_destroy(struct mlx5_vdpa_net *ndev, u16 idx)mlx5_db_free (ndev->mvdev.mdev, &vcq->db); } -static int umem_size (struct mlx5_vdpa_net *ndev,struct mlx5_vdpa_virtqueue *mvq,int num, -struct mlx5_vdpa_umem **umemp) +static void set_umem_size (struct mlx5_vdpa_net *ndev,struct mlx5_vdpa_virtqueue *mvq,int num, +struct mlx5_vdpa_umem **umemp) {struct mlx5_core_dev *mdev = ndev->mvdev.mdev;int p_a;@@ -634,7 +634,7 @@ static int umem_size(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq *umemp = &mvq->umem3;break ; } -return p_a * mvq->num_ent + p_b; + (*umemp)->size = p_a * mvq->num_ent + p_b; }static void umem_frag_buf_free (struct mlx5_vdpa_net *ndev,struct mlx5_vdpa_umem *umem)@@ -650,15 +650,10 @@ static int create_umem(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvoid *in;int err;__be64 *pas; -int size;struct mlx5_vdpa_umem *umem; - size =umem_size (ndev, mvq, num, &umem); -if (size <0 ) -return size; - - umem->size = size; - err =umem_frag_buf_alloc (ndev, umem, size); +set_umem_size (ndev, mvq, num, &umem); + err =umem_frag_buf_alloc (ndev, umem, umem->size);if (err)return err;Signature · 1 line
2.31.1
Quoted 10 lines · Michael S. Tsirkin
Quoted 9 lines · Eli Cohen
Quoted 8 lines · Michael S. Tsirkin
Quoted 6 lines · Eli Cohen
umem size is a 32 bit unsigned value so assigning it to an int could cause false failures. Set the calculated value inside the function and modify function name to reflect the fact it updates the size.
Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")Signed-off-by Eli Cohen <[email protected]>
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
could you clarify the impact of the bug please?
This was found by code revew. I did not see it causing trouble becuase umem sizes are small enough to fit in int. Nevertheless it's a bug that deserves a fix.
ok pls include this info in the commit log.
Not sure what info do you want me to include. Seems to me that the changelog already provides the required information.
Quoted 51 lines
Quoted 50 lines
Quoted 50 lines
Quoted 49 lines
--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)drivers/vdpa/mlx5/net/mlx5_vnet.c +5
-10@@ -610,8 +610,8 @@ static void cq_destroy(struct mlx5_vdpa_net *ndev, u16 idx)mlx5_db_free (ndev->mvdev.mdev, &vcq->db); } -static int umem_size (struct mlx5_vdpa_net *ndev,struct mlx5_vdpa_virtqueue *mvq,int num, -struct mlx5_vdpa_umem **umemp) +static void set_umem_size (struct mlx5_vdpa_net *ndev,struct mlx5_vdpa_virtqueue *mvq,int num, +struct mlx5_vdpa_umem **umemp) {struct mlx5_core_dev *mdev = ndev->mvdev.mdev;int p_a;@@ -634,7 +634,7 @@ static int umem_size(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq *umemp = &mvq->umem3;break ; } -return p_a * mvq->num_ent + p_b; + (*umemp)->size = p_a * mvq->num_ent + p_b; }static void umem_frag_buf_free (struct mlx5_vdpa_net *ndev,struct mlx5_vdpa_umem *umem)@@ -650,15 +650,10 @@ static int create_umem(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvoid *in;int err;__be64 *pas; -int size;struct mlx5_vdpa_umem *umem; - size =umem_size (ndev, mvq, num, &umem); -if (size <0 ) -return size; - - umem->size = size; - err =umem_frag_buf_alloc (ndev, umem, size); +set_umem_size (ndev, mvq, num, &umem); + err =umem_frag_buf_alloc (ndev, umem, umem->size);if (err)return err;Signature · 1 line
2.31.1
Michael S. Tsirkin
maintainerQuoted 18 lines · Eli Cohen
Quoted 17 lines · Michael S. Tsirkin
Quoted 15 lines · Eli Cohen
Quoted 10 lines · Michael S. Tsirkin
Quoted 6 lines · Eli Cohen
umem size is a 32 bit unsigned value so assigning it to an int could cause false failures. Set the calculated value inside the function and modify function name to reflect the fact it updates the size.
Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")Signed-off-by Eli Cohen <[email protected]>could you clarify the impact of the bug please?
This was found by code revew. I did not see it causing trouble becuase umem sizes are small enough to fit in int. Nevertheless it's a bug that deserves a fix.
Quoted 5 lines
Quoted 2 lines
ok pls include this info in the commit log.
Not sure what info do you want me to include. Seems to me that the changelog already provides the required information.
that this was found by code review and has no practical impact.
Quoted 51 lines
Quoted 51 lines
Quoted 50 lines
Quoted 50 lines
Quoted 49 lines
--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)drivers/vdpa/mlx5/net/mlx5_vnet.c +5
-10@@ -610,8 +610,8 @@ static void cq_destroy(struct mlx5_vdpa_net *ndev, u16 idx)mlx5_db_free (ndev->mvdev.mdev, &vcq->db); } -static int umem_size (struct mlx5_vdpa_net *ndev,struct mlx5_vdpa_virtqueue *mvq,int num, -struct mlx5_vdpa_umem **umemp) +static void set_umem_size (struct mlx5_vdpa_net *ndev,struct mlx5_vdpa_virtqueue *mvq,int num, +struct mlx5_vdpa_umem **umemp) {struct mlx5_core_dev *mdev = ndev->mvdev.mdev;int p_a;@@ -634,7 +634,7 @@ static int umem_size(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq *umemp = &mvq->umem3;break ; } -return p_a * mvq->num_ent + p_b; + (*umemp)->size = p_a * mvq->num_ent + p_b; }static void umem_frag_buf_free (struct mlx5_vdpa_net *ndev,struct mlx5_vdpa_umem *umem)@@ -650,15 +650,10 @@ static int create_umem(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvoid *in;int err;__be64 *pas; -int size;struct mlx5_vdpa_umem *umem; - size =umem_size (ndev, mvq, num, &umem); -if (size <0 ) -return size; - - umem->size = size; - err =umem_frag_buf_alloc (ndev, umem, size); +set_umem_size (ndev, mvq, num, &umem); + err =umem_frag_buf_alloc (ndev, umem, umem->size);if (err)return err;Signature · 1 line
2.31.1
Quoted 19 lines · Michael S. Tsirkin
Quoted 18 lines · Eli Cohen
Quoted 17 lines · Michael S. Tsirkin
Quoted 15 lines · Eli Cohen
Quoted 10 lines · Michael S. Tsirkin
Quoted 6 lines · Eli Cohen
umem size is a 32 bit unsigned value so assigning it to an int could cause false failures. Set the calculated value inside the function and modify function name to reflect the fact it updates the size.
Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")Signed-off-by Eli Cohen <[email protected]>could you clarify the impact of the bug please?
This was found by code revew. I did not see it causing trouble becuase umem sizes are small enough to fit in int. Nevertheless it's a bug that deserves a fix.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
ok pls include this info in the commit log.
Not sure what info do you want me to include. Seems to me that the changelog already provides the required information.
that this was found by code review and has no practical impact.
ok
Quoted 53 lines
Quoted 52 lines
Quoted 52 lines
Quoted 51 lines
Quoted 51 lines
Quoted 50 lines
--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)drivers/vdpa/mlx5/net/mlx5_vnet.c +5
-10@@ -610,8 +610,8 @@ static void cq_destroy(struct mlx5_vdpa_net *ndev, u16 idx)mlx5_db_free (ndev->mvdev.mdev, &vcq->db); } -static int umem_size (struct mlx5_vdpa_net *ndev,struct mlx5_vdpa_virtqueue *mvq,int num, -struct mlx5_vdpa_umem **umemp) +static void set_umem_size (struct mlx5_vdpa_net *ndev,struct mlx5_vdpa_virtqueue *mvq,int num, +struct mlx5_vdpa_umem **umemp) {struct mlx5_core_dev *mdev = ndev->mvdev.mdev;int p_a;@@ -634,7 +634,7 @@ static int umem_size(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq *umemp = &mvq->umem3;break ; } -return p_a * mvq->num_ent + p_b; + (*umemp)->size = p_a * mvq->num_ent + p_b; }static void umem_frag_buf_free (struct mlx5_vdpa_net *ndev,struct mlx5_vdpa_umem *umem)@@ -650,15 +650,10 @@ static int create_umem(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvoid *in;int err;__be64 *pas; -int size;struct mlx5_vdpa_umem *umem; - size =umem_size (ndev, mvq, num, &umem); -if (size <0 ) -return size; - - umem->size = size; - err =umem_frag_buf_alloc (ndev, umem, size); +set_umem_size (ndev, mvq, num, &umem); + err =umem_frag_buf_alloc (ndev, umem, umem->size);if (err)return err;Signature · 1 line
2.31.1