From nobody Mon Apr 29 23:44:06 2024 Delivered-To: wpasupplicant.patchew@gmail.com Received: by 2002:a02:3b21:0:0:0:0:0 with SMTP id c33csp1052023jaa; Tue, 1 Feb 2022 16:40:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJxSPKRD/EcFr0QBmjqg19fhInXr3tq4DotODpUAq9DiKGNvKDun0U177sLOQ25uE1ZL9VTy X-Received: by 2002:a63:6984:: with SMTP id e126mr19133171pgc.249.1643762442754; Tue, 01 Feb 2022 16:40:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643762442; cv=none; d=google.com; s=arc-20160816; b=HYmbzxvrshgLNtRcAHqNFecuYtd60lnGEEla/boQbKy9ckUtrMogdF+Gcui0/BtkJ5 9JMauksGz4GfShYItNKf19hAlX5KDrmhaUhXCNFIEESSKb/LZLE/ePNzKBWjC1VxRmZ3 LSN6v34BpBRN3HBlpmMIMHoG8hTBS9G3mf5+O9FFJ9jl5AhYmepCMfNfn7vJ0qutzDQR JP6UXCAbchmfOfz1ZwPtUEtQJEj/dIbpP2Yn0XQI0/6TRRcjMIAaaAa21Qhpn6fjVzbM igjLaO1kx+LcJ7rBazYftWA7NacTAI5ESRXS5F/JWLfeaBUw2Onrwyl+vxG79cr4R+cT 4PYA== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=39vWdzGDYLlYZdso4BAEOb/Lo79j2SpoWvVVljrPadM=; b=PR2YfC7sQGb55Ey755Nx9VSrp4fNC1M5SKupd3z6X09iyk0opGWnciy1GoJQJhkyBd VSZUoiC0u3bic/QLjdT6vpSH+zqMwpwUmr+hIoNhUHndEoqNqaGgnuK0FptbQzEm2ylh ZFbBBEWvrQSEpEQCXalaaxGK2UFMnq92vxwx7QXrZvIBzz6J7eNkuFDXsDLjET90rjMo hs61tIdao0MQpYZLuowPnb2eY4RV6JYuLPindPAgwOrWa72OO+KeewAd7YXBCkbM05RH 53S+BmPiSBYmDj+kt7YWWzAZhFyTYxoauuvo5Z4X/6+3b78u2Gnu2P1IMKnsZx2eRn3H t+Zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="dLvbR8I/"; spf=pass (google.com: domain of mptcp+bounces-3400-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:1000:8100::1 as permitted sender) smtp.mailfrom="mptcp+bounces-3400-wpasupplicant.patchew=gmail.com@lists.linux.dev"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 i4si15545665plb.295.2022.02.01.16.40.42 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Feb 2022 16:40:42 -0800 (PST) Received-SPF: pass (google.com: domain of mptcp+bounces-3400-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=@intel.com header.s=Intel header.b="dLvbR8I/"; spf=pass (google.com: domain of mptcp+bounces-3400-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:1000:8100::1 as permitted sender) smtp.mailfrom="mptcp+bounces-3400-wpasupplicant.patchew=gmail.com@lists.linux.dev"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 A5CB53E0F69 for ; Wed, 2 Feb 2022 00:40:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B9D5B2C9C; Wed, 2 Feb 2022 00:40:40 +0000 (UTC) X-Original-To: mptcp@lists.linux.dev Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (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 0BC9B2F25 for ; Wed, 2 Feb 2022 00:40:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1643762439; x=1675298439; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=Gpu84bcDw2fPX2Vd6X2nGsX2v4WpEFG/NzmKJQ9+Lno=; b=dLvbR8I/Zgmj5jLrXyU7wctMCjeRmK+vj6BGXFiMGojcnGCv0oqVvup2 IJOp2n2JfDps+3Hdyyn4I3Wh5C9R8mBi5YJILRwyJHWO0UAyEkZygTyON o+o78vLQhoQm/14TQNo5DvOXPC08Unkm7Ax3/JgV85UqGWDvLU+DcaHDs lfsnCSYzYNnKnXKlgG7gJHJNJKZgnFIKegjKQh7Vuj6zKr9jNXN6TZ3Rc lwMgWmeNpAcvDde08e9cGtjjVQxihmdvocay06RWRqo8NH/3ryO9Crgcl o+Um7dtG3Dynl5GGdO+5UQOxFs7wvtn6tPLSLvdkoDK4+O0/t47QbYvTQ g==; X-IronPort-AV: E=McAfee;i="6200,9189,10245"; a="247597157" X-IronPort-AV: E=Sophos;i="5.88,335,1635231600"; d="scan'208";a="247597157" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Feb 2022 16:40:38 -0800 X-IronPort-AV: E=Sophos;i="5.88,335,1635231600"; d="scan'208";a="769127737" Received: from mjmartin-desk2.amr.corp.intel.com (HELO mjmartin-desk2.intel.com) ([10.252.129.66]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Feb 2022 16:40:37 -0800 From: Mat Martineau To: mptcp@lists.linux.dev, pabeni@redhat.com Cc: Mat Martineau , stable@vger.kernel.org Subject: [PATCH mptcp-stable] mptcp: fix msk traversal in mptcp_nl_cmd_set_flags() Date: Tue, 1 Feb 2022 16:40:32 -0800 Message-Id: <20220202004032.208848-1-mathew.j.martineau@linux.intel.com> X-Mailer: git-send-email 2.35.1 Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" commit 8e9eacad7ec7a9cbf262649ebf1fa6e6f6cc7d82 upstream. The upstream commit had to handle a lookup_by_id variable that is only present in 5.17. This version of the patch removes that variable, so the __lookup_addr() function only handles the lookup as it is implemented in 5.15 and 5.16. It also removes one 'const' keyword to prevent a warning due to differing const-ness in the 5.17 version of addresses_equal(). The MPTCP endpoint list is under RCU protection, guarded by the pernet spinlock. mptcp_nl_cmd_set_flags() traverses the list without acquiring the spin-lock nor under the RCU critical section. This change addresses the issue performing the lookup and the endpoint update under the pernet spinlock. Fixes: 0f9f696a502e ("mptcp: add set_flags command in PM netlink") Signed-off-by: Mat Martineau Acked-by: Paolo Abeni --- Paolo, can I add an ack or signoff tag from you? The upstream commit (8e9eacad7ec7) was queued for the 5.16 and 5.15 stable trees, which brought along a few extra patches that didn't belong in stable. I asked Greg to drop those patches from his queue, and this particular commit required manual changes as described above (related to the lookup_by_id variable that's new in 5.16). This patch will not apply to the export branch. I confirmed that it applies, builds, and runs on both the 5.16.5 and 5.15.19 branches. Self tests succeed too. When I send to the stable list, I'll also include these tags: Cc: # 5.15.x Cc: # 5.16.x --- net/mptcp/pm_netlink.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 65764c8171b3..5d305fafd0e9 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -459,6 +459,18 @@ static unsigned int fill_remote_addresses_vec(struct m= ptcp_sock *msk, bool fullm return i; } =20 +static struct mptcp_pm_addr_entry * +__lookup_addr(struct pm_nl_pernet *pernet, struct mptcp_addr_info *info) +{ + struct mptcp_pm_addr_entry *entry; + + list_for_each_entry(entry, &pernet->local_addr_list, list) { + if (addresses_equal(&entry->addr, info, true)) + return entry; + } + return NULL; +} + static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk) { struct sock *sk =3D (struct sock *)msk; @@ -1725,17 +1737,21 @@ static int mptcp_nl_cmd_set_flags(struct sk_buff *s= kb, struct genl_info *info) if (addr.flags & MPTCP_PM_ADDR_FLAG_BACKUP) bkup =3D 1; =20 - list_for_each_entry(entry, &pernet->local_addr_list, list) { - if (addresses_equal(&entry->addr, &addr.addr, true)) { - mptcp_nl_addr_backup(net, &entry->addr, bkup); - - if (bkup) - entry->flags |=3D MPTCP_PM_ADDR_FLAG_BACKUP; - else - entry->flags &=3D ~MPTCP_PM_ADDR_FLAG_BACKUP; - } + spin_lock_bh(&pernet->lock); + entry =3D __lookup_addr(pernet, &addr.addr); + if (!entry) { + spin_unlock_bh(&pernet->lock); + return -EINVAL; } =20 + if (bkup) + entry->flags |=3D MPTCP_PM_ADDR_FLAG_BACKUP; + else + entry->flags &=3D ~MPTCP_PM_ADDR_FLAG_BACKUP; + addr =3D *entry; + spin_unlock_bh(&pernet->lock); + + mptcp_nl_addr_backup(net, &addr.addr, bkup); return 0; } =20 --=20 2.35.1