Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 241B8C433EF for ; Thu, 26 May 2022 11:49:38 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3708F842C4; Thu, 26 May 2022 13:49:36 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=suse.com header.i=@suse.com header.b="EkAcdQm3"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5340B84311; Thu, 26 May 2022 13:49:34 +0200 (CEST) Received: from de-smtp-delivery-102.mimecast.com (de-smtp-delivery-102.mimecast.com [194.104.109.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 2C06883EFE for ; Thu, 26 May 2022 13:49:30 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=mbrugger@suse.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1653565769; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xpauBsChK6HShH2QQXeIrob6k/B7nQ8wu9WVBdevlbA=; b=EkAcdQm3fnLW/1zCbN3aPeNXP73M5rJ2oQPuDoW61GAKStWagGtFc3i6/F03IbfxV5mFPT 0uPREkdvLm7zuijr9EMjSrfTUuYMDu4MAawoC3yxa0VgFkTHBEpZ5AYv9tLBD/wLORXm33 VsEb50wXBocvUDz3Jl8aN/fYQ+Jq6gI= Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05lp2110.outbound.protection.outlook.com [104.47.18.110]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id de-mta-41-JFn1CTUBONinCsM9T6vjcQ-1; Thu, 26 May 2022 13:49:28 +0200 X-MC-Unique: JFn1CTUBONinCsM9T6vjcQ-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dQKhzaLy6ajXBH5a2VdlsDFNyw+kQr6RhGrsbyiNjTz02Ise9aXWiIJOAthgttMlvZOzLdRBUqSbbKghv4kNZ4r9LEvwx/bAEqo+dUegT+pq3xZ+ZVVQVEPdxyzvhrGfl9g/xQ2vFrw0nWYw26KOGd5uEfIB/6No/7GeR/nnxS/cjnJZe9vN8BmYabvkyzFUWUepXK+HWh92RIun7jm590aNryp8hsQg5Tus9/oUhp6B20DU5rYGWx0N/F0hhy2wKj9ZpYrlR4uC/wbRXynV849LQMCSbagFklmz4SllJDpLPYGjvUQaNpCvP2oCMaJukuSw5A/epUGEJgigWbKQ0Q== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=xpauBsChK6HShH2QQXeIrob6k/B7nQ8wu9WVBdevlbA=; b=ZMpQt9ofWHeR7QM6Isc4YR2fTsDmYWAYZNfWJrf1p97xg1y2BaJf13DaD2K4NXY9k+zolwAp14GGXBmGq874quQAdtjgD8HJMVEnv+f4SazaTDCROLd9VgcI7SUku4LVxi/78LJYJADaaP3OT8xJ7Z6zZ87+iHAHU2p4uI0hQQiauBpxcglP6dtZbkGmTUatxczwH5wKWMN+dOX1EDm9ZYVq/dmcZflZCpLL8laW/I31NJ17KKEaI5RWyyjp3ueejcAlg3/7BobrsxGK1IY8aTpXchMwZWv4Rf4WHfCtWXpcSt5dcPyUP2y1ohHemILbcMMsXnDZkgyp0UyEM+R7qg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Received: from AM6PR04MB5366.eurprd04.prod.outlook.com (2603:10a6:20b:9d::19) by DB8PR04MB7195.eurprd04.prod.outlook.com (2603:10a6:10:12d::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5293.13; Thu, 26 May 2022 11:49:26 +0000 Received: from AM6PR04MB5366.eurprd04.prod.outlook.com ([fe80::4178:823e:5e3e:ff5b]) by AM6PR04MB5366.eurprd04.prod.outlook.com ([fe80::4178:823e:5e3e:ff5b%5]) with mapi id 15.20.5293.013; Thu, 26 May 2022 11:49:26 +0000 Message-ID: <247960ce-e707-8c88-966c-04e59e1c322a@suse.com> Date: Thu, 26 May 2022 13:48:58 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 Subject: Re: Vulnerability Disclosure in net/ Content-Language: en-US To: Ramon Fried , Nicolas Bidron Cc: "u-boot@lists.denx.de" , "joe.hershberger@ni.com" , "trini@konsulko.com" References: From: Matthias Brugger In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: AM6P195CA0051.EURP195.PROD.OUTLOOK.COM (2603:10a6:209:87::28) To AM6PR04MB5366.eurprd04.prod.outlook.com (2603:10a6:20b:9d::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5b177d18-6720-4105-2ae3-08da3f0dc8b5 X-MS-TrafficTypeDiagnostic: DB8PR04MB7195:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LTcd5cn4xB0au3LtT6bip2W17EI6g/bBIHwHpMGcWhYgVVLkTYuwTqgx/3mYl+hav1uFG3EEHyXvw7lyeajG/11g9smx2saBDIQk0W8tYAqLhkMl2DzFER58mTJ+DN6G+zpexLv+6eGmTL35YdA+falGYNVIDhWqkF4tJyW6VqCmmb64cAqL9M7yH1AG0vnneaDrAiHwD/0tMnjDZoEKFZPypV4l2QrwGo7p18XjsY5ECa6N92VDPevdhGKpzvVc9btastcfZEmgWZ+WkLrWoJhHAmzuvf46OTOg7HUyGimID+Bp5Aj0TY/x92qPN27df+OHatcdeshJKaR7ClhqgKgt45BB1MVVN33AFPdyKT6Xo8YPYtgqJU0Imfr8k/ffhxZHYNjrPf90jY9zTkI9xTksOK7mLyN5Zwn5qWXoIfg9lbMxax0LByOUnQa6QdqOL/7isF4oZ/Ynf7UPoUZUWBbS2Ds+7swCMx2rdn5JOuibkqINpe5UDeOuHoiPnI3q0reQX57FYucdQukzjyI0r9BOeuiQb0toe3gkJRoEubpCGTv/0DufMTKI14V8UvX1hRFHjCQkHJBxbk82YYZbnNc46Hw+efMiaRa4XVATHuu5YUJErctoSroBsXPIxgjkLeIlF8lxJXHGyQeb2EO2Ceyg/l57QCrAdZb9726ALAuZlD3s9mNWVUD8hL9SA8bnLyu7MRwvYWRbytF6Ek5EpFvMfsT74pNMnv0rjTWLFtrpV51zmIi7lO7AFuXAcKYisMy6iCl6WPqo8c6JjzMUZq/y8xaNWKMpbaqav5P4MmkCT0mdYM4abUiXGxxn2gU3xBLxCdbMbk/4U7TLhXbqXwr1igvy1nAJgDrNZe8JCc0= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR04MB5366.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(86362001)(54906003)(2906002)(31696002)(38100700002)(53546011)(36756003)(6666004)(110136005)(186003)(2616005)(31686004)(26005)(8936002)(66556008)(6512007)(5660300002)(4326008)(3480700007)(66946007)(8676002)(66476007)(6506007)(966005)(316002)(6486002)(508600001)(83380400001)(45980500001)(43740500002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?OEd5ZGV3RlBOVXZ5NWN4TSszR3VxbmE0aitqUHE2eDNSQndWa1ZlTzhxOUdn?= =?utf-8?B?MDhXcElETHQzWXVSQTFNWk9XN1Y4NmZRRUs2bk0xdVlNdDVOeDd3Ty9ldUxa?= =?utf-8?B?UlBCa0dtY2c0NWVPRDVQK1hzS01WWEZ1RFhjdGJwekFwZFd4dFNsakVRWitu?= =?utf-8?B?cy9hODlOZ3NsakFrRUxrU0MxUWx2eUVWSHlkYkQ4RDIvRE1KSFFwRGw5Vzl6?= =?utf-8?B?YkU2bmUvRU9WQzVZQUpMS1hXd3FGL1FDN3h3K2FqTllJNGxDajFuVlN1SUNU?= =?utf-8?B?UmtJQk11YmM0eVNrVUhxcW9wa3I0YTl1QUdOSVZrbnlKcEI4K1BrcmFRb1kv?= =?utf-8?B?Sis3OHRRZjM1M2xHbzg5RElDODhjaFBiNHU2aHVhRGNjenlMQjJSSXlaMktF?= =?utf-8?B?SFphOGdvWjI3UWJYR2RsNUh1bWM3RXZ0NGRFTVZ4ekRxbVRCUUxCcVRYT0d3?= =?utf-8?B?ekFxNS94Z3U4RUx6RldHL3ZiR2xPUE5wRGJoQUp0YXhPSFlJaTlsUGM5Ymxl?= =?utf-8?B?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nhRcHU3OGc4L2kzVk5MQnZidz09?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5b177d18-6720-4105-2ae3-08da3f0dc8b5 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB5366.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 May 2022 11:49:26.2662 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 9DhvQFSL4nwPAU5JyK8RTRKOnj/8gKZKPn+muiXBsB/20hf4eYPiJ+pgHtcMBghfwfLdLmT1kq3UOZuMaZYbmQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR04MB7195 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Hi Ramon, On 26/05/2022 04:46, Ramon Fried wrote: > On Wed, May 18, 2022 at 7:14 PM Nicolas Bidron > wrote: >> >> Hello, >> >> We found a couple of bugs in net/net.s in the IP defragmentation >> function __net_defragment(). Below the writeup for the 2 bugs: >> >> -----------BUG 1----------- >> >> # Hole Descriptor Overwrite in U-Boot IP Packet Defragmentation Leads to >> Arbitrary Out of Bounds Write Primitive (CVE-TBD) >> >> | | | >> | --- | --- | >> |Project | U-Boot | >> |Project URL | https://github.com/u-boot/u-boot | >> |Versions affected | all versions up to commit TBD | >> |Systems affected | All systems defining `CONFIG_IP_DEFRAG` | >> |CVE identifier | TBD | >> |Advisory URL | TBD | >> |Risk | Critical 9.6 (CVSS:3.1/AV:A/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H) | >> |Authors | Nicolas Guigo, Nicolas Bidron | >> >> ### Summary >> >> U-boot is a popular boot loader for embedded systems with >> implementations for a large number of architectures and prominent in >> most linux based embedded systems. >> >> ### Location >> >> In `u-boot/net/net.c` the `__net_defragment` function line 900 through 1018. >> >> ### Impact >> >> The U-Boot implementation of >> [RFC815](https://datatracker.ietf.org/doc/html/rfc815) IP DATAGRAM >> REASSEMBLY ALGORITHMS is susceptible to a Hole Descriptor overwrite >> attack which ultimately leads to an arbitrary write primitve. >> >> ### Description >> >> In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of >> `ip->ip_len` (IP packet header's Total Length) higher than `IP_HDR_SIZE` >> and strictly lower than `IP_HDR_SIZE+8` will lead to a value for `len` >> comprised between `0` and `7`. This will ultimately result in a >> truncated division by `8` resulting value of `0` forcing the hole >> metadata and fragment to point to the same location. The subsequent >> memcopy will overwrite the hole metadata with the fragment data. Through >> a second fragment, this can be exploited to write to an arbitrary offset >> controlled by that overwritten hole metadata value. >> >> This bug is only exploitable locally as it requires crafting two packets >> the first of which would most likely be dropped through routing due to >> its unexpectedly low Total Length. However, this bug can potentially be >> exploited to root linux based embedded devices locally. >> >> ```C >> static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp) >> { >> static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN); >> static u16 first_hole, total_len; >> struct hole *payload, *thisfrag, *h, *newh; >> struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff; >> uchar *indata = (uchar *)ip; >> int offset8, start, len, done = 0; >> u16 ip_off = ntohs(ip->ip_off); >> >> /* payload starts after IP header, this fragment is in there */ >> payload = (struct hole *)(pkt_buff + IP_HDR_SIZE); >> offset8 = (ip_off & IP_OFFS); >> thisfrag = payload + offset8; >> start = offset8 * 8; >> len = ntohs(ip->ip_len) - IP_HDR_SIZE; >> ``` >> >> The last line of the previous excerpt from `u-boot/net/net.c` shows how >> the attacker can control the value of `len` to be strictly lower than >> `8` by issuing a packet with `ip_len` between `21` and `27` >> (`IP_HDR_SIZE` has a value of `20`). >> >> Also note that `offset8` here is `0` which leads to `thisfrag = payload`. >> >> ```C >> } else if (h >= thisfrag) { >> /* overlaps with initial part of the hole: move this hole */ >> newh = thisfrag + (len / 8); >> *newh = *h; >> h = newh; >> if (h->next_hole) >> payload[h->next_hole].prev_hole = (h - payload); >> if (h->prev_hole) >> payload[h->prev_hole].next_hole = (h - payload); >> else >> first_hole = (h - payload); >> >> } else { >> ``` >> >> Lower down the same function, execution reaches the above code path. >> Here, `len / 8` evaluates to `0` leading to `newh = thisfrag`. Also note >> that `first_hole` here is `0` since `h` and `payload` point to the same >> location. >> >> ```C >> /* finally copy this fragment and possibly return whole packet */ >> memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len); >> ``` >> >> Finally, in the above excerpt the `memcpy` overwrites the hole metadata >> since `thisfrag` and `h` both point to the same location. The hole >> metadata is effectively overwritten with arbitrary data from the >> fragmented IP packet data. If `len` was crafted to be `6`, `last_byte`, >> `next_hole`, and `prev_hole` of the `first_hole` can be controlled by >> the attacker. >> >> Finally the arbitrary offset write occurs through a second fragment that >> only needs to be crafted to write data in the hole pointed to by the >> previously controlled hole metadata (`next_hole`) from the first packet. >> >> ### Recommendation >> >> Handle cases where `len` is strictly lower than 8 by preventing the >> overwrite of the hole metadata during the memcpy of the fragment. This >> could be achieved by either: >> * Moving the location where the hole metadata is stored when `len` is >> lower than `8`. >> * Or outright rejecting fragmented IP datagram with a Total Length >> (`ip_len`) lower than 28 bytes which is the minimum valid fragmented IP >> datagram size (as defined as the minimum fragment of 8 octets in the IP >> Specification Document: >> [RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 25). >> >> ----------BUG 2---------- >> >> # Large buffer overflow leads to DoS in U-Boot IP Packet Defragmentation >> Code (CVE-TBD) >> >> | | | >> | --- | --- | >> |Project | U-Boot | >> |Project URL | https://github.com/u-boot/u-boot | >> |Versions affected | all versions up to commit TBD | >> |Systems affected | All systems defining `CONFIG_IP_DEFRAG` | >> |CVE identifier | TBD | >> |Advisory URL | TBD | >> |Risk | High 7.1 (CVSS:3.1/AV:A/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:H) | >> |Authors | Nicolas Guigo, Nicolas Bidron | >> >> ### Summary >> >> U-boot is a popular boot loader for embedded systems with >> implementations for a large number of architectures and prominent in >> most linux based embedded systems. >> >> ### Location >> >> `u-boot/net/net.c` lines 915 and 1011. >> >> ### Impact >> >> The U-Boot implementation of >> [RFC815](https://datatracker.ietf.org/doc/html/rfc815) IP DATAGRAM >> REASSEMBLY ALGORITHMS is susceptible to a buffer overflow through a >> specially crafted fragmented IP Datagram with an invalid Total Length >> which creates Denial of Service conditions. >> >> ### Description >> >> In compiled versions of U-Boot that define CONFIG_IP_DEFRAG, a value of >> `ip->ip_len` (IP packet header's Total Length) lower than `IP_HDR_SIZE` >> will lead to a negative value for `len` which will ultimately result in >> a buffer overflow during the subsequent `memcpy` that uses `len` as it's >> `count` parameter. >> >> This bug is only exploitable on local ethernet as it requires crafting >> an invalid packet to include an unexpected `ip_len` value in the IP UDP >> header that's lower than the minimum accepted Total Length of a packet >> (21 as defined in the IP Specification Document: >> [RFC791](https://datatracker.ietf.org/doc/html/rfc791)). Such packet >> would in all likelihood be dropped while being routed to its final >> destination through most routing equipment and as such requires the >> attacker to be in a local position in order to be exploited. >> >> ```C >> static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp) >> { >> static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN); >> static u16 first_hole, total_len; >> struct hole *payload, *thisfrag, *h, *newh; >> struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff; >> uchar *indata = (uchar *)ip; >> int offset8, start, len, done = 0; >> u16 ip_off = ntohs(ip->ip_off); >> >> /* payload starts after IP header, this fragment is in there */ >> payload = (struct hole *)(pkt_buff + IP_HDR_SIZE); >> offset8 = (ip_off & IP_OFFS); >> thisfrag = payload + offset8; >> start = offset8 * 8; >> len = ntohs(ip->ip_len) - IP_HDR_SIZE; >> ``` >> >> The last line of the previous excerpt from `u-boot/net/net.c` shows >> where the undeflow to a negative `len` value occurs if `ip_len` is set >> to a value strictly lower than 20 (`IP_HDR_SIZE` being 20). Also note >> that in the above excerpt the `pkt_buff` buffer has a size of >> `CONFIG_NET_MAXDEFRAG` which defaults to 16 KB but can range from 1KB to >> 64 KB depending on configurations. >> >> ```C >> /* finally copy this fragment and possibly return whole packet */ >> memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len); >> ``` >> >> In the above excerpt the `memcpy` overflows the destination by >> attempting to make a copy of nearly 4 gigabytes in a buffer that's >> designed to hold `CONFIG_NET_MAXDEFRAG` bytes at most which leads to a DoS. >> >> ### Recommendation >> >> Stop processing of the packet if `ip_len` is lower than 21 (as defined >> by the minimum length of a data carrying datagram in the IP >> Specification Document: >> [RFC791](https://datatracker.ietf.org/doc/html/rfc791) page 34). >> >> >> Nicolas Bidron, Nicolas Guigo >> > Hi Nicolas, > Thanks for the research. > I have read your description thoroughly, very interesting. > I will implement fixes to the findings. Thanks for looking into this. I wanted to give it a shot as well but got side-tracked. Could you keep me in CC on any patch you have for this? Thanks a lot. Matthias