From patchwork Tue Feb 7 13:04:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Baerts X-Patchwork-Id: 53872 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2836206wrn; Tue, 7 Feb 2023 05:05:52 -0800 (PST) X-Google-Smtp-Source: AK7set85QLTKoWLetWNpbyMDK778cy7OU0C0VAbaYrM7W2NpNzugPJm5xvF9lsA+ALPGd34m6AyK X-Received: by 2002:a17:906:ae5a:b0:887:d8b0:27c5 with SMTP id lf26-20020a170906ae5a00b00887d8b027c5mr3429929ejb.52.1675775152052; Tue, 07 Feb 2023 05:05:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675775152; cv=none; d=google.com; s=arc-20160816; b=fwSBy67mwPC3SgaDIuT0Lpvw9a88DXfmBEjjHc1ZCLY09hPHOp870oFFPj5Kt4a/JM TzJePnlE2ifQD3rP365NpGhStGNFniMB9J+bvFUZNXLtNN0yb1FWkl6tC8cN0RigVPmM k596Di4Uk268G+72/f10cnI+fAJ64NgTQpU5oU8Ym7pwN3ADj3Fv3vi+qpdtWLZD2/79 HmVaKz6TcS5C2ky+Nmfd6EQ/i1zUnScm4w8yui2M8XhFYN7kGPGoh7fB1ePfIC5MDcgy F+CHlNsMkdz9GtEBFrN759RI7OqpwprmQ781wEoVL4lfKa3slG/C3q4jnfedX02IaVdo W4Hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=JmesjpDIr41PWKtzB6vOyUJvIfGcXoSXXW1ARPTGITM=; b=BgpKfb7xeckxrEwiY7dE1rTYoBC7/Wv1zIZcsJilPz4c6M8AGLshftD69G0o9NRX4V zw5hrDMOhhQn4nwyIvC5M7ZJ8XtjgX2PxAKAZqMNTKRuH5ZvXUx18jRu6DGCgFYvov/1 qTc0coJ0OAyqwqTdFNVazydPkjIfAXPd+YwbsK0w1vrjHGtos29HpUz2qwTv1Zg5pPk8 SHHOxCjUXwA0knQst8rMJh6jxEmMaOX6PW4bdO2s80A3rBczE/vzYDcWPITIpiwzMfAy pdS88Pkm7+kzz2JiEkXyJHs+5K7DJc4omlqx91HG907rgmk2Y+bgg486yFXLvM6WZjIx G6Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tessares.net header.s=google header.b="owM3VR/j"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=tessares.net Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k2-20020aa7c382000000b004aaa94fbe4bsi8458236edq.385.2023.02.07.05.05.28; Tue, 07 Feb 2023 05:05:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@tessares.net header.s=google header.b="owM3VR/j"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=tessares.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232144AbjBGNFH (ORCPT + 99 others); Tue, 7 Feb 2023 08:05:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232130AbjBGNEz (ORCPT ); Tue, 7 Feb 2023 08:04:55 -0500 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E5F139296 for ; Tue, 7 Feb 2023 05:04:46 -0800 (PST) Received: by mail-wr1-x42f.google.com with SMTP id i5so6312675wrc.0 for ; Tue, 07 Feb 2023 05:04:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tessares.net; s=google; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=JmesjpDIr41PWKtzB6vOyUJvIfGcXoSXXW1ARPTGITM=; b=owM3VR/jlNpYcBXX8SZAxXp1etnWM6U2dXrfws3gNjXUFOyb7fN8PzE3YmG3EI7Yyg 6/8Q66QFBkLywuVTaZgLQ+M3i8Glgkldi0YROlbo3qGt+vn/wmbEDjkQlr+Wh6pW4ny2 MJfwTU/dX8l8Es5leQcD2/8jG7BSJyB0CGKlT1+P7jchzA3TRvUoIZ0IUL/sq4GyGP82 vo1lpuNAQdsgKrMhDVIgoWmeFHkc/vu9zAfjE04M0Bp4SZ31NGfXorI0czA7ZRgzuT/Z uKuq/ZXWUDqTQB2x6m8ZkFQJ/QxjDyFgyVnBmZ+QGwaRB+/WzgbvP+q3Qd066gJQC0Dd +7ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JmesjpDIr41PWKtzB6vOyUJvIfGcXoSXXW1ARPTGITM=; b=1S1VZ+hHoVQZLPqZBKGizuG6uM4yMKgSnsIu9222S6tzkjfZoaCQ3SXjcB0NmMnG5K byRmrjEkzKJ0M5tAS4pbVb4kpVBWJgpCYzMzRzp5Mz2uwvqsmGK9InD2PNjJxkbQQwqg DEzlkry5t1oubhcslCoTvZRjI+gIj6XfsWpN+VQdaPFNNDYju/YEkDY+C6ggmzBovX3K nGhl7pk+0B5X3NNJV5pKheympTjxH8qWN0s6B5T/x5uGz0VS8O7yYNsjh5djSe46G+fH RTiNMYz9zflW1IUa0XSeWIFCGu27F0fVgknBwpzyFclHfS4VjSGwuAiPf1PtUDqTa7HJ uCcg== X-Gm-Message-State: AO0yUKVRz3wIBhgwNqq+T2AhKBjjRspN3eZPqWK/mkUmOecH+7r+stac TcEnUBguy/U/NqvgcUUDkzukHA== X-Received: by 2002:adf:f783:0:b0:2bf:c741:5956 with SMTP id q3-20020adff783000000b002bfc7415956mr2476789wrp.19.1675775085136; Tue, 07 Feb 2023 05:04:45 -0800 (PST) Received: from vdi08.nix.tessares.net (static.219.156.76.144.clients.your-server.de. [144.76.156.219]) by smtp.gmail.com with ESMTPSA id n9-20020a5d5989000000b002bc7fcf08ddsm11645394wri.103.2023.02.07.05.04.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Feb 2023 05:04:44 -0800 (PST) From: Matthieu Baerts Date: Tue, 07 Feb 2023 14:04:15 +0100 Subject: [PATCH net 3/6] mptcp: fix locking for in-kernel listener creation MIME-Version: 1.0 Message-Id: <20230207-upstream-net-20230207-various-fix-6-2-v1-3-2031b495c7cc@tessares.net> References: <20230207-upstream-net-20230207-various-fix-6-2-v1-0-2031b495c7cc@tessares.net> In-Reply-To: <20230207-upstream-net-20230207-various-fix-6-2-v1-0-2031b495c7cc@tessares.net> To: mptcp@lists.linux.dev, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Davide Caratti , Mat Martineau , Benjamin Hesmans , Geliang Tang , Shuah Khan Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Matthieu Baerts , stable@vger.kernel.org X-Mailer: b4 0.12.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=2251; i=matthieu.baerts@tessares.net; h=from:subject:message-id; bh=XqGLRd5Gpr7HPf6uQpX8sWyYQO0xBG7RUyxFxCjNxK0=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBj4kxovoLKV49l0355uwyXmfmFrMmpaxMCjYT6d x2e2nb+W/WJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCY+JMaAAKCRD2t4JPQmmg cx4JD/4qaEwAHa2J7Ygws0P1+1OO4C/tG0wO+xAF48Op10/BYRxRsw8VL1OyifNuO46USuHEcoK kRhuZsn4dUiinVV7xNUK8zW/yayMo21TZEzheAd9zx1C6ut48HKofQ3XMbQir/T4C/Mv0qprdrQ p+k9FjgW3eph3rq1FUhI5n0/GYGmh54+wfo3aA4Ache57HqU3/K0+4bMix16VEi2sWEIsGh2K4R Xw0FCTdZkh5Rm0xRVQzHgSEC76MSzukJ2T8ggFTOOLdWNbt6wkBv8PuVrWpJjSk+0S1aIu2j1y3 sdvQ/ieBfT4dOzKnM0QrpLRN8pjgxbUg88SHthyfPs6z0yOLaVJxS/0da1o2tRHKP9NVE3S9EI3 9Q41hVCZ1T/7nu1HL3w+80ryzuxAVEFb2QbnVNnQABWHq34iJ5eFKb3N8JkhoBzu0XtAwzP+qta 3a8gNgC0mSUltHexuRf3KgpgUgG9yKuP2wOddCRlTJjt62hW1EBW6KhKbEc/JCMqdMZMeu/xz3s y4md89lL+0ThShZNKZzUhtP+9MTIFeXiaBIMnIk9BR7g1hISdugxKR445k0LZk/L8bkPdWTjBj2 7Q+1Ks8kvhzCztT5/Zu38EUJ8f2QXiwjdyCrrFRAC82ylDIr6fT26MioCzQPilLdUcXHhJU/h80 AmaL9/lyTTi0+Ng== X-Developer-Key: i=matthieu.baerts@tessares.net; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757177605785684012?= X-GMAIL-MSGID: =?utf-8?q?1757177605785684012?= From: Paolo Abeni For consistency, in mptcp_pm_nl_create_listen_socket(), we need to call the __mptcp_nmpc_socket() under the msk socket lock. Note that as a side effect, mptcp_subflow_create_socket() needs a 'nested' lockdep annotation, as it will acquire the subflow (kernel) socket lock under the in-kernel listener msk socket lock. The current lack of locking is almost harmless, because the relevant socket is not exposed to the user space, but in future we will add more complexity to the mentioned helper, let's play safe. Fixes: 1729cf186d8a ("mptcp: create the listening socket for new port") Cc: stable@vger.kernel.org Signed-off-by: Paolo Abeni Reviewed-by: Matthieu Baerts Signed-off-by: Matthieu Baerts --- net/mptcp/pm_netlink.c | 10 ++++++---- net/mptcp/subflow.c | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 2ea7eae43bdb..10fe9771a852 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -998,8 +998,8 @@ static int mptcp_pm_nl_create_listen_socket(struct sock *sk, { int addrlen = sizeof(struct sockaddr_in); struct sockaddr_storage addr; - struct mptcp_sock *msk; struct socket *ssock; + struct sock *newsk; int backlog = 1024; int err; @@ -1008,11 +1008,13 @@ static int mptcp_pm_nl_create_listen_socket(struct sock *sk, if (err) return err; - msk = mptcp_sk(entry->lsk->sk); - if (!msk) + newsk = entry->lsk->sk; + if (!newsk) return -EINVAL; - ssock = __mptcp_nmpc_socket(msk); + lock_sock(newsk); + ssock = __mptcp_nmpc_socket(mptcp_sk(newsk)); + release_sock(newsk); if (!ssock) return -EINVAL; diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index ec54413fb31f..a3e5026bee5b 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -1679,7 +1679,7 @@ int mptcp_subflow_create_socket(struct sock *sk, unsigned short family, if (err) return err; - lock_sock(sf->sk); + lock_sock_nested(sf->sk, SINGLE_DEPTH_NESTING); /* the newly created socket has to be in the same cgroup as its parent */ mptcp_attach_cgroup(sk, sf->sk);