netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jon Maloy <jon.maloy@ericsson.com>
To: <davem@davemloft.net>, <netdev@vger.kernel.org>
Cc: <parthasarathy.bhuvaragan@ericsson.com>, <ying.xue@windriver.com>,
	<tipc-discussion@lists.sourceforge.net>
Subject: [net-next v2 02/18] tipc: improve address sanity check in tipc_connect()
Date: Fri, 13 Oct 2017 11:04:18 +0200	[thread overview]
Message-ID: <1507885474-11213-3-git-send-email-jon.maloy@ericsson.com> (raw)
In-Reply-To: <1507885474-11213-1-git-send-email-jon.maloy@ericsson.com>

The address given to tipc_connect() is not completely sanity checked,
under the assumption that this will be done later in the function
__tipc_sendmsg() when the address is used there.

However, the latter functon will in the next commits serve as caller
to several other send functions, so we want to move the corresponding
sanity check there to the beginning of that function, before we possibly
need to grab the address stored by tipc_connect(). We must therefore
be able to trust that this address already has been thoroughly checked.

We do this in this commit.

Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Acked-by: Ying Xue <ying.xue@windriver.com>
---
 net/tipc/socket.c | 31 +++++++++++++++----------------
 1 file changed, 15 insertions(+), 16 deletions(-)

diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index 9a7e7b5c..7659e79 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -1911,28 +1911,27 @@ static int tipc_connect(struct socket *sock, struct sockaddr *dest,
 	int previous;
 	int res = 0;
 
+	if (destlen != sizeof(struct sockaddr_tipc))
+		return -EINVAL;
+
 	lock_sock(sk);
 
-	/* DGRAM/RDM connect(), just save the destaddr */
-	if (tipc_sk_type_connectionless(sk)) {
-		if (dst->family == AF_UNSPEC) {
-			memset(&tsk->peer, 0, sizeof(struct sockaddr_tipc));
-		} else if (destlen != sizeof(struct sockaddr_tipc)) {
+	if (dst->family == AF_UNSPEC) {
+		memset(&tsk->peer, 0, sizeof(struct sockaddr_tipc));
+		if (!tipc_sk_type_connectionless(sk))
 			res = -EINVAL;
-		} else {
-			memcpy(&tsk->peer, dest, destlen);
-		}
 		goto exit;
+	} else if (dst->family != AF_TIPC) {
+		res = -EINVAL;
 	}
-
-	/*
-	 * Reject connection attempt using multicast address
-	 *
-	 * Note: send_msg() validates the rest of the address fields,
-	 *       so there's no need to do it here
-	 */
-	if (dst->addrtype == TIPC_ADDR_MCAST) {
+	if (dst->addrtype != TIPC_ADDR_ID && dst->addrtype != TIPC_ADDR_NAME)
 		res = -EINVAL;
+	if (res)
+		goto exit;
+
+	/* DGRAM/RDM connect(), just save the destaddr */
+	if (tipc_sk_type_connectionless(sk)) {
+		memcpy(&tsk->peer, dest, destlen);
 		goto exit;
 	}
 
-- 
2.1.4

  parent reply	other threads:[~2017-10-13  9:04 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-13  9:04 [net-next v2 00/18] tipc: Introduce Communcation Group feature Jon Maloy
2017-10-13  9:04 ` [net-next v2 01/18] tipc: add ability to order and receive topology events in driver Jon Maloy
2017-10-13  9:04 ` Jon Maloy [this message]
2017-10-13  9:04 ` [net-next v2 03/18] tipc: add ability to obtain node availability status from other files Jon Maloy
2017-10-13  9:04 ` [net-next v2 04/18] tipc: refactor function filter_rcv() Jon Maloy
2017-10-13  9:04 ` [net-next v2 05/18] tipc: add new function for sending multiple small messages Jon Maloy
2017-10-13  9:04 ` [net-next v2 06/18] tipc: improve destination linked list Jon Maloy
2017-10-13  9:04 ` [net-next v2 07/18] tipc: introduce communication groups Jon Maloy
2017-10-13  9:04 ` [net-next v2 08/18] tipc: add second source address to recvmsg()/recvfrom() Jon Maloy
2017-10-13  9:04 ` [net-next v2 09/18] tipc: receive group membership events via member socket Jon Maloy
2017-10-13  9:04 ` [net-next v2 10/18] tipc: introduce flow control for group broadcast messages Jon Maloy
2017-10-13  9:04 ` [net-next v2 11/18] tipc: introduce group unicast messaging Jon Maloy
2017-10-13  9:04 ` [net-next v2 12/18] tipc: introduce group anycast messaging Jon Maloy
2017-10-13  9:04 ` [net-next v2 13/18] tipc: introduce group multicast messaging Jon Maloy
2017-10-13  9:04 ` [net-next v2 14/18] tipc: guarantee group unicast doesn't bypass group broadcast Jon Maloy
2017-10-13  9:04 ` [net-next v2 15/18] tipc: guarantee that group broadcast doesn't bypass group unicast Jon Maloy
2017-10-13  9:04 ` [net-next v2 16/18] tipc: guarantee delivery of UP event before first broadcast Jon Maloy
2017-10-13  9:04 ` [net-next v2 17/18] tipc: guarantee delivery of last broadcast before DOWN event Jon Maloy
2017-10-13  9:04 ` [net-next v2 18/18] tipc: add multipoint-to-point flow control Jon Maloy
2017-10-13 15:51 ` [net-next v2 00/18] tipc: Introduce Communcation Group feature David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1507885474-11213-3-git-send-email-jon.maloy@ericsson.com \
    --to=jon.maloy@ericsson.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=parthasarathy.bhuvaragan@ericsson.com \
    --cc=tipc-discussion@lists.sourceforge.net \
    --cc=ying.xue@windriver.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).