RDMA/ucma: fix a kernel-infoleak in ucma_init_qp_attr()
PATCH 1/1 RDMA/ucma: fix a kernel-infoleak in ucma_init_qp_attr()
From: Haimin Zhang <[email protected]>
The ib_copy_ah_attr_to_user() function only initializes "resp.grh" if the "resp.is_global" flag is set. Unfortunately, this data is copied to the user and copying uninitialized stack data to the user is an information leak. Zero out the whole struct to be safe.
---
Resending through the regular lists.
I added parentheses around the sizeof to make checkpatch happy. s/sizeof resp/sizeof(resp)/.
drivers/infiniband/core/ucma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/core/ucma.c +1 -1
@@ -1232,7 +1232,7 @@ static ssize_t ucma_init_qp_attr(struct ucma_file *file,if (IS_ERR (ctx))return PTR_ERR (ctx); - resp.qp_attr_mask =0 ; +memset (&resp,0 ,sizeof (resp));memset (&qp_attr,0 ,sizeof qp_attr); qp_attr.qp_state = cmd.qp_state;mutex_lock (&ctx->mutex);
Signature · 1 line
2.20.1
Quoted 11 lines · Dan Carpenter
From: Haimin Zhang <[email protected]>
The
ib_copy_ah_attr_to_user()function only initializes "resp.grh" if the "resp.is_global" flag is set. Unfortunately, this data is copied to the user and copying uninitialized stack data to the user is an information leak. Zero out the whole struct to be safe.Fixes 4ba66093bdc6 ("IB/core: Check for global flag when using ah_attr")Reported-by TCS Robot <[email protected]>Signed-off-by Haimin Zhang <[email protected]>Signed-off-by Dan Carpenter <[email protected]>
Quoted 8 lines
---
Resending through the regular lists.I added parentheses around the sizeof to make checkpatch happy. s/sizeof resp/sizeof(resp)/.
drivers/infiniband/core/ucma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
The change is ok, but I prefer to initialize to zero as early as possible.
drivers/infiniband/core/ucma.c +2 -4
@@ -1211,9 +1211,9 @@ static ssize_t ucma_init_qp_attr(struct ucma_file *file, int in_len, int out_len) {struct rdma_ucm_init_qp_attr cmd; -struct ib_uverbs_qp_attr resp; +struct ib_uverbs_qp_attr resp = {};struct ucma_context *ctx; -struct ib_qp_attr qp_attr; +struct ib_qp_attr qp_attr = {};int ret;if (out_len <sizeof (resp))
@@ -1229,8 +1229,6 @@ static ssize_t ucma_init_qp_attr(struct ucma_file *file,if (IS_ERR (ctx))return PTR_ERR (ctx); - resp.qp_attr_mask =0 ; -memset (&qp_attr,0 ,sizeof qp_attr); qp_attr.qp_state = cmd.qp_state;mutex_lock (&ctx->mutex); ret =rdma_init_qp_attr (ctx->cm_id, &qp_attr, &resp.qp_attr_mask);
Quoted 17 lines
drivers/infiniband/core/ucma.c +1
-1@@ -1232,7 +1232,7 @@ static ssize_t ucma_init_qp_attr(struct ucma_file *file,if (IS_ERR (ctx))return PTR_ERR (ctx); - resp.qp_attr_mask =0 ; +memset (&resp,0 ,sizeof (resp));memset (&qp_attr,0 ,sizeof qp_attr); qp_attr.qp_state = cmd.qp_state;mutex_lock (&ctx->mutex);Signature · 1 line
2.20.1
Quoted 28 lines · Leon Romanovsky
Quoted 11 lines · Dan Carpenter
From: Haimin Zhang <[email protected]>
The
ib_copy_ah_attr_to_user()function only initializes "resp.grh" if the "resp.is_global" flag is set. Unfortunately, this data is copied to the user and copying uninitialized stack data to the user is an information leak. Zero out the whole struct to be safe.Fixes 4ba66093bdc6 ("IB/core: Check for global flag when using ah_attr")Reported-by TCS Robot <[email protected]>Signed-off-by Haimin Zhang <[email protected]>Signed-off-by Dan Carpenter <[email protected]>Quoted 8 lines
---
Resending through the regular lists.I added parentheses around the sizeof to make checkpatch happy. s/sizeof resp/sizeof(resp)/.
drivers/infiniband/core/ucma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)The change is ok, but I prefer to initialize to zero as early as possible.
drivers/infiniband/core/ucma.c +0
-0
drivers/infiniband/core/ucma.c static ssize_t ucma_init_qp_attr(struct ucma_file *file, · line 1216
Quoted 8 lines
drivers/infiniband/core/ucma.c +2
-2@@ -1211,9 +1211,9 @@ static ssize_t ucma_init_qp_attr(struct ucma_file *file, int in_len, int out_len) {struct rdma_ucm_init_qp_attr cmd; -struct ib_uverbs_qp_attr resp; +struct ib_uverbs_qp_attr resp = {};struct ucma_context *ctx; -struct ib_qp_attr qp_attr; +struct ib_qp_attr qp_attr = {};
Will that catch all of the padding in the structure? This seems to come up a lot and I never remember...
thanks,
greg k-h
Quoted 23 lines · Greg KH
Quoted 22 lines · Leon Romanovsky
Quoted 11 lines · Dan Carpenter
From: Haimin Zhang <[email protected]>
The
ib_copy_ah_attr_to_user()function only initializes "resp.grh" if the "resp.is_global" flag is set. Unfortunately, this data is copied to the user and copying uninitialized stack data to the user is an information leak. Zero out the whole struct to be safe.Fixes 4ba66093bdc6 ("IB/core: Check for global flag when using ah_attr")Reported-by TCS Robot <[email protected]>Signed-off-by Haimin Zhang <[email protected]>Signed-off-by Dan Carpenter <[email protected]>Quoted 7 lines
Resending through the regular lists.
I added parentheses around the sizeof to make checkpatch happy. s/sizeof resp/sizeof(resp)/.
drivers/infiniband/core/ucma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)The change is ok, but I prefer to initialize to zero as early as possible.
Quoted 15 lines
drivers/infiniband/core/ucma.c static ssize_t ucma_init_qp_attr(struct ucma_file *file, · line 1216
Quoted 12 lines
drivers/infiniband/core/ucma.c +3
-2+++ b/drivers/infiniband/core/ucma.c@@ -1211,9 +1211,9 @@ static ssize_t ucma_init_qp_attr(struct ucma_file *file, int in_len, int out_len) {struct rdma_ucm_init_qp_attr cmd; -struct ib_uverbs_qp_attr resp; +struct ib_uverbs_qp_attr resp = {};struct ucma_context *ctx; -struct ib_qp_attr qp_attr; +struct ib_qp_attr qp_attr = {};Will that catch all of the padding in the structure? This seems to come up a lot and I never remember...
Yes, last time you asked we went over it.
Jason