Commit c29c3f70 authored by Allan Stephens's avatar Allan Stephens Committed by Paul Gortmaker

tipc: Abort excessive send requests as early as possible

Adds checks to TIPC's socket send routines to promptly detect and
abort attempts to send more than 66,000 bytes in a single TIPC
message or more than 2**31-1 bytes in a single TIPC byte stream request.
In addition, this ensures that the number of iovecs in a send request
does not exceed the limits of a standard integer variable.
Signed-off-by: default avatarAllan Stephens <Allan.Stephens@windriver.com>
Signed-off-by: default avatarPaul Gortmaker <paul.gortmaker@windriver.com>
parent 66e019a6
...@@ -101,7 +101,7 @@ static inline unsigned int tipc_node(__u32 addr) ...@@ -101,7 +101,7 @@ static inline unsigned int tipc_node(__u32 addr)
* Limiting values for messages * Limiting values for messages
*/ */
#define TIPC_MAX_USER_MSG_SIZE 66000 #define TIPC_MAX_USER_MSG_SIZE 66000U
/* /*
* Message importance levels * Message importance levels
......
...@@ -535,6 +535,9 @@ static int send_msg(struct kiocb *iocb, struct socket *sock, ...@@ -535,6 +535,9 @@ static int send_msg(struct kiocb *iocb, struct socket *sock,
if (unlikely((m->msg_namelen < sizeof(*dest)) || if (unlikely((m->msg_namelen < sizeof(*dest)) ||
(dest->family != AF_TIPC))) (dest->family != AF_TIPC)))
return -EINVAL; return -EINVAL;
if ((total_len > TIPC_MAX_USER_MSG_SIZE) ||
(m->msg_iovlen > (unsigned)INT_MAX))
return -EMSGSIZE;
if (iocb) if (iocb)
lock_sock(sk); lock_sock(sk);
...@@ -640,6 +643,10 @@ static int send_packet(struct kiocb *iocb, struct socket *sock, ...@@ -640,6 +643,10 @@ static int send_packet(struct kiocb *iocb, struct socket *sock,
if (unlikely(dest)) if (unlikely(dest))
return send_msg(iocb, sock, m, total_len); return send_msg(iocb, sock, m, total_len);
if ((total_len > TIPC_MAX_USER_MSG_SIZE) ||
(m->msg_iovlen > (unsigned)INT_MAX))
return -EMSGSIZE;
if (iocb) if (iocb)
lock_sock(sk); lock_sock(sk);
...@@ -723,6 +730,12 @@ static int send_stream(struct kiocb *iocb, struct socket *sock, ...@@ -723,6 +730,12 @@ static int send_stream(struct kiocb *iocb, struct socket *sock,
goto exit; goto exit;
} }
if ((total_len > (unsigned)INT_MAX) ||
(m->msg_iovlen > (unsigned)INT_MAX)) {
res = -EMSGSIZE;
goto exit;
}
/* /*
* Send each iovec entry using one or more messages * Send each iovec entry using one or more messages
* *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment