Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp77687rbb; Fri, 23 Feb 2024 12:20:35 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVEibndefzyxX3oUwz5Uv+1w4qiinRGmwZqR2j+snnoXdMAztOoQfwQQyRhS7ARNAMV+F1jahYA32vRkRqm2whMUWZq59xPSM+KwHf50w== X-Google-Smtp-Source: AGHT+IHAr27Q4M8tCdjp8pc6rd6QloChT0WpbPC7j+YTwlFkdCwi6667+LJQEtxT7RwrAezr924A X-Received: by 2002:a05:620a:388:b0:787:ad2a:91c4 with SMTP id q8-20020a05620a038800b00787ad2a91c4mr896510qkm.64.1708719634797; Fri, 23 Feb 2024 12:20:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708719634; cv=pass; d=google.com; s=arc-20160816; b=VJAMR0dXoqYRVpii+duVRkYTM1Hbe5iyahI+O8RWfAt8pzRwkOyDLIxQmM4to5RU1D ATjJVcnUpQuDZEndR04sv09F0aQQMCbAZQxor5hCwGWFQ94zqw6v/64D2ERDRVJoflZP 4g1l1fA18Y+f/6EZ11MigEH6nTMSXYive6CjhWHSoiO6gycGDZUgNR+rbrbAK5zN+iMx 2NfQRfDPLYP/lMcCOQZZP0yYx5ScImoUefJfm1gb1LXbZ/EtBqfk4pAz4j7zUmaue6m3 OZixBjep6+7ZiYE+8xxG+cHBjjADZGs6CfmGlCtLgTWufXxRmd0377RaBCaLXkY49S6m dYCg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=fK27vTrNC42j5nvPqtKjcRtbMuwnuNEZH8bh5ym1MzI=; fh=Z1YWgvxkmJ0/+y4FkLRSZ5mzUdtmyDAS67SU6REkp38=; b=XtUDlGtNzhp5+I51f2qRP0+pmSfFZJNiypX5wY7LY7Bj6maOX0xAHKnId0YWs5vnM+ nfH/2gDbgN5t1yYA9dw43upfiuzUfi3Kc+qicjrZPcykbyktwi1W9sPdR8tOXWTLHHPR rLTUMGxofWXBqoS+tt2rjR8JBpFzOD+BLBY+X844aPMz7Z54wwvZg1pG6ecPO1mWAt4h YNaMqApt8k6EUx9SzoUQNdw3Xj9jigs0R8yEXrxsw2qjKbdyN+rSr6d+EYQacv44PYa2 1msuDTvc/K6u5zC7i+HLnVFmS8t163YMTLCemMX90aYBaILvznEhxgjbAeGSDz6WhaAp 51Lg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="pRRy/pWa"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-79086-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79086-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id bj18-20020a05620a191200b007877d1e4229si4121717qkb.322.2024.02.23.12.20.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 12:20:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79086-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="pRRy/pWa"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-79086-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79086-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 870001C22705 for ; Fri, 23 Feb 2024 20:20:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A0A2D1493A7; Fri, 23 Feb 2024 20:19:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pRRy/pWa" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 E7A81146E84; Fri, 23 Feb 2024 20:19:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708719553; cv=none; b=jah+GJd0SGISxYpf2k+YN1C6VOq9sTxwD6FXCjremm7rPkDQu7TX5T1fwCgpk/RKt6Kvu65WZUpiM0tpOSoes5nPa+3v8rFXjXFr/WxhrkRTAcvJD4A8wXTH65HFLXr3iWcgAbJffdiyC6vQmSdmi/nSN7KI7H4VNMFz7N1Nt58= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708719553; c=relaxed/simple; bh=CUxFDPyTjDPgcgfn5h2C/Q9GGH3cNDWmsoWlzMpvK6c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HbWVRHMswrH1OJKbE54wQFgZlXXsIutISovrDjtZvI6qaK2jbgb+ttJIDYfTjt1YFGhy4nvIhOpP07LFRLCRqgbkArI8MUI/AB/jck9RRrk55dYd4arjnFm0QHNvvCgSzLQaisCp3bJUdQ9To1nUz41MX0aq0D2bSod1FhRoW14= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pRRy/pWa; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5195BC433C7; Fri, 23 Feb 2024 20:19:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708719551; bh=CUxFDPyTjDPgcgfn5h2C/Q9GGH3cNDWmsoWlzMpvK6c=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=pRRy/pWaoT1wDkwlVwp4ayT1x5iXCaJQZ4X5d6wrdqCCrpBDulYaIGVMYG+of5SA9 2kqwy91EIpIsFli8RAVVbHqHFNW1o01+KsBMvWIUDqMG6Lprao0pj4xwZnRuUwVksw 1eoPh2tbE81Qk8xQGsv4d8UhuYQOTMG3IEA8ljIRKQ6K7ALsXU4PghKKszckc98QrA LZysgVeqm4mRPFvLoXDueXueLDlXOhgIjFsMXmdk2zM/Cszy8J0gwzd8ZClbysy6Kk QqL7aYLam4chtYUmMoujxHQmf2YbttpyiYIeoWGuSUvenCiYAw6zb33G7iXf66MDcd qI+ipf1X13+1g== From: "Matthieu Baerts (NGI0)" Date: Fri, 23 Feb 2024 21:17:56 +0100 Subject: [PATCH net-next 4/8] mptcp: check the protocol in mptcp_sk() with DEBUG_NET Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240223-upstream-net-next-20240223-misc-improvements-v1-4-b6c8a10396bd@kernel.org> References: <20240223-upstream-net-next-20240223-misc-improvements-v1-0-b6c8a10396bd@kernel.org> In-Reply-To: <20240223-upstream-net-next-20240223-misc-improvements-v1-0-b6c8a10396bd@kernel.org> To: mptcp@lists.linux.dev, Mat Martineau , Geliang Tang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shuah Khan Cc: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, "Matthieu Baerts (NGI0)" X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1495; i=matttbe@kernel.org; h=from:subject:message-id; bh=CUxFDPyTjDPgcgfn5h2C/Q9GGH3cNDWmsoWlzMpvK6c=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBl2P2qEcJtSiUiDIwSGN1n9T5qWPvJ2VGPQKWAF p8P6A9lM4yJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZdj9qgAKCRD2t4JPQmmg c2gcEADibZI0WrfH0y2ybUH4yxBwbFJfUZEWnjhaaPJVdiH+/WjOcyRPvwLivx0QTPPAYOPiJ1c V4OHbrUISKyAhPMBuxmyXIpgwh93V2xcQF9+gjy7UTFzAm/1ql3uZncCAZNGO6+g9EJy8pyQCEO TTBmFcBI7o0/lxbJspHwUe+qQ0SSMJYxcVFgcX/B9de8tgJv1aQtLUC79PSTfm+oez+KrgXbr9S JFyI/MTIR4HmXLnwz7Y8PK+jr2uPZtqfar2z32/OMgLbynKlKKOvmNv5Uebi5baJvNVAPtCnau7 ASS4unrgi4KcxcoPCUa/juBrWX7rXc1XQT37ikK3D4CQ8rIIyOKEBPhy+5oMZ71TYg435Y46gb1 GgxyiwgsKIR5H0nF/+7B7yPPgCLt4u7vf1yh9whWycXga19ivpYG6sNa3e1+OK6/zb96oQaS7Cm gdAAlcuH8KvwUp92RkRpq2ERBfu9a5tpvaD+x1B9oIFQ2TShqLiHss3gJ1YvA4Mw0soc92tE/ov GNtbMrMxnO1jwiNv8iVqJcjvsfi929hhj29uHUCCnVNBn/UjTh1tTrOxFIJsoJMdWKcqPxCFEZP BTwXnwhoKDCMWxgRv2rWBJMG3jfwYaToN1J5HMm/ezi8kKE+v9CWu3VTg9+fUYii+I0G386Endj jckuvanoILA96vg== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 Fuzzers and static checkers might not detect when mptcp_sk() is used with a non mptcp_sock structure. This is similar to the parent commit, where it is easy to use mptcp_sk() with a TCP sock, e.g. with a subflow sk. So a new simple check is done when CONFIG_DEBUG_NET is enabled to tell kernel devs when a non-MPTCP socket is being used as an MPTCP one. 'mptcp_sk()' macro is then defined differently: with an extra WARN to complain when an unexpected socket is being used. Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/protocol.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 026ed360bd72..051b100d9403 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -356,9 +356,15 @@ static inline void msk_owned_by_me(const struct mptcp_sock *msk) WARN_ON(_ptr->sk_protocol != IPPROTO_TCP); \ container_of_const(_ptr, struct tcp_sock, inet_conn.icsk_inet.sk); \ }) -#endif +#define mptcp_sk(ptr) ({ \ + typeof(ptr) _ptr = (ptr); \ + WARN_ON(_ptr->sk_protocol != IPPROTO_MPTCP); \ + container_of_const(_ptr, struct mptcp_sock, sk.icsk_inet.sk); \ +}) +#else /* !CONFIG_DEBUG_NET */ #define mptcp_sk(ptr) container_of_const(ptr, struct mptcp_sock, sk.icsk_inet.sk) +#endif /* the msk socket don't use the backlog, also account for the bulk * free memory -- 2.43.0