Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3059014ybt; Mon, 29 Jun 2020 14:11:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzDVTNAwmiyazcDBf/9hOtiEyvyWbNy9g4v0U9PKF9uY16exOeLjt255X3bxJwH5f+8DafI X-Received: by 2002:a05:6402:2065:: with SMTP id bd5mr16050300edb.67.1593465102225; Mon, 29 Jun 2020 14:11:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593465102; cv=none; d=google.com; s=arc-20160816; b=rId8MXIzT4bA2ViNV8ns41gfRhXoX+tWeBNeJO57nVW+ZdP+7ZldBj01gyX09FAe2q e4kR3K57dS+rQGS/HKa5L5QauLWy9M17wGcoM6aaTwYE+NI/R0TxAK3RvUBj3AMF5cFQ a0ktTyIpG5skJjPwQdFN4/teFXOh5czDQyd9mf4vvU0DTjo3LysQr1NgL5A1/JTJqoeV /vCJXzZzK4msNKrGP/bf/hEbNDvTrt8gGlogwxCqKUwchRwdw/g6utgav+Y+uBFG0FB4 Pwpn1Na7UXd/ysE9F8cHMZIKi1ZxgKmjCAgpghzIZBBIT/Anfl9fSEfofz9D3KBbn4qg Ns4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gjfF2y1FbD2sDuzOS/uTKCXxJOAMFHNEmOyJrQcfzEU=; b=u0f0JKGs9nFQRvZ9RhWuP7wIPGdJo+JucXm03lz1DZZ1IrAzwQPDz0PVEqJOXZq++6 hlSpTs2idWWtL7rHswI9m9OW24WG7x111I9RaNRyo5v5Yco3A3+ZwOp8yjeUjEJngCVN DKUkMnHkuyzR8f1q8CzvdfnG1Ul5My2A4FJv4Llrc0gKp56NwsLgYHJqCmyliCv2+O2r 5Pdnm78AE3Ii2sOGjzzvyrEE6F20lxIB3Rwwi6PGv73mh5lN7V6/w5QI1bNJ5zozz9EJ K2e4njcxu92BwItjOMo4SPw/IugsCd33MU6EJaUtI72NusasCi7y3eFHnPpO4O9cjh5v VU0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Uy8zTG4N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o10si394469ejn.140.2020.06.29.14.11.19; Mon, 29 Jun 2020 14:11:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Uy8zTG4N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390124AbgF2VJv (ORCPT + 99 others); Mon, 29 Jun 2020 17:09:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:45424 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730318AbgF2TAS (ORCPT ); Mon, 29 Jun 2020 15:00:18 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 741152552E; Mon, 29 Jun 2020 15:54:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593446096; bh=aX5v3KXsyExJHrmVdV1Qa6ONasE96WpUM+mXSI/slVY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Uy8zTG4NmKhOTjYaoPZrfx5WMtPpeROttEjR+ONElm3xXAEMTI7yvjzDvRonk9WoB Z8MlKM336apfWiYcxOAMVwQw5C+oldnyAgHg77qA19ArZ+mOXcgpOZ0BRjK0F3PK63 laitQvQhARsB5rOwYMjZjXyZOEbAh5W/5g10dOZ0= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Marcelo Ricardo Leitner , Corey Minyard , "David S . Miller" , Greg Kroah-Hartman Subject: [PATCH 4.4 089/135] sctp: Don't advertise IPv4 addresses if ipv6only is set on the socket Date: Mon, 29 Jun 2020 11:52:23 -0400 Message-Id: <20200629155309.2495516-90-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200629155309.2495516-1-sashal@kernel.org> References: <20200629155309.2495516-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.4.229-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.4.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.4.229-rc1 X-KernelTest-Deadline: 2020-07-01T15:53+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marcelo Ricardo Leitner [ Upstream commit 471e39df96b9a4c4ba88a2da9e25a126624d7a9c ] If a socket is set ipv6only, it will still send IPv4 addresses in the INIT and INIT_ACK packets. This potentially misleads the peer into using them, which then would cause association termination. The fix is to not add IPv4 addresses to ipv6only sockets. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Reported-by: Corey Minyard Signed-off-by: Marcelo Ricardo Leitner Tested-by: Corey Minyard Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- include/net/sctp/constants.h | 8 +++++--- net/sctp/associola.c | 5 ++++- net/sctp/bind_addr.c | 1 + net/sctp/protocol.c | 1 + 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/include/net/sctp/constants.h b/include/net/sctp/constants.h index 8c337cd0e1e45..bf03bab93d9e9 100644 --- a/include/net/sctp/constants.h +++ b/include/net/sctp/constants.h @@ -357,11 +357,13 @@ typedef enum { ipv4_is_anycast_6to4(a)) /* Flags used for the bind address copy functions. */ -#define SCTP_ADDR6_ALLOWED 0x00000001 /* IPv6 address is allowed by +#define SCTP_ADDR4_ALLOWED 0x00000001 /* IPv4 address is allowed by local sock family */ -#define SCTP_ADDR4_PEERSUPP 0x00000002 /* IPv4 address is supported by +#define SCTP_ADDR6_ALLOWED 0x00000002 /* IPv6 address is allowed by + local sock family */ +#define SCTP_ADDR4_PEERSUPP 0x00000004 /* IPv4 address is supported by peer */ -#define SCTP_ADDR6_PEERSUPP 0x00000004 /* IPv6 address is supported by +#define SCTP_ADDR6_PEERSUPP 0x00000008 /* IPv6 address is supported by peer */ /* Reasons to retransmit. */ diff --git a/net/sctp/associola.c b/net/sctp/associola.c index f24d31f12cb44..aa38578fdfcd9 100644 --- a/net/sctp/associola.c +++ b/net/sctp/associola.c @@ -1575,12 +1575,15 @@ void sctp_assoc_rwnd_decrease(struct sctp_association *asoc, unsigned int len) int sctp_assoc_set_bind_addr_from_ep(struct sctp_association *asoc, sctp_scope_t scope, gfp_t gfp) { + struct sock *sk = asoc->base.sk; int flags; /* Use scoping rules to determine the subset of addresses from * the endpoint. */ - flags = (PF_INET6 == asoc->base.sk->sk_family) ? SCTP_ADDR6_ALLOWED : 0; + flags = (PF_INET6 == sk->sk_family) ? SCTP_ADDR6_ALLOWED : 0; + if (!inet_v6_ipv6only(sk)) + flags |= SCTP_ADDR4_ALLOWED; if (asoc->peer.ipv4_address) flags |= SCTP_ADDR4_PEERSUPP; if (asoc->peer.ipv6_address) diff --git a/net/sctp/bind_addr.c b/net/sctp/bind_addr.c index 871cdf9567e6b..664215448d09f 100644 --- a/net/sctp/bind_addr.c +++ b/net/sctp/bind_addr.c @@ -449,6 +449,7 @@ static int sctp_copy_one_addr(struct net *net, struct sctp_bind_addr *dest, * well as the remote peer. */ if ((((AF_INET == addr->sa.sa_family) && + (flags & SCTP_ADDR4_ALLOWED) && (flags & SCTP_ADDR4_PEERSUPP))) || (((AF_INET6 == addr->sa.sa_family) && (flags & SCTP_ADDR6_ALLOWED) && diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c index 9c6c42fd9f8af..b0e401dfe1600 100644 --- a/net/sctp/protocol.c +++ b/net/sctp/protocol.c @@ -210,6 +210,7 @@ int sctp_copy_local_addr_list(struct net *net, struct sctp_bind_addr *bp, * sock as well as the remote peer. */ if ((((AF_INET == addr->a.sa.sa_family) && + (copy_flags & SCTP_ADDR4_ALLOWED) && (copy_flags & SCTP_ADDR4_PEERSUPP))) || (((AF_INET6 == addr->a.sa.sa_family) && (copy_flags & SCTP_ADDR6_ALLOWED) && -- 2.25.1