Skip to content

Commit 75d658a

Browse files
committed
[general][sdk] update mbedtls and lwip codes (Ameba-AIoT#24)
* [general][mbedtls] update mbedtls * Add secure flag and declaration. * [general][lwip] fix CVE-2020-22283 in lwip 2.1.2 * fix CVE-2020-22283 in lwip 2.1.2 Notes: * Fix CVE-2020-22283 in lwip v2.1.2 * Based on https://nvd.nist.gov/vuln/detail/CVE-2020-22283 * A buffer overflow vulnerability in the icmp6_send_response_with_addrs_and_netif() function of Free Software Foundation lwIP version git head allows attackers to access sensitive information via a crafted ICMPv6 packet.
1 parent 3fead39 commit 75d658a

File tree

7 files changed

+41
-13
lines changed

7 files changed

+41
-13
lines changed

common/lwip/lwip_v2.1.2/src/core/ipv6/icmp6.c

+18-9
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@
5757

5858
#include <string.h>
5959

60-
#if LWIP_ICMP6_DATASIZE == 0
60+
#if !LWIP_ICMP6_DATASIZE || (LWIP_ICMP6_DATASIZE > (IP6_MIN_MTU_LENGTH - IP6_HLEN - ICMP6_HLEN))
6161
#undef LWIP_ICMP6_DATASIZE
62-
#define LWIP_ICMP6_DATASIZE 8
62+
#define LWIP_ICMP6_DATASIZE (IP6_MIN_MTU_LENGTH - IP6_HLEN - ICMP6_HLEN)
6363
#endif
6464

6565
/* Forward declarations */
@@ -387,26 +387,35 @@ icmp6_send_response_with_addrs_and_netif(struct pbuf *p, u8_t code, u32_t data,
387387
{
388388
struct pbuf *q;
389389
struct icmp6_hdr *icmp6hdr;
390+
u16_t datalen = LWIP_MIN(p->tot_len, LWIP_ICMP6_DATASIZE);
391+
u16_t offset;
390392

391-
/* ICMPv6 header + IPv6 header + data */
392-
q = pbuf_alloc(PBUF_IP, sizeof(struct icmp6_hdr) + IP6_HLEN + LWIP_ICMP6_DATASIZE,
393+
/* ICMPv6 header + datalen (as much of the offending packet as possible) */
394+
q = pbuf_alloc(PBUF_IP, sizeof(struct icmp6_hdr) + datalen,
393395
PBUF_RAM);
394396
if (q == NULL) {
395397
LWIP_DEBUGF(ICMP_DEBUG, ("icmp_time_exceeded: failed to allocate pbuf for ICMPv6 packet.\n"));
396398
ICMP6_STATS_INC(icmp6.memerr);
397399
return;
398400
}
399-
LWIP_ASSERT("check that first pbuf can hold icmp 6message",
400-
(q->len >= (sizeof(struct icmp6_hdr) + IP6_HLEN + LWIP_ICMP6_DATASIZE)));
401+
LWIP_ASSERT("check that first pbuf can hold icmp6 header",
402+
(q->len >= (sizeof(struct icmp6_hdr))));
401403

402404
icmp6hdr = (struct icmp6_hdr *)q->payload;
403405
icmp6hdr->type = type;
404406
icmp6hdr->code = code;
405407
icmp6hdr->data = lwip_htonl(data);
406408

407-
/* copy fields from original packet */
408-
SMEMCPY((u8_t *)q->payload + sizeof(struct icmp6_hdr), (u8_t *)p->payload,
409-
IP6_HLEN + LWIP_ICMP6_DATASIZE);
409+
/* copy fields from original packet (which may be a chain of pbufs) */
410+
offset = sizeof(struct icmp6_hdr);
411+
while (p && datalen) {
412+
u16_t len = LWIP_MIN(datalen, p->len);
413+
err_t res = pbuf_take_at(q, p->payload, len, offset);
414+
if (res != ERR_OK) break;
415+
datalen -= len;
416+
offset += len;
417+
p = p->next;
418+
}
410419

411420
/* calculate checksum */
412421
icmp6hdr->chksum = 0;

common/lwip/lwip_v2.1.2/src/include/lwip/opt.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -2494,10 +2494,12 @@
24942494

24952495
/**
24962496
* LWIP_ICMP6_DATASIZE: bytes from original packet to send back in
2497-
* ICMPv6 error messages.
2497+
* ICMPv6 error messages (0 = default of IP6_MIN_MTU_LENGTH)
2498+
* ATTENTION: RFC4443 section 2.4 says IP6_MIN_MTU_LENGTH is a MUST,
2499+
* so override this only if you absolutely have to!
24982500
*/
24992501
#if !defined LWIP_ICMP6_DATASIZE || defined __DOXYGEN__
2500-
#define LWIP_ICMP6_DATASIZE 8
2502+
#define LWIP_ICMP6_DATASIZE 0
25012503
#endif
25022504

25032505
/**

common/lwip/lwip_v2.1.2/src/include/lwip/prot/icmp6.h

+2
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ PACK_STRUCT_END
146146
# include "arch/epstruct.h"
147147
#endif
148148

149+
#define ICMP6_HLEN 8
150+
149151
/** This is the ICMP6 header adapted for echo req/resp. */
150152
#ifdef PACK_STRUCT_USE_INCLUDES
151153
# include "arch/bpstruct.h"

common/lwip/lwip_v2.1.2/src/include/lwip/prot/ip6.h

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
extern "C" {
4545
#endif
4646

47+
#define IP6_MIN_MTU_LENGTH 1280
48+
4749
/** This is the packed version of ip6_addr_t,
4850
used in network headers that are itself packed */
4951
#ifdef PACK_STRUCT_USE_INCLUDES

common/mbedtls/mbedtls-2.28.1/library/ssl_msg.c

+13
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@
2929
#include "common.h"
3030

3131
#include "device_lock.h"
32+
33+
#if defined(CONFIG_BUILD_SECURE) && (CONFIG_BUILD_SECURE == 1)
34+
#if defined(__ICCARM__)
35+
extern void (__cmse_nonsecure_call *ns_device_mutex_lock)(uint32_t);
36+
extern void (__cmse_nonsecure_call *ns_device_mutex_unlock)(uint32_t);
37+
#else
38+
extern void __attribute__((cmse_nonsecure_call)) (*ns_device_mutex_lock)(uint32_t);
39+
extern void __attribute__((cmse_nonsecure_call)) (*ns_device_mutex_unlock)(uint32_t);
40+
#endif
41+
#define device_mutex_lock ns_device_mutex_lock
42+
#define device_mutex_unlock ns_device_mutex_unlock
43+
#endif
44+
3245
#if defined(MBEDTLS_SSL_TLS_C)
3346

3447
#if defined(MBEDTLS_PLATFORM_C)

tools/docker/amebad/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ FROM ameba-rtos-matter:common
33

44
# Redefine following build arguments to respective repo and tag/branch
55
ARG AMEBA_MATTER_REPO=https://github.com/xshuqun/ameba-rtos-matter.git
6-
ARG TAG_NAME=ameba/update_sdk_250302
6+
ARG TAG_NAME=ameba/sync_sdk_250313
77

88
# Define fixed build arguments
99
ARG AMBD_REPO=https://github.com/Ameba-AIoT/ameba-rtos-d.git

tools/docker/amebaz2/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ FROM ameba-rtos-matter:common
33

44
# Redefine following build arguments to respective repo and tag/branch
55
ARG AMEBA_MATTER_REPO=https://github.com/xshuqun/ameba-rtos-matter.git
6-
ARG TAG_NAME=ameba/update_sdk_250302
6+
ARG TAG_NAME=ameba/sync_sdk_250313
77

88
# Define fixed build arguments
99
ARG AMBZ2_REPO=https://github.com/Ameba-AIoT/ameba-rtos-z2.git

0 commit comments

Comments
 (0)