From patchwork Thu Jun 10 16:40:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Mikityanskiy X-Patchwork-Id: 458329 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=-18.9 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, URIBL_BLOCKED, 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 C84F7C47094 for ; Thu, 10 Jun 2021 16:41:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B3FF5613F8 for ; Thu, 10 Jun 2021 16:41:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231530AbhFJQnV (ORCPT ); Thu, 10 Jun 2021 12:43:21 -0400 Received: from mail-dm6nam10on2054.outbound.protection.outlook.com ([40.107.93.54]:43873 "EHLO NAM10-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231520AbhFJQnH (ORCPT ); Thu, 10 Jun 2021 12:43:07 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C5ohtPr1fhxdemA6cKYaKMW1I0yTGl5XmnquFEGKZ3qzQxsC2Xgp8M27UJ3c+gyYVuXJ85iQxSiVxYM4z257AJzGrm7u4LaooLwCnEtqae4EqqMBRJv6bKbU/a8WxlZ/ShfDxbyP792C2R4ivec3MzwPd23FZiVlw3UdV7WSamaRSO8VQZ/LKyDgXoHp6Apvozp87sP9wYaszcCy74f8l68I22Hh38GSh9oNyfnLh6gc8n6JL2gcDuV/xxy0P3G9AGv2HnmQMkHenkUElLGeUQePDXEpKmUVIV1YvI+jqodpun+0N+gpojrvVr+SV1us2p705SqecDqTw4v4LCB7Ig== 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=F2p8lpQ+bwtlwEIaQdcJVF54mwWaCH41v24HdDqFXTE=; b=M1FdTv/VbaNeFiYT2YfUY8AEmtT06EajVGvUPJYXwE37KHgUg3fhVsUZWDiZ98JPmn24iy/Hw48xh/gCKFkUVRoBFGg7drJQcxVvNQXS8b69fCvhUZycld4v+E3E0p3zL80DKVAqNGkG985rm1hjfB0Wez7SmiDsKEnuWmvzNHG3f//vwc0txCgKCo4PMVLXhoIJi8LW+/mztcVIy0STI+nfBngWnc02iPZ+GnXlhHMD0tBjoR8C5PszOKv3FjpM1p2mFrRRVrHjgUFEvslz32AzYIXC+1QbFBxc2Eyt7rsyxUnc/XdLTIUCVz6gLZRtQcYdIQYaOdDW3BQgufracA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.35) 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=F2p8lpQ+bwtlwEIaQdcJVF54mwWaCH41v24HdDqFXTE=; b=o72j/WRKHmDJAewrOGdQBWxRI0GC78UX1IviVpbHxpaye3xquzWRkwgWfxExf+2EZuBfkY7HRb4ULTfIu/8KYmNnB5V52NrgHFPzXAptE/3xGr/uEui0Cpubyrd9qPDvEKPiAQ7TNvhvd8MIv/mfVRahs/bHnVZ8zO+xHy7XeJ3/nvWgDY3tp7ry+hLAKYvzXRC3Z0/TKvfyjmp0T3X+Yoce5W+4e7ggP8pmlPArS2OW79fR7GtG2A9xOlAAbeCbwQcNmXgTXA5suQuwuCbqQfLK1v4XBJYyLF1TfCXNZACSaD+LkTA+m+HSH+Tv4wEJ/neLBLpVopwo3n/EvBljaA== Received: from BN9PR03CA0180.namprd03.prod.outlook.com (2603:10b6:408:f4::35) by BYAPR12MB2966.namprd12.prod.outlook.com (2603:10b6:a03:df::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.22; Thu, 10 Jun 2021 16:41:09 +0000 Received: from BN8NAM11FT049.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f4:cafe::ae) by BN9PR03CA0180.outlook.office365.com (2603:10b6:408:f4::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.20 via Frontend Transport; Thu, 10 Jun 2021 16:41:09 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.35) 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.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 BN8NAM11FT049.mail.protection.outlook.com (10.13.177.157) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4219.21 via Frontend Transport; Thu, 10 Jun 2021 16:41:09 +0000 Received: from HQMAIL107.nvidia.com (172.20.187.13) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 10 Jun 2021 16:41:08 +0000 Received: from vdi.nvidia.com (172.20.187.5) by mail.nvidia.com (172.20.187.13) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 10 Jun 2021 16:40:54 +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 v2 1/3] netfilter: synproxy: Fix out of bounds when parsing TCP options Date: Thu, 10 Jun 2021 19:40:29 +0300 Message-ID: <20210610164031.3412479-2-maximmi@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210610164031.3412479-1-maximmi@nvidia.com> References: <20210610164031.3412479-1-maximmi@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 337c0952-1ce9-455f-5efb-08d92c2e8d0a X-MS-TrafficTypeDiagnostic: BYAPR12MB2966: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:660; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2nu0k5q+uwJcbyfYn1xsqpj0FG5SsuCYjwWQyHfuXauRlzsZjnSW07xI7WUSrQrYBaBVow6igFabVUJoD2L3pIHrJlVvEJX17RteYRb1574Yaupg+be2SZmZal1x4Zu+ImJRKCqW6ZsCdcmEZ4UCTBf808lj3ybp2wNy3l7Vao7Qt6H/JsClql3HZZIGaukL+LiBCsXnnUEDP1v9I4MXC2/0p1Zgn5T2ofVxOCGfH7KgUoTSzo0ish82r7Z8Hej3j2U96PHao+xQ9N9RfUgr+y0tFlt9wTRfRSkxo64FEZFASrLJm6ZbRDZ3SzhmbW1TiLJT1r5uGJn258dkrROCP/ZMY6DmM6+1GnWWR7r6+qkWQYUP+1ovfEyvzDS+/tYzv2vQmzN2+XXWhBeQW9F9fYeLkgmub3QMbDzWbNofimOR5CVvWKHBG7i66B9TJtj6BXrg9lljzWGPcP25F7/cgVWnHtNIZ5rniPtCZwJllCl4UpwXwqth31mUSi6aCPZRlVWa9vupGRYOuwTYIhEZcOld+nolzt9DAcmk4XtIrnnIRsj07kytgZbAioL6MNKYLSqXzlKEeRAluIbppLuiOgOhtrLv7vE4CpOQaU7e/VqE3XEMhbl9PZQW+ESFb1BRLuf+a2atqYmtq8nbr29teKa8/ZzAMP0X/gwWIQ92z24= 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)(346002)(136003)(39860400002)(396003)(36840700001)(46966006)(36860700001)(316002)(54906003)(110136005)(83380400001)(36906005)(47076005)(2616005)(356005)(478600001)(336012)(82310400003)(70586007)(2906002)(8676002)(7696005)(36756003)(426003)(8936002)(86362001)(7636003)(6666004)(70206006)(26005)(7416002)(921005)(82740400003)(186003)(4326008)(107886003)(5660300002)(1076003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2021 16:41:09.4051 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 337c0952-1ce9-455f-5efb-08d92c2e8d0a 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: BN8NAM11FT049.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB2966 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."). v2 changes: Added an early return when length < 0 to avoid calling skb_header_pointer with negative length. Cc: Young Xiao <92siuyang@gmail.com> Fixes: 48b1de4c110a ("netfilter: add SYNPROXY core/target") Signed-off-by: Maxim Mikityanskiy --- net/netfilter/nf_synproxy_core.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/netfilter/nf_synproxy_core.c b/net/netfilter/nf_synproxy_core.c index b100c04a0e43..3d6d49420db8 100644 --- a/net/netfilter/nf_synproxy_core.c +++ b/net/netfilter/nf_synproxy_core.c @@ -31,6 +31,9 @@ synproxy_parse_options(const struct sk_buff *skb, unsigned int doff, int length = (th->doff * 4) - sizeof(*th); u8 buf[40], *ptr; + if (unlikely(length < 0)) + return false; + ptr = skb_header_pointer(skb, doff + sizeof(*th), length, buf); if (ptr == NULL) return false; @@ -47,6 +50,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 Thu Jun 10 16:40:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Mikityanskiy X-Patchwork-Id: 458328 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=-18.9 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, URIBL_BLOCKED, 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 1B2E0C48BD1 for ; Thu, 10 Jun 2021 16:41:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0BA36613E1 for ; Thu, 10 Jun 2021 16:41:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231671AbhFJQnf (ORCPT ); Thu, 10 Jun 2021 12:43:35 -0400 Received: from mail-bn8nam11on2083.outbound.protection.outlook.com ([40.107.236.83]:37985 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231607AbhFJQnV (ORCPT ); Thu, 10 Jun 2021 12:43:21 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CPsjL0ZfYLqnBVwH2esRgTkEO89kPCXcaK7SPbfPFzSxtKcfbcmDG1NenPsIMKGEKMRZrhccVdMG+r22hVkSuqER6IYt2QkKokax+5alDa8hU21dfG5dJNF7xnHOyrhWb1LIs1eZzrjV75U0M3ic4j4bHWWvsJ1N1JHlSjNu4ymcE/Y/7vzyTbRLw5mrRWxUDd54pgMrxLXJThM/e2U+ECA32IPkGc0sM8suFjy1CsrMQGDYqKq2LMAFH94X1oKQ+0SwXRyydhocpUtIL+7acCzh7PjdsV2yyODzRKFHcvYqXrNY1hZeI7wnPlo0E69mtHZfaersWWgI7ktIOk8DBg== 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=W2wY0Wt2lqMPTtGKpjeTV9b4X2qBRYxq4hCDftLZM9g=; b=Al08csYL50Av7k+nj0T61/ZtHp1CyqbgZPIIibFX+R0yStCvZDPRMIXv8+Pm3ykYgjblYh07g+xKHWgw3rLQAIJ21+LjLTz9yu35uK9diUHglLBcJeDVJ+NJZm8PwNiWkKy//1OU5RV/VKzyhxLup+LC30GwB05bSSsq9hX+mpDR1NZ+bRqSWyjESFbnFlMljxQRQ4WV0ewiHngYNqwEsbbKyH6BUThokc6aYb8qgAhGDHG4JYDoPKdwSNf7Ts66HmzDTBaJTs6GGxvIAPD3YyHm28m18r+Y6UafosqnM2Y5uw8y9R2gn4XfLfCm0mMiqS+K91zKcGuJb2mptovveg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.35) 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=W2wY0Wt2lqMPTtGKpjeTV9b4X2qBRYxq4hCDftLZM9g=; b=DJ46mVC2mA+k123xwzEs03yu5i3aQ1kRZrLH+iNdFyWKfAiGn/kkSrM5nlnhfC/O2EHq5v29qgHD9KPE5uHZ6e8DX+Cqf2YW/Ywxl1oR8M8OydycXnKtaSJy430lGHXgR04FEvpdP7A+73Bz/yyZ3B5/EdTyZBzxbru7ODYwQv/RlKz21WCykOvDZZzvtRjvxN848onL+Z+p0LbzDnIeH/+DvngPF2e7yeAJGh1jZXfqCKUBILt9TyhA8Tc/PWKMX3WQhMw3pAgkFYDkrpDvS9xCWuBLaSvzCyTtVUJF0ms3+mmoZBKecT+ZlkU2Eulf+AXaQg3+AxqKpN322XEdVA== Received: from BN9PR03CA0405.namprd03.prod.outlook.com (2603:10b6:408:111::20) by DM5PR12MB1273.namprd12.prod.outlook.com (2603:10b6:3:76::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.29; Thu, 10 Jun 2021 16:41:22 +0000 Received: from BN8NAM11FT059.eop-nam11.prod.protection.outlook.com (2603:10b6:408:111:cafe::2f) by BN9PR03CA0405.outlook.office365.com (2603:10b6:408:111::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.22 via Frontend Transport; Thu, 10 Jun 2021 16:41:22 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.35) 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.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 BN8NAM11FT059.mail.protection.outlook.com (10.13.177.120) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4219.21 via Frontend Transport; Thu, 10 Jun 2021 16:41:22 +0000 Received: from HQMAIL107.nvidia.com (172.20.187.13) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 10 Jun 2021 16:41:21 +0000 Received: from vdi.nvidia.com (172.20.187.5) by mail.nvidia.com (172.20.187.13) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 10 Jun 2021 16:41:09 +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 v2 2/3] mptcp: Fix out of bounds when parsing TCP options Date: Thu, 10 Jun 2021 19:40:30 +0300 Message-ID: <20210610164031.3412479-3-maximmi@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210610164031.3412479-1-maximmi@nvidia.com> References: <20210610164031.3412479-1-maximmi@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: dfc3ce01-fe34-4403-1a4f-08d92c2e94a9 X-MS-TrafficTypeDiagnostic: DM5PR12MB1273: 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: NnpHfmBejfgiULVtr9yo29XC5HeSEDYztHQh9pfO/UOJQdX4voOn1wUK+sXBVz+zsTYBmxTQuokndH0pG2qfxc8C+IP9fuPLogydB3247m7w99zGTwhBSfDVxERJIkBE3cQ7Y0e1dXwVqaSQBV4lcQbIHtU0VIfbjdJhLSG8z6czuH48c0kXwLH8CBcNPNxKl71H6Nyq2UvoJwtDGx+LAj54PeUvR8dpg4HlCpwM0npiEoK83O++psyRcQo0wLENC5yCZWRWCcfM5WsTaOGCuIO8AFnXic45rmJaeMdb/sVKulu/wrIeMPuhT9NlB3l7AOKiloI22wgutyP6ea9q3dfUSXIn6XxVIYqgCqqIhVfSU6gwRcjNk/5DkdX4USTdnVW7bHPFPtYvTEeCHTcPJZmHDFCRuvRTWmternpEHcg23AIqsjEuNIhITXyUowcKf9OVANS8n/y53igi/SUdm2K7LNW/OX7/+8pRz2RXnDyB6A2WWQLNf2VfqXnoNnPq2We/x5Gwxd66up2XSLPC+k1D+Z9abGn3+LzVS7t0didZ1KUBqCcaPuypm+/H2GYjTdHAVE8S15Nb2R5H7gBXhdbr3ssRPlwyYRc7xlb+mBUgbFK0xjNj3J74CrLNNqSnmnnuyZigfkQT2Mdtk0aUsZyHgvHU1zRPOIMXFyxHxfg= 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)(396003)(39860400002)(376002)(136003)(346002)(36840700001)(46966006)(36860700001)(5660300002)(82310400003)(70206006)(186003)(478600001)(26005)(4326008)(1076003)(356005)(110136005)(316002)(47076005)(7416002)(54906003)(36906005)(426003)(70586007)(36756003)(6666004)(83380400001)(2906002)(8936002)(82740400003)(7696005)(107886003)(2616005)(8676002)(86362001)(921005)(7636003)(336012); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2021 16:41:22.1984 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dfc3ce01-fe34-4403-1a4f-08d92c2e94a9 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: BN8NAM11FT059.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1273 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 Thu Jun 10 16:40:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxim Mikityanskiy X-Patchwork-Id: 458327 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=-18.9 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, URIBL_BLOCKED, 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 9E027C48BDF for ; Thu, 10 Jun 2021 16:42:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 87B2D60FDA for ; Thu, 10 Jun 2021 16:42:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231831AbhFJQn6 (ORCPT ); Thu, 10 Jun 2021 12:43:58 -0400 Received: from mail-dm6nam11on2053.outbound.protection.outlook.com ([40.107.223.53]:43841 "EHLO NAM11-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231465AbhFJQng (ORCPT ); Thu, 10 Jun 2021 12:43:36 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e1RD7CNYC7F86x5xRee3OFzdA4zpgMAd34/IvdaAaaSIcKuuEc/1WqUbNSJY8eqkfFOB8cso7LLQsfdaDgGWEU3JGAqolKgG+rq4WBkhB6DQA0QZGjIYDWMnfr7EJrVI1L18ADdUhGj5b/g/pApZzwPQ91g2rrcz37Ebg+cmWLszw5gMlnGQxgdxjKCJJJLGQeUQmTVzRVU8xUmOEG+Xwqj8mWR2drstv30LoHIXO+Ug6MEAWcrvCG9am1luo9HI++SlCAqucBtjQQO5WYnR3OSUIPuCKqKnuxVqs5xfBkDDzgESOcNA4FvSr57cfIG1x7NQN2+UrUof9oO84sGRbA== 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=TtELPH2XDXSmApLmukK1vEoxEaLRnYib95Abanrr4ms=; b=B5HDdvu3HVPBpiIAmD8aWZKepnWT6VE6i6yfWYLugecI569KcowY1APlBP9/49QQdQ0x8GzwSv5mzzEazpuAflqHHEgC1hvaWfmBf8rl5u+yDw7OKyM7jkV163mH97z4ymxIB7uw/gPkLE1z9etgzPWNKJCGh2yUWWRbWOOrxSRLfm5YTOJgkvbkudM6zeqKdxv2jgsIPrPIQkktFqqcSXaBZbI8yTxoQ/1ihn4s+G9zzmakUOG0bUj6tTOZfC2K3TXCODJFzVQQwRhPc9Iuearnl0S8lWoDppk6WaYQsbwizmDV+MeKgaz38O5V/fbD6kUAdBVWk3Vk8vmOhfj1Kg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.36) 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=TtELPH2XDXSmApLmukK1vEoxEaLRnYib95Abanrr4ms=; b=fQ1X2KPvj8e+X9rNg+X9oFvpp11NFt0BcX8jPICIHQcisUf4bexU1tChL/GQHR25zP+zyde6IQQPVWriSyHtWwQQdzWtZh9e6rJytg9DsP68Fd5eGDiUyzzGFe/E8ymHD1Zxm2dXM3bl9bYO7Tv6YxnLdwBYFN8b7gh3jZbYWqQ7h2vF0mCMSIKz4sewGIIeXUYNiMANV0uWezX2V7kBKvk8zx4PJcVfGORDrcY9UW+sGYQFwy+NASUUYmiVfomsP8tVLmtmKO9RBL3rE0tAouDwHpM0ywtz067k3ATAiSC5L9eXlErn8i0pV7r34xz5LEaBKG2jgYiprs7Eggs9yw== Received: from BN1PR13CA0014.namprd13.prod.outlook.com (2603:10b6:408:e2::19) by MN2PR12MB3390.namprd12.prod.outlook.com (2603:10b6:208:c9::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.21; Thu, 10 Jun 2021 16:41:38 +0000 Received: from BN8NAM11FT047.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e2:cafe::5b) by BN1PR13CA0014.outlook.office365.com (2603:10b6:408:e2::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4242.9 via Frontend Transport; Thu, 10 Jun 2021 16:41:38 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.36) 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.36 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.36; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.36) by BN8NAM11FT047.mail.protection.outlook.com (10.13.177.220) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4219.21 via Frontend Transport; Thu, 10 Jun 2021 16:41:37 +0000 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 10 Jun 2021 16:41:35 +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; Thu, 10 Jun 2021 16:41:34 +0000 Received: from vdi.nvidia.com (172.20.187.5) by mail.nvidia.com (172.20.187.13) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 10 Jun 2021 16:41:22 +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 v2 3/3] sch_cake: Fix out of bounds when parsing TCP options and header Date: Thu, 10 Jun 2021 19:40:31 +0300 Message-ID: <20210610164031.3412479-4-maximmi@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210610164031.3412479-1-maximmi@nvidia.com> References: <20210610164031.3412479-1-maximmi@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f3142fc6-19ff-42fe-f044-08d92c2e9dcc X-MS-TrafficTypeDiagnostic: MN2PR12MB3390: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:169; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XX+qWSZdW1CrSIqGXCxg5NZvkeotlTmEGNHtDz46KLWVPIkhe3I2pOoSbpUSD4SvoCyDXHjOAGa9hUAiNNzN5sQtlL87InDdenzK2nQueXMRw6/cCini/RGsihjyLOYi8gRZJUOb0Qabz2hK+fi8yurB95XlIOeKhvz6WfkJ23cdgxa+M/mM9MXI9OSN9aJAnmkCi0yaZy4+0Os0Vm4mHnoBjNwUeJ0ug2oi2iDvtTeudnDZJDFDMJ2/ZAW9oKJDh+DqyM/vl1CFWH17NLKTEdfVUuUC5qPPw8cO6NsR/RwCMk/CfsxD+SVLY9AVg0v2LeFPz5nUyauzxjjPQhbK07qMYMsYcXou6elv7MPoawV70WzaCgrPNH0W+poGWPIcjt5OsWuny3z56aZ4TAm6OG9mXYxMRCB/YvhVCkXS0JZppQd/0Eesx/XeTgyKtv8l9UVcjK38yeu/nvWt94Wp7BcU2eGhD1V4UdXTGVLPPrIBZUVAuEWqGeLk/YYspAsLBzm2bsPOsusTUi+maWRFwisL/Ki5iYqH+6GlX+zC2ADONw2Wf0VSaLKylpMiBRyTr390P26BRGrgKD32ZDzkck0bYZqQMc6P2VGzgCyBdcqLRfiA7OHgVrzlaAZFVhArbUgr3D9vWkJ8u7XyO6B+qGQ/x4AJhumMpc0K8jqyf3U= X-Forefront-Antispam-Report: CIP:216.228.112.36; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid05.nvidia.com; CAT:NONE; SFS:(4636009)(396003)(39860400002)(136003)(346002)(376002)(46966006)(36840700001)(36860700001)(8676002)(36906005)(316002)(426003)(110136005)(54906003)(4326008)(86362001)(26005)(478600001)(186003)(47076005)(356005)(921005)(8936002)(336012)(5660300002)(2616005)(7696005)(6666004)(7636003)(70586007)(70206006)(36756003)(1076003)(7416002)(107886003)(83380400001)(66574015)(2906002)(82310400003)(82740400003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2021 16:41:37.5078 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f3142fc6-19ff-42fe-f044-08d92c2e9dcc 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.36]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT047.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3390 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."). v2 changes: Added doff validation in cake_get_tcphdr to avoid parsing garbage as TCP header. Although it wasn't strictly an out-of-bounds access (memory was allocated), garbage values could be read where CAKE expected the TCP header if doff was smaller than 5. Cc: Young Xiao <92siuyang@gmail.com> Fixes: 8b7138814f29 ("sch_cake: Add optional ACK filter") Signed-off-by: Maxim Mikityanskiy Acked-by: Toke Høiland-Jørgensen --- net/sched/sch_cake.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/net/sched/sch_cake.c b/net/sched/sch_cake.c index 7d37638ee1c7..5c15968b5155 100644 --- a/net/sched/sch_cake.c +++ b/net/sched/sch_cake.c @@ -943,7 +943,7 @@ static struct tcphdr *cake_get_tcphdr(const struct sk_buff *skb, } tcph = skb_header_pointer(skb, offset, sizeof(_tcph), &_tcph); - if (!tcph) + if (!tcph || tcph->doff < 5) return NULL; return skb_header_pointer(skb, offset, @@ -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;