RDS: IB: NULL dereference on error in rds_ib_alloc_frmr()
Subsystems (5)
PATCH 1/1 RDS: IB: NULL dereference on error in rds_ib_alloc_frmr()
We accidentally return ERR_PTR(0) if ib_alloc_mr() fails. The caller is expecting error pointers so it results in a NULL dereference.
net/rds/ib_frmr.c +2 -1
@@ -38,7 +38,7 @@ static struct rds_ib_mr *rds_ib_alloc_frmr(struct rds_ib_device *rds_ibdev,struct rds_ib_mr_pool *pool;struct rds_ib_mr *ibmr =NULL ;struct rds_ib_frmr *frmr; -int err =0 ; +int err;if (npages <=RDS_MR_8K_MSG_SIZE ) pool = rds_ibdev->mr_8k_pool;
@@ -61,6 +61,7 @@ static struct rds_ib_mr *rds_ib_alloc_frmr(struct rds_ib_device *rds_ibdev, pool->fmr_attr.max_pages);if (IS_ERR (frmr->mr)) {pr_warn ("RDS/IB: %s failed to allocate MR" , __func__); + err = -ENOMEM ; goto out_no_cigar; }
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 11 lines · Dan Carpenter
We accidentally return
ERR_PTR(0)ifib_alloc_mr()fails. The caller is expecting error pointers so it results in a NULL dereference.Fixes 1659185fb4d0 ("RDS: IB: Support Fastreg MR (FRMR) memory registration mode")Signed-off-by Dan Carpenter <[email protected]>net/rds/ib_frmr.c +0
-0
net/rds/ib_frmr.c static struct rds_ib_mr *rds_ib_alloc_frmr(struct rds_ib_device *rds_ibdev, · line 41
Quoted 5 lines
net/rds/ib_frmr.c +1
-1@@ -38,7 +38,7 @@ static struct rds_ib_mr *rds_ib_alloc_frmr(struct rds_ib_device *rds_ibdev,struct rds_ib_mr_pool *pool;struct rds_ib_mr *ibmr =NULL ;struct rds_ib_frmr *frmr; -int err =0 ; +int err;
Can we trust it'll be zero?
Quoted 15 lines
net/rds/ib_frmr.c +1
-1if (npages <=RDS_MR_8K_MSG_SIZE ) pool = rds_ibdev->mr_8k_pool;@@ -61,6 +61,7 @@ static struct rds_ib_mr *rds_ib_alloc_frmr(struct rds_ib_device *rds_ibdev, pool->fmr_attr.max_pages);if (IS_ERR (frmr->mr)) {pr_warn ("RDS/IB: %s failed to allocate MR" , __func__); + err = -ENOMEM ; goto out_no_cigar; } --To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 7 lines · Yuval Shaia
Quoted 6 lines · Dan Carpenter
We accidentally return
ERR_PTR(0)ifib_alloc_mr()fails. The caller is expecting error pointers so it results in a NULL dereference.Fixes 1659185fb4d0 ("RDS: IB: Support Fastreg MR (FRMR) memory registration mode")Signed-off-by Dan Carpenter <[email protected]>
Quoted 12 lines
net/rds/ib_frmr.c static struct rds_ib_mr *rds_ib_alloc_frmr(struct rds_ib_device *rds_ibdev, · line 41
Quoted 10 lines
net/rds/ib_frmr.c +1
-1@@ -38,7 +38,7 @@ static struct rds_ib_mr *rds_ib_alloc_frmr(struct rds_ib_device *rds_ibdev,struct rds_ib_mr_pool *pool;struct rds_ib_mr *ibmr =NULL ;struct rds_ib_frmr *frmr; -int err =0 ; +int err;Can we trust it'll be zero?
We don't ever want it to be zero. This way, hopefully, GCC will catch it if we introduce any new bugs where we forget to set it to negative.
regards,
dan carpenter
Yuval Shaia
Reviewed-byQuoted 21 lines · Dan Carpenter
Quoted 7 lines · Yuval Shaia
Quoted 6 lines · Dan Carpenter
We accidentally return
ERR_PTR(0)ifib_alloc_mr()fails. The caller is expecting error pointers so it results in a NULL dereference.Fixes 1659185fb4d0 ("RDS: IB: Support Fastreg MR (FRMR) memory registration mode")Signed-off-by Dan Carpenter <[email protected]>Quoted 12 lines
net/rds/ib_frmr.c static struct rds_ib_mr *rds_ib_alloc_frmr(struct rds_ib_device *rds_ibdev, · line 41
Quoted 10 lines
net/rds/ib_frmr.c +1
-1@@ -38,7 +38,7 @@ static struct rds_ib_mr *rds_ib_alloc_frmr(struct rds_ib_device *rds_ibdev,struct rds_ib_mr_pool *pool;struct rds_ib_mr *ibmr =NULL ;struct rds_ib_frmr *frmr; -int err =0 ; +int err;Can we trust it'll be zero?
Quoted 2 lines
We don't ever want it to be zero. This way, hopefully, GCC will catch it if we introduce any new bugs where we forget to set it to negative.
I see your point, in a "good" case we just return the ptr.
Quoted 4 lines
regards,
dan carpenter
Quoted 7 lines · Yuval Shaia
Quoted 6 lines · Dan Carpenter
We accidentally return
ERR_PTR(0)ifib_alloc_mr()fails. The caller is expecting error pointers so it results in a NULL dereference.Fixes 1659185fb4d0 ("RDS: IB: Support Fastreg MR (FRMR) memory registration mode")Signed-off-by Dan Carpenter <[email protected]>
Quoted 12 lines
net/rds/ib_frmr.c static struct rds_ib_mr *rds_ib_alloc_frmr(struct rds_ib_device *rds_ibdev, · line 41
Quoted 10 lines
net/rds/ib_frmr.c +1
-1@@ -38,7 +38,7 @@ static struct rds_ib_mr *rds_ib_alloc_frmr(struct rds_ib_device *rds_ibdev,struct rds_ib_mr_pool *pool;struct rds_ib_mr *ibmr =NULL ;struct rds_ib_frmr *frmr; -int err =0 ; +int err;Can we trust it'll be zero?
No need. With the change below there is always an assignment before the only reference at the end of the function.
julia
Quoted 21 lines
Quoted 13 lines
net/rds/ib_frmr.c +1
-1if (npages <=RDS_MR_8K_MSG_SIZE ) pool = rds_ibdev->mr_8k_pool;@@ -61,6 +61,7 @@ static struct rds_ib_mr *rds_ib_alloc_frmr(struct rds_ib_device *rds_ibdev, pool->fmr_attr.max_pages);if (IS_ERR (frmr->mr)) {pr_warn ("RDS/IB: %s failed to allocate MR" , __func__); + err = -ENOMEM ; goto out_no_cigar; } --Quoted 3 lines
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 6 lines · Dan Carpenter
We accidentally return
ERR_PTR(0)ifib_alloc_mr()fails. The caller is expecting error pointers so it results in a NULL dereference.Fixes 1659185fb4d0 ("RDS: IB: Support Fastreg MR (FRMR) memory registration mode")Signed-off-by Dan Carpenter <[email protected]>
Thanks Dan for fix.
You haven't copied netdev. Can you please resend the patch with my ack on netdev so that Dave can pick it up.
Quoted 27 lines · Dan Carpenter
We accidentally return
ERR_PTR(0)ifib_alloc_mr()fails. The caller is expecting error pointers so it results in a NULL dereference.Fixes 1659185fb4d0 ("RDS: IB: Support Fastreg MR (FRMR) memory registration mode")Signed-off-by Dan Carpenter <[email protected]>net/rds/ib_frmr.c +2
-1@@ -38,7 +38,7 @@ static struct rds_ib_mr *rds_ib_alloc_frmr(struct rds_ib_device *rds_ibdev,struct rds_ib_mr_pool *pool;struct rds_ib_mr *ibmr =NULL ;struct rds_ib_frmr *frmr; -int err =0 ; +int err;if (npages <=RDS_MR_8K_MSG_SIZE ) pool = rds_ibdev->mr_8k_pool;@@ -61,6 +61,7 @@ static struct rds_ib_mr *rds_ib_alloc_frmr(struct rds_ib_device *rds_ibdev, pool->fmr_attr.max_pages);if (IS_ERR (frmr->mr)) {pr_warn ("RDS/IB: %s failed to allocate MR" , __func__); + err = -ENOMEM ; goto out_no_cigar; }