From nobody Sun Feb 8 18:33:19 2026 Delivered-To: wpasupplicant.patchew@gmail.com Received: by 2002:a02:9f92:0:0:0:0:0 with SMTP id a18csp1881680jam; Wed, 9 Feb 2022 01:47:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJx3BHWcQ4AfaJPiouCGOSZ1Rhzu4FcPZDaFmjeFtAfk6+0oPUI/JGuu+hh3izjHB6CkT2Jy X-Received: by 2002:a17:902:8f8b:: with SMTP id z11mr1611264plo.45.1644400066547; Wed, 09 Feb 2022 01:47:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644400066; cv=none; d=google.com; s=arc-20160816; b=MKol40dqD9SQik5RRE4La14kfbwPeoFVr5Cn332VvW2eNBp85d5iOsIOIaT9K6qiEn V7xb83lgLDwiBYt8qK65XkZidgFRJYkPCVK8weFXTIpnf7KWmHQ1YhFM7/rTTeYLc4de jamMj70/ipcrM+zLw6RLEIurS+yrOwJhUxBxVGblxoIsatho87purah4gTaaCUYn91tR TAPq1R5pEZc2KRMmliJyR790eX4Ii090iAdqFA3Odea+TMD1qPtr7Aux35K7NAZHw2eK U75IikeSIz/Dn9i3rEGcvloS6+UIOZGyhA+rc5Rjk6E1fWMKCoUO2itC5spBCRDVdJZ+ peVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from:dkim-signature; bh=ZlWhKHLLxSH3NQU7f7YpSzfHzpv6ql8uwYl1VmPivJ8=; b=Yq2on2MbG8y1oL2q932hT9y0rqm9dBrmfYl2sQXOfkoCmqs344AXL4NI0PULB0gdnd cDrhutlzNWtHrOd1gEjBVJfXvz4G5lNVS4+AdW7jJxFF/w9RJA6wJ4PtOqtmThHoHGLL 7KEI2OLhKbShwLNKVzMjR3YFyh0eO8ZcQ+bjbiX5vhHyMy+nJCnqFUEAn92oWBci00aa mtD3x7tbibSGYbBdbBg/2ZDgquh9U5GK/7XlDief0BDrXs7K2n3IfG5mU01SZcbh+G7M DIzZRHEHaORfvRVYpDzUUiGPPSS5hlwhRYyp0mOnTt0urVkRbwTDDfXsiUm1k5IG6M7S xsVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=eoF1Wnnl; spf=pass (google.com: domain of mptcp+bounces-3561-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:1000:8100::1 as permitted sender) smtp.mailfrom="mptcp+bounces-3561-wpasupplicant.patchew=gmail.com@lists.linux.dev"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sjc.edge.kernel.org (sjc.edge.kernel.org. [2604:1380:1000:8100::1]) by mx.google.com with ESMTPS id k1si16861629plk.132.2022.02.09.01.47.46 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Feb 2022 01:47:46 -0800 (PST) Received-SPF: pass (google.com: domain of mptcp+bounces-3561-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:1000:8100::1 as permitted sender) client-ip=2604:1380:1000:8100::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=eoF1Wnnl; spf=pass (google.com: domain of mptcp+bounces-3561-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:1000:8100::1 as permitted sender) smtp.mailfrom="mptcp+bounces-3561-wpasupplicant.patchew=gmail.com@lists.linux.dev"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sjc.edge.kernel.org (Postfix) with ESMTPS id E688E3E0F75 for ; Wed, 9 Feb 2022 09:47:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7E1FA2CA4; Wed, 9 Feb 2022 09:47:44 +0000 (UTC) X-Original-To: mptcp@lists.linux.dev Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3AA2D29CA for ; Wed, 9 Feb 2022 09:47:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644400062; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZlWhKHLLxSH3NQU7f7YpSzfHzpv6ql8uwYl1VmPivJ8=; b=eoF1WnnlMZGVhAK2E/nnHMz4SrUnfhz2bMtL0iVFoxcpzekHLy67lLuj1nNQwVsYLfDE02 FX68sOkGcPIT+JfIr4DqTNOn3neZlnWukRpQm1J+eatA3M6x7OCv2KzsqvYM+gTfEGCuk+ AO+6CDRJZn2ohY82+NCDrFytq4vgpUs= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-350-rZ514NSkO3a7bQvRJnj8qQ-1; Wed, 09 Feb 2022 04:47:40 -0500 X-MC-Unique: rZ514NSkO3a7bQvRJnj8qQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 786B48145E0 for ; Wed, 9 Feb 2022 09:47:39 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.39.193.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id DEEFD2A17B for ; Wed, 9 Feb 2022 09:47:38 +0000 (UTC) From: Paolo Abeni To: mptcp@lists.linux.dev Subject: [PATCH mptcp-net v3 2/4] mptcp: fix race in incoming ADD_ADDR option processing. Date: Wed, 9 Feb 2022 10:47:31 +0100 Message-Id: <911eab24cdc573cfce1865556aa1ec8986ea6e60.1644399915.git.pabeni@redhat.com> In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pabeni@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If an MPTCP endpoint received moltiple consecutive incoming ADD_ADDR options, mptcp_pm_add_addr_received() can overwrite the current remote address value after the PM lock is released in mptcp_pm_nl_add_addr_received() and before such address is echoed. Fix the issue caching the remote address value a little earlier and always using the cached value after releasing the PM lock. Fixes: f7efc7771eac ("mptcp: drop argument port from mptcp_pm_announce_addr= ") Signed-off-by: Paolo Abeni --- v2 -> v3: - properly initialize reset_port - Matt --- net/mptcp/pm_netlink.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index fb8d4bfcfbd6..98b485406afa 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -660,6 +660,7 @@ static void mptcp_pm_nl_add_addr_received(struct mptcp_= sock *msk) unsigned int add_addr_accept_max; struct mptcp_addr_info remote; unsigned int subflows_max; + bool reset_port =3D false; int i, nr; =20 add_addr_accept_max =3D mptcp_pm_get_add_addr_accept_max(msk); @@ -669,15 +670,19 @@ static void mptcp_pm_nl_add_addr_received(struct mptc= p_sock *msk) msk->pm.add_addr_accepted, add_addr_accept_max, msk->pm.remote.family); =20 - if (lookup_subflow_by_daddr(&msk->conn_list, &msk->pm.remote)) + remote =3D msk->pm.remote; + if (lookup_subflow_by_daddr(&msk->conn_list, &remote)) goto add_addr_echo; =20 + /* pick id 0 port, if none is provided the remote address */ + if (!remote.port) { + reset_port =3D true; + remote.port =3D sk->sk_dport; + } + /* connect to the specified remote address, using whatever * local address the routing configuration will pick. */ - remote =3D msk->pm.remote; - if (!remote.port) - remote.port =3D sk->sk_dport; nr =3D fill_local_addresses_vec(msk, addrs); =20 msk->pm.add_addr_accepted++; @@ -690,8 +695,12 @@ static void mptcp_pm_nl_add_addr_received(struct mptcp= _sock *msk) __mptcp_subflow_connect(sk, &addrs[i], &remote); spin_lock_bh(&msk->pm.lock); =20 + /* be sure to echo exactly the received address */ + if (reset_port) + remote.port =3D 0; + add_addr_echo: - mptcp_pm_announce_addr(msk, &msk->pm.remote, true); + mptcp_pm_announce_addr(msk, &remote, true); mptcp_pm_nl_addr_send_ack(msk); } =20 --=20 2.34.1