RDS: Heap OOB write in rds_message_alloc_sgs()

Message ID 5a4be135.1296df0a.90c9.baea@mx.google.com
State Accepted
Delegated to: David Miller
Headers show
Series
  • RDS: Heap OOB write in rds_message_alloc_sgs()
Related show

Commit Message

simo.ghannam@gmail.com Jan. 2, 2018, 7:44 p.m.
From: Mohamed Ghannam <simo.ghannam@gmail.com>

When args->nr_local is 0, nr_pages gets also 0 due some size
calculation via rds_rm_size(), which is later used to allocate
pages for DMA, this bug produces a heap Out-Of-Bound write access
to a specific memory region.

Signed-off-by: Mohamed Ghannam <simo.ghannam@gmail.com>
---
 net/rds/rdma.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

David Miller Jan. 3, 2018, 4:24 p.m. | #1
From: simo.ghannam@gmail.com
Date: Tue,  2 Jan 2018 19:44:34 +0000

> From: Mohamed Ghannam <simo.ghannam@gmail.com>
> 
> When args->nr_local is 0, nr_pages gets also 0 due some size
> calculation via rds_rm_size(), which is later used to allocate
> pages for DMA, this bug produces a heap Out-Of-Bound write access
> to a specific memory region.
> 
> Signed-off-by: Mohamed Ghannam <simo.ghannam@gmail.com>

Applied and queued up for -stable, thanks.

Patch

diff --git a/net/rds/rdma.c b/net/rds/rdma.c
index bc2f1e0977d6..40a733566eb7 100644
--- a/net/rds/rdma.c
+++ b/net/rds/rdma.c
@@ -525,6 +525,9 @@  int rds_rdma_extra_size(struct rds_rdma_args *args)
 
 	local_vec = (struct rds_iovec __user *)(unsigned long) args->local_vec_addr;
 
+	if (args->nr_local == 0)
+		return -EINVAL;
+
 	/* figure out the number of pages in the vector */
 	for (i = 0; i < args->nr_local; i++) {
 		if (copy_from_user(&vec, &local_vec[i],