From patchwork Wed Jun 9 14:22:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Mikityanskiy X-Patchwork-Id: 458429 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6961C48BCD for ; Wed, 9 Jun 2021 14:23:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D2A5F613B8 for ; Wed, 9 Jun 2021 14:23:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237946AbhFIOY6 (ORCPT ); Wed, 9 Jun 2021 10:24:58 -0400 Received: from mail-dm3nam07on2047.outbound.protection.outlook.com ([40.107.95.47]:13920 "EHLO NAM02-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S237794AbhFIOYs (ORCPT ); Wed, 9 Jun 2021 10:24:48 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BEt0mdwyVBzehEIIktD5x4mI8gaj5PWCzLb60ZZvs4fJGMn1iA+Nfb7wAvZFjRaNVEGxZKPy8zw/q3U37ggGPz5Bi1b38dV25MURGqH0KJLh0CWgasSaRco8ix70MRGeRMhglVCOw7eMR/A7pl45U3Vuf5Kk21LEYBJ/bCauJAfpOvocyDR6pd85Gc+NSwIsz95zAal/DdZFYlJEFwYKpx+BTBm3IWbTO4h54eytiSyDYM9JbIF6avhk3s6oNpcqpHhl3tVW/1bZ+LMyl366SwACy3csFHGwKQNW8ivKUTWypBfnHBTSWnjkmA5cFE6IS/S0liZDbVf6hXwBM/aIMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8yMCxIxZol2c+lPp7M0M/1j3OtKTnf2YOuTKQI2ug8c=; b=ODZfNwZFPK+sMQg91xo2hcq7snAQ7lKTpqQ5DYQpQHP09cX0Hwxri2IeQuwRjqlrfk4gyTEKrUElcO2FNZ2Gofu52gue5VeNoD28N79MP8w9sdhGYkVsVJLLXT702jRBBUHjLr9ZflEfdSZW1ctgralRf+DNtFtLjL7xAcunVKLhHMQ1OPf/VwRcYCI3E3k71EiQzUuIQoUXuUo3tVOD8jGsHkl652elVMb6FKgMYoqw6ziY5JQ/j8M0t8/HC8iPzV6na3fWvX0ixtzBykR+2Zt8CnCQI/hgIAdTsMILPaV145nuSS42TOfYU9+gA35ms3025kqB+0ZxPUAUjh0z2w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.35) smtp.rcpttodomain=linux.intel.com smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8yMCxIxZol2c+lPp7M0M/1j3OtKTnf2YOuTKQI2ug8c=; b=pvrQPY1g5UNUdarHwzdrVN43+eMhpuoG45OZ+eu72oUVPcWvKPtbg4NHvAINZ4nGjRkgelHFDpCnV1Bil6PaGx+4ZZcXv+vD6Bj85AzO0dOefxLplar47xqlFz6MTmEg6XDcZiNkvOOGUYJ7TD1334XSqUahQLAP1dW61oS20z+GwxgtIvxIgWkMkLCbBTQ0Ck3jVQ2Yt8GLmdJflsuvivsHyuO1/9vK5L3Ylmmc11NiBJYsy/XINOPUMBvAZmFkYTvBSYqd+WcHJJSl1RvHYdI/f8SMxWovCj+8TTHbBIEBtlPzNsfxc1aRJ3mxvSg2vCoq9Xg1DSVIp2w1dDR+Xw== Received: from CO1PR15CA0102.namprd15.prod.outlook.com (2603:10b6:101:21::22) by CH0PR12MB5106.namprd12.prod.outlook.com (2603:10b6:610:bd::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.24; Wed, 9 Jun 2021 14:22:52 +0000 Received: from CO1NAM11FT037.eop-nam11.prod.protection.outlook.com (2603:10b6:101:21:cafe::d7) by CO1PR15CA0102.outlook.office365.com (2603:10b6:101:21::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.21 via Frontend Transport; Wed, 9 Jun 2021 14:22:51 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.35) smtp.mailfrom=nvidia.com; linux.intel.com; dkim=none (message not signed) header.d=none; linux.intel.com; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.35 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.35; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.35) by CO1NAM11FT037.mail.protection.outlook.com (10.13.174.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4219.21 via Frontend Transport; Wed, 9 Jun 2021 14:22:51 +0000 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 9 Jun 2021 14:22:51 +0000 Received: from HQMAIL107.nvidia.com (172.20.187.13) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 9 Jun 2021 14:22:50 +0000 Received: from vdi.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.13) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 9 Jun 2021 14:22:46 +0000 From: Maxim Mikityanskiy To: Mat Martineau , Matthieu Baerts , Jakub Kicinski , "David S. Miller" , Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= , "Jamal Hadi Salim" , Cong Wang , Jiri Pirko , Patrick McHardy , Jesper Dangaard Brouer , Paolo Abeni , Christoph Paasch , Peter Krystad CC: Young Xiao <92siuyang@gmail.com>, , "Maxim Mikityanskiy" Subject: [PATCH net 1/3] netfilter: synproxy: Fix out of bounds when parsing TCP options Date: Wed, 9 Jun 2021 17:22:10 +0300 Message-ID: <20210609142212.3096691-2-maximmi@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210609142212.3096691-1-maximmi@nvidia.com> References: <20210609142212.3096691-1-maximmi@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7d3327c2-8ce3-4958-3a67-08d92b5210c2 X-MS-TrafficTypeDiagnostic: CH0PR12MB5106: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:538; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: U4r/ZE+kv1twrAOvB/76znE0xC77Se79sepeAVVPmkCprN1CIK5Xpovt5Sd+a/YQbQ1EN+CzPmAxkdlVxcR8kH26oLgoQnTKKpMVQlx+vO2S6sBE5faw4Z1H5883H6j7MGcrWlNHvSe179wUyUaLd/IBePRfQDxr/92uvNzlOHHc4Y8TzIoWFpKxfHG/a2GSPCm+u4KAeXp7R/fDajfRyy02C3wHTG8L0aIRWgE8uKlBq9W+Q/o2PUSAA5aWG/mUVbf91qo1FwraCw19YT28jG1LLnC9uC/J0ssF+R7euvSsQZBjvnd9UXhs3uiMcMQhAZhRv35UbwxoL1oHNUJL6BsTWfTAS+mtr/Impotf/DqziHLehDZUn3xWCmIV8Cg44Bl6w1WrZx+92sKkhK5+xrL7cv8Vp+T9stD8aIt4JSxjCgYcTLphjs0vynLmeoN4iOLkccXy23hxnGNG0RI/XBjsbduUxN4q6TjV6sj9gRnhOY419x/ihe2K9bTfaE8qIXDC3/vhJfYeC2o09eNKkI45kKkrnjprFMn4MwQOOyEJCRKy3I+hr0YoEtOwbLLr6V+GoBErBMjCeq1yeHWvzwqqAdJvyEeh44uRGmVIb0KOQm0EI9ovafUQb+8Yk+g90A1myhDTQGeOr0nlhINsMXSww4fYRQLotf+ByRUEqTQ= X-Forefront-Antispam-Report: CIP:216.228.112.35; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid02.nvidia.com; CAT:NONE; SFS:(4636009)(376002)(396003)(136003)(39860400002)(346002)(46966006)(36840700001)(86362001)(426003)(82310400003)(7636003)(316002)(356005)(6666004)(186003)(7696005)(54906003)(47076005)(110136005)(8676002)(336012)(478600001)(36906005)(4326008)(26005)(83380400001)(1076003)(5660300002)(921005)(107886003)(70206006)(8936002)(82740400003)(36756003)(7416002)(36860700001)(70586007)(2616005)(2906002); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jun 2021 14:22:51.6963 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7d3327c2-8ce3-4958-3a67-08d92b5210c2 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.35]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT037.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5106 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The TCP option parser in synproxy (synproxy_parse_options) could read one byte out of bounds. When the length is 1, the execution flow gets into the loop, reads one byte of the opcode, and if the opcode is neither TCPOPT_EOL nor TCPOPT_NOP, it reads one more byte, which exceeds the length of 1. This fix is inspired by commit 9609dad263f8 ("ipv4: tcp_input: fix stack out of bounds when parsing TCP options."). Cc: Young Xiao <92siuyang@gmail.com> Fixes: 48b1de4c110a ("netfilter: add SYNPROXY core/target") Signed-off-by: Maxim Mikityanskiy --- net/netfilter/nf_synproxy_core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/netfilter/nf_synproxy_core.c b/net/netfilter/nf_synproxy_core.c index b100c04a0e43..621eb5ef9727 100644 --- a/net/netfilter/nf_synproxy_core.c +++ b/net/netfilter/nf_synproxy_core.c @@ -47,6 +47,8 @@ synproxy_parse_options(const struct sk_buff *skb, unsigned int doff, length--; continue; default: + if (length < 2) + return true; opsize = *ptr++; if (opsize < 2) return true; From patchwork Wed Jun 9 14:22:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Mikityanskiy X-Patchwork-Id: 457398 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77281C48BCD for ; Wed, 9 Jun 2021 14:23:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6449C613B8 for ; Wed, 9 Jun 2021 14:23:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237999AbhFIOZI (ORCPT ); Wed, 9 Jun 2021 10:25:08 -0400 Received: from mail-dm6nam11on2057.outbound.protection.outlook.com ([40.107.223.57]:21345 "EHLO NAM11-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S237849AbhFIOYw (ORCPT ); Wed, 9 Jun 2021 10:24:52 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=F+5dsQJt2pzeDgxsX5iXLLJs6nknIEY8dmDUoF6+irfWVHcwN8B/SCJrVaZnHJFadXve+r0KZRLkPRqidG56kGdCPPIlqxAxEOcKYpXxK+2pJUNYCJZOgSRfsI1bPNm3VLpA7gEimt1whhzacaZ9IZt+o3uC2eSoWF636magQ690zprEboCrYxfa0Fr0qqHx2z6DXTEKR3GJBgq054ZzJit3HJf3PzH2IqnO2Y7ZvxXiyYDoaNobl2uXQUmsnXQYuysoTPbcE1S+AqGViF/GG78EYlPrD2m4mJWuBCeeQgkAup+F1VLrlVC1nHP8nVLC8VVgUbotOCH+hWJ5AjGwYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/QYR+S9r80f57bvrxBVwzzjQpZL5NkbBqrMjIadmWq8=; b=MVSDfhdNF1CRqmulNYtOuPKs9UiE6FqF3NxD79/BNv5+UgYQf0j5SL7FFJ1RIAwUrOZUZ4zwox8iWV1a+SyfPrEyZdYOPseiDRwB03TXY1NqcrYZ5gxiDMh1mq4mUvb5g8xekmglINoiaIB9BEOTF/rQgxIh3kGCepLB+WRPtltWmOwJpkoBaN+4QmHOR4LPmf4AbXljImj6iUPs1m7V7LKNFqTM5AJFXZSCDrSNnOzY9yai6YAsmRIbLCsVhoFuK4sRgyfwJ4XvSX4lGurqE/WYgxkNQdBlSz5DDYJe28gdnkydU6iKJus/P8OlI0odqWiUn5Q4nSY7FSUp0SCQvw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.32) smtp.rcpttodomain=redhat.com smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/QYR+S9r80f57bvrxBVwzzjQpZL5NkbBqrMjIadmWq8=; b=n0ToKBV7TiDY1X4+yS1kUKOyKftOJapz6519u0CQDJIkzlH2D066dKi9cEIZf8zRpVa1aMZuzgfg+NJcvq/i5jtxA74Eoq/WvAtLlI4HY5sWtdLzYCM28DdpReFUFWs6asRFtc1VQrma8rEvynMwh1rju2MznJuZ36jrfVCHo2iKMqE1I06JuLyzjun3clIcKdggvibG/iqYEdOi1DmLXZ2/fZW++SmNyQtcBENFPgz1d3b4IQdmq1Qh7UIT+x8wBMdSJfRYvjmVuYjSwnnHt+Np5rdkrA3sW1eJo+cCo2mhSo0xSN4fjwWxARG6vBIhg3hDH9FutQ74tOAjCsqUSQ== Received: from DS7PR03CA0284.namprd03.prod.outlook.com (2603:10b6:5:3ad::19) by MN2PR12MB3533.namprd12.prod.outlook.com (2603:10b6:208:107::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.21; Wed, 9 Jun 2021 14:22:56 +0000 Received: from DM6NAM11FT027.eop-nam11.prod.protection.outlook.com (2603:10b6:5:3ad:cafe::fb) by DS7PR03CA0284.outlook.office365.com (2603:10b6:5:3ad::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.20 via Frontend Transport; Wed, 9 Jun 2021 14:22:56 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.32) smtp.mailfrom=nvidia.com; redhat.com; dkim=none (message not signed) header.d=none; redhat.com; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.32 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.32; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.32) by DM6NAM11FT027.mail.protection.outlook.com (10.13.172.205) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4219.21 via Frontend Transport; Wed, 9 Jun 2021 14:22:56 +0000 Received: from HQMAIL107.nvidia.com (172.20.187.13) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 9 Jun 2021 07:22:55 -0700 Received: from vdi.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.13) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 9 Jun 2021 14:22:51 +0000 From: Maxim Mikityanskiy To: Mat Martineau , Matthieu Baerts , Jakub Kicinski , "David S. Miller" , Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= , "Jamal Hadi Salim" , Cong Wang , Jiri Pirko , Patrick McHardy , Jesper Dangaard Brouer , Paolo Abeni , Christoph Paasch , Peter Krystad CC: Young Xiao <92siuyang@gmail.com>, , "Maxim Mikityanskiy" Subject: [PATCH net 2/3] mptcp: Fix out of bounds when parsing TCP options Date: Wed, 9 Jun 2021 17:22:11 +0300 Message-ID: <20210609142212.3096691-3-maximmi@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210609142212.3096691-1-maximmi@nvidia.com> References: <20210609142212.3096691-1-maximmi@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 56b2b811-9eba-4d5f-fe9d-08d92b5213a5 X-MS-TrafficTypeDiagnostic: MN2PR12MB3533: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:549; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aU/dFOxRgIrUdKNuIyoSsfSOq08Ozygstcj49ybvguXNyAf9oC1+seEQbErOD6f/xGRoY/jeZNMMLytKZ/69LSArNEOT+naeIQrnj9zdkQI9l6eYBcyHKFGKCztQ0CGwqvjxbO/VrAOWc0UJAfrCPA6epEC8ZqjnHe0WWpqf29xi4ELIrmHMkOrk0E5rS3RLt6LMT3psELyeIiOqX2oT/umBtN2PO+8b15weWcRg8eADNL19Xo4xB5t/f4j89w5sp8bzRGBuwqAa0QXN8pMNqkmvh3VeL6x0i5j7KHx8on9a6MDLnYL3QLPEb147XTMMH20Kav5QuyYrMzCKT1FfZP8BgetANhutbCHJsJSwbxD8e5zf0UHSYcqLqsXDh4gKXiiUFmQifNc7OtdyfcjRk3OpXer/Kt8gznqJgmNP/QwuUfotVTGbCDD8tjDFCvjLS2+dGm5NfpWGpjI+P5xOGZNxG9sp8i0jduClMbAIJ3mrjzWUyP50vy3vd3ddkVuCxijlO/5M9UHIh/lab4ZUM+3x1wUb0vizNK9iT9l6twP39QSBG47s0Blb/DUDhANVsxYptSbc3Tm9Z2Z+5cJxi1/0B+ucvC0HHRtuZmYvCDN8NVMaX9s5zQ3zt1HtqkJnyg+Wqw3NdRaED11dyA3iQU8VrlwbZ4M3hsfJTVNlJco= X-Forefront-Antispam-Report: CIP:216.228.112.32; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid01.nvidia.com; CAT:NONE; SFS:(4636009)(136003)(396003)(376002)(346002)(39860400002)(36840700001)(46966006)(426003)(110136005)(7636003)(36860700001)(478600001)(6666004)(54906003)(86362001)(82740400003)(5660300002)(7696005)(4744005)(8936002)(83380400001)(356005)(186003)(36756003)(2616005)(7416002)(70586007)(70206006)(336012)(2906002)(47076005)(1076003)(107886003)(921005)(4326008)(82310400003)(316002)(8676002)(26005); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jun 2021 14:22:56.5554 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 56b2b811-9eba-4d5f-fe9d-08d92b5213a5 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.32]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT027.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3533 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The TCP option parser in mptcp (mptcp_get_options) could read one byte out of bounds. When the length is 1, the execution flow gets into the loop, reads one byte of the opcode, and if the opcode is neither TCPOPT_EOL nor TCPOPT_NOP, it reads one more byte, which exceeds the length of 1. This fix is inspired by commit 9609dad263f8 ("ipv4: tcp_input: fix stack out of bounds when parsing TCP options."). Cc: Young Xiao <92siuyang@gmail.com> Fixes: cec37a6e41aa ("mptcp: Handle MP_CAPABLE options for outgoing connections") Signed-off-by: Maxim Mikityanskiy Reviewed-by: Mat Martineau --- net/mptcp/options.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/mptcp/options.c b/net/mptcp/options.c index 6b825fb3fa83..9b263f27ce9b 100644 --- a/net/mptcp/options.c +++ b/net/mptcp/options.c @@ -356,6 +356,8 @@ void mptcp_get_options(const struct sk_buff *skb, length--; continue; default: + if (length < 2) + return; opsize = *ptr++; if (opsize < 2) /* "silly options" */ return; From patchwork Wed Jun 9 14:22:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Mikityanskiy X-Patchwork-Id: 458428 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 54D02C48BCD for ; Wed, 9 Jun 2021 14:23:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3D07A613B9 for ; Wed, 9 Jun 2021 14:23:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237969AbhFIOZQ (ORCPT ); Wed, 9 Jun 2021 10:25:16 -0400 Received: from mail-dm6nam12on2056.outbound.protection.outlook.com ([40.107.243.56]:42592 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S237943AbhFIOY6 (ORCPT ); Wed, 9 Jun 2021 10:24:58 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V1AEw13tSSZxizQ1R1PRmBASZEBC0xnGmWtpbaSZI2OgtYBHv56Gq2rZgoU+QFNMmDFq0OECKntKAEUqmpN4IrhnZVtoiCw7YCDKEcbZhNJEr0jzIxaQbzwpjbadp7ZFqXw6tKVxkjTzcYeQaAHiX+zPRIRU18jbvFJAKC95HHa3f2S7WR6UiDBEWrHKYdjk+q/xV7KgLY1jmru1AJPAxexaJWFMBPXn8VLsa03U4wF+ljbVRVaCm1FeIds8OueL5TDiQEIhEPNkCYXTE2bycVfIWiDANF7xLskRz+hhBH24xX7/Z9ahOxITyDz3JSA/4T2Ddi0oOkr/EhsoUlwD/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1Jgsp9z8kv7HHd0epraP0WbSUXnHIhdoS2jee3r6JgM=; b=Xdga4nF/7+3Q+I3LfC8oJ8ZwxtqYHTEzv15xl58lKZdJanbaV/MdsrE/QkGL4R0fRgMFUgav8vBu0xcSPOlQY/yCAPypEeorbFNgZ0Q5n0Sn6Tlj/aqHCeH9Hw7ruKvEOHZzjvvE2/qIu2K1bx3NlBh9JpwoqyLvpmcHupQcr/F+E6/qo6x5Bh/qIV1XBwX2LGgoziOWV1DWeahFhycBaURRwrW+OkY2gTJTAnu+Z9XcVIjQn9+EaB3LmzHhw1r+5v/wWVxAcyPUo17u52QTJagWlXfhBBzF9Qq4VAspaLv0kSCke4E17dR5wJzBq7BoLipH3mCZB7jRiv+Ady4nsw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=redhat.com smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1Jgsp9z8kv7HHd0epraP0WbSUXnHIhdoS2jee3r6JgM=; b=KauCc76Bhke8rClGBm6f8Y+oiw4s9/dLAQ4SGhDSHcmH5RXjUtPvLyfop4C2f8oa1syKTfVxESmPkpQh4gBzsB4n4JubGyqxkw096tx12LgXB/O8hXlXPO+8jMvqUOnZbrS0ve94o9tTk7ZtmQZEhvGR9HYSaDY36AZLm6oB7LhoIZ+AS3ZQHewCdg7gADENMXLOBdBYwArxP5bHrJKpwOF9gf3ueSvMrXm2/z80FHes0N6YSNM41DVSP/ldjNC0E/LF5U8TNAngwNpmOd/UwxiDzObQ932IzDqD2ZHB52YhjUWS4TrEC45rHXQ+L2iViVeaUpBQ/RrlqIU0HVsHGA== Received: from MWHPR01CA0043.prod.exchangelabs.com (2603:10b6:300:101::29) by CY4PR12MB1623.namprd12.prod.outlook.com (2603:10b6:910:6::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.24; Wed, 9 Jun 2021 14:23:02 +0000 Received: from CO1NAM11FT006.eop-nam11.prod.protection.outlook.com (2603:10b6:300:101:cafe::8d) by MWHPR01CA0043.outlook.office365.com (2603:10b6:300:101::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.21 via Frontend Transport; Wed, 9 Jun 2021 14:23:02 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; redhat.com; dkim=none (message not signed) header.d=none; redhat.com; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by CO1NAM11FT006.mail.protection.outlook.com (10.13.174.246) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4219.21 via Frontend Transport; Wed, 9 Jun 2021 14:23:02 +0000 Received: from HQMAIL107.nvidia.com (172.20.187.13) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 9 Jun 2021 14:23:01 +0000 Received: from vdi.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.13) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 9 Jun 2021 14:22:56 +0000 From: Maxim Mikityanskiy To: Mat Martineau , Matthieu Baerts , Jakub Kicinski , "David S. Miller" , Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= , "Jamal Hadi Salim" , Cong Wang , Jiri Pirko , Patrick McHardy , Jesper Dangaard Brouer , Paolo Abeni , Christoph Paasch , Peter Krystad CC: Young Xiao <92siuyang@gmail.com>, , "Maxim Mikityanskiy" Subject: [PATCH net 3/3] sch_cake: Fix out of bounds when parsing TCP options Date: Wed, 9 Jun 2021 17:22:12 +0300 Message-ID: <20210609142212.3096691-4-maximmi@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210609142212.3096691-1-maximmi@nvidia.com> References: <20210609142212.3096691-1-maximmi@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 68104536-408f-41b1-8e4a-08d92b5216ff X-MS-TrafficTypeDiagnostic: CY4PR12MB1623: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:538; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MV3AivStOcdF9IuRo/BNfLbIwXhIoEn8txTpaSk1K+yeQ4FZ0sCpcBJ88D005gaK5eJiFYhodx3RAcVrDafzg4IDHjipxA08k+W1G6uewhLJkMRNNCjV9JUxlT9boVCL/vdv7XSL9jx+xJShL7t6uTIWyi3HAxDq1tCUMy7tnUJnGoXGDPNMtV1SvMG0AJBuUj/8vSlBG1yvixEmoS5IH5wYKiYeEvunJQsrJuX9WzUJYtoPgWTBgUoROz+Nzs7kQP7tYeclU2NLh4o6W0AmKOvZmHNIUqgDc91cwlPQDh1PzGLqbzcie3yCznd/x2PRMCRAPg3H79AzV5Tojw7eZ5/qktFDHTDbDV4KcXrdlgxOFlAND0ExNpVwHOuQSSxjfNGLU8+FBGY9cj8G5rsQfJ2M+qOdJ1di7xec+DnWalZt0IG/qvo7pIlZPmFozRbI58VaJck5q6oWmg6xnZr8EYXQaKi5RbPtrMmSG2Cl7wCcw9m19MYtY5e25aAy005QkfbuBma+BfRZwxkuAaeNG0Pacm25wIo+iYargan8um+1vl5NWdUWYadFFCodXXOrDJlehswBwcDsMtdok6aJUK79+0bRRmaNx+Zvt/BzPHfeGw6MS8DlPOdBVMkJKKp3AF65tzkGSyYJ+EK8G2DVWdcwUajEaS96AIh3wWvMkG4= X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(136003)(346002)(396003)(376002)(39860400002)(36840700001)(46966006)(5660300002)(110136005)(36906005)(54906003)(4326008)(107886003)(316002)(7696005)(2906002)(6666004)(336012)(47076005)(356005)(83380400001)(7416002)(82740400003)(1076003)(26005)(186003)(8676002)(36860700001)(426003)(8936002)(2616005)(70586007)(478600001)(70206006)(7636003)(82310400003)(36756003)(921005)(86362001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jun 2021 14:23:02.1196 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 68104536-408f-41b1-8e4a-08d92b5216ff X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT006.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1623 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The TCP option parser in cake qdisc (cake_get_tcpopt and cake_tcph_may_drop) could read one byte out of bounds. When the length is 1, the execution flow gets into the loop, reads one byte of the opcode, and if the opcode is neither TCPOPT_EOL nor TCPOPT_NOP, it reads one more byte, which exceeds the length of 1. This fix is inspired by commit 9609dad263f8 ("ipv4: tcp_input: fix stack out of bounds when parsing TCP options."). Cc: Young Xiao <92siuyang@gmail.com> Fixes: 8b7138814f29 ("sch_cake: Add optional ACK filter") Signed-off-by: Maxim Mikityanskiy --- net/sched/sch_cake.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/net/sched/sch_cake.c b/net/sched/sch_cake.c index 7d37638ee1c7..6b03eebf0a78 100644 --- a/net/sched/sch_cake.c +++ b/net/sched/sch_cake.c @@ -967,6 +967,8 @@ static const void *cake_get_tcpopt(const struct tcphdr *tcph, length--; continue; } + if (length < 2) + break; opsize = *ptr++; if (opsize < 2 || opsize > length) break; @@ -1104,6 +1106,8 @@ static bool cake_tcph_may_drop(const struct tcphdr *tcph, length--; continue; } + if (length < 2) + break; opsize = *ptr++; if (opsize < 2 || opsize > length) break;