diff options
author | Andy Grover <andy.grover@oracle.com> | 2010-10-28 11:40:59 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2010-10-30 19:34:18 -0400 |
commit | d139ff0907dac9ef72fb2cf301e345bac3aec42f (patch) | |
tree | 0ba63235a10b7640bc8b613da0d0cda220a55087 /net/rds | |
parent | fc8162e3c034af743d8def435fda6396603d321f (diff) |
RDS: Let rds_message_alloc_sgs() return NULL
Even with the previous fix, we still are reading the iovecs once
to determine SGs needed, and then again later on. Preallocating
space for sg lists as part of rds_message seemed like a good idea
but it might be better to not do this. While working to redo that
code, this patch attempts to protect against userspace rewriting
the rds_iovec array between the first and second accesses.
The consequences of this would be either a too-small or too-large
sg list array. Too large is not an issue. This patch changes all
callers of message_alloc_sgs to handle running out of preallocated
sgs, and fail gracefully.
Signed-off-by: Andy Grover <andy.grover@oracle.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/rds')
-rw-r--r-- | net/rds/message.c | 5 | ||||
-rw-r--r-- | net/rds/rdma.c | 8 | ||||
-rw-r--r-- | net/rds/send.c | 4 |
3 files changed, 17 insertions, 0 deletions
diff --git a/net/rds/message.c b/net/rds/message.c index a84545dae370..848cff45183b 100644 --- a/net/rds/message.c +++ b/net/rds/message.c | |||
@@ -224,6 +224,9 @@ struct scatterlist *rds_message_alloc_sgs(struct rds_message *rm, int nents) | |||
224 | WARN_ON(rm->m_used_sgs + nents > rm->m_total_sgs); | 224 | WARN_ON(rm->m_used_sgs + nents > rm->m_total_sgs); |
225 | WARN_ON(!nents); | 225 | WARN_ON(!nents); |
226 | 226 | ||
227 | if (rm->m_used_sgs + nents > rm->m_total_sgs) | ||
228 | return NULL; | ||
229 | |||
227 | sg_ret = &sg_first[rm->m_used_sgs]; | 230 | sg_ret = &sg_first[rm->m_used_sgs]; |
228 | sg_init_table(sg_ret, nents); | 231 | sg_init_table(sg_ret, nents); |
229 | rm->m_used_sgs += nents; | 232 | rm->m_used_sgs += nents; |
@@ -246,6 +249,8 @@ struct rds_message *rds_message_map_pages(unsigned long *page_addrs, unsigned in | |||
246 | rm->m_inc.i_hdr.h_len = cpu_to_be32(total_len); | 249 | rm->m_inc.i_hdr.h_len = cpu_to_be32(total_len); |
247 | rm->data.op_nents = ceil(total_len, PAGE_SIZE); | 250 | rm->data.op_nents = ceil(total_len, PAGE_SIZE); |
248 | rm->data.op_sg = rds_message_alloc_sgs(rm, num_sgs); | 251 | rm->data.op_sg = rds_message_alloc_sgs(rm, num_sgs); |
252 | if (!rm->data.op_sg) | ||
253 | return ERR_PTR(-ENOMEM); | ||
249 | 254 | ||
250 | for (i = 0; i < rm->data.op_nents; ++i) { | 255 | for (i = 0; i < rm->data.op_nents; ++i) { |
251 | sg_set_page(&rm->data.op_sg[i], | 256 | sg_set_page(&rm->data.op_sg[i], |
diff --git a/net/rds/rdma.c b/net/rds/rdma.c index caa4d9866d92..8920f2a83327 100644 --- a/net/rds/rdma.c +++ b/net/rds/rdma.c | |||
@@ -607,6 +607,10 @@ int rds_cmsg_rdma_args(struct rds_sock *rs, struct rds_message *rm, | |||
607 | op->op_recverr = rs->rs_recverr; | 607 | op->op_recverr = rs->rs_recverr; |
608 | WARN_ON(!nr_pages); | 608 | WARN_ON(!nr_pages); |
609 | op->op_sg = rds_message_alloc_sgs(rm, nr_pages); | 609 | op->op_sg = rds_message_alloc_sgs(rm, nr_pages); |
610 | if (!op->op_sg) { | ||
611 | ret = -ENOMEM; | ||
612 | goto out; | ||
613 | } | ||
610 | 614 | ||
611 | if (op->op_notify || op->op_recverr) { | 615 | if (op->op_notify || op->op_recverr) { |
612 | /* We allocate an uninitialized notifier here, because | 616 | /* We allocate an uninitialized notifier here, because |
@@ -807,6 +811,10 @@ int rds_cmsg_atomic(struct rds_sock *rs, struct rds_message *rm, | |||
807 | rm->atomic.op_active = 1; | 811 | rm->atomic.op_active = 1; |
808 | rm->atomic.op_recverr = rs->rs_recverr; | 812 | rm->atomic.op_recverr = rs->rs_recverr; |
809 | rm->atomic.op_sg = rds_message_alloc_sgs(rm, 1); | 813 | rm->atomic.op_sg = rds_message_alloc_sgs(rm, 1); |
814 | if (!rm->atomic.op_sg) { | ||
815 | ret = -ENOMEM; | ||
816 | goto err; | ||
817 | } | ||
810 | 818 | ||
811 | /* verify 8 byte-aligned */ | 819 | /* verify 8 byte-aligned */ |
812 | if (args->local_addr & 0x7) { | 820 | if (args->local_addr & 0x7) { |
diff --git a/net/rds/send.c b/net/rds/send.c index 0bc9db17a87d..35b9c2e9caf1 100644 --- a/net/rds/send.c +++ b/net/rds/send.c | |||
@@ -973,6 +973,10 @@ int rds_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg, | |||
973 | /* Attach data to the rm */ | 973 | /* Attach data to the rm */ |
974 | if (payload_len) { | 974 | if (payload_len) { |
975 | rm->data.op_sg = rds_message_alloc_sgs(rm, ceil(payload_len, PAGE_SIZE)); | 975 | rm->data.op_sg = rds_message_alloc_sgs(rm, ceil(payload_len, PAGE_SIZE)); |
976 | if (!rm->data.op_sg) { | ||
977 | ret = -ENOMEM; | ||
978 | goto out; | ||
979 | } | ||
976 | ret = rds_message_copy_from_user(rm, msg->msg_iov, payload_len); | 980 | ret = rds_message_copy_from_user(rm, msg->msg_iov, payload_len); |
977 | if (ret) | 981 | if (ret) |
978 | goto out; | 982 | goto out; |