TCP: Prevent incorrectly formed PDUs causing RAM exhaustion.

src/net.c:

Add in a sanity check that the PDU length is not more that the negotiated
CSM size for incoming data.
Track CSM remote supports block transfer.
Do not allow Block options if CSM has not negotiated block transfer.

src/coap_session.c:

Include block-wise-transfer is supported in the CSM

include/coap2/coap_session.h:

Make MTU size bigger than 32 bits as CSM mtu size can be greater than 32 bits.
Track CSM remote supports block transfer.

include/coap2/pdu.h:

Make COAP_DEFAULT_MAX_PDU_RX_SIZE a unsigned long to be bigger than 32 bits.
This commit is contained in:
Jon Shallow committed 2020-06-16 08:28:14 +01:00
1 parent 9a61290b0b
commit 88151d3eb7
4 files changed
+36 -5

No files matched your search

+2 -1
View File
@@ -63,7 +63,7 @@ typedef struct coap_session_t {
coap_session_state_t state; /**< current state of relationaship with peer */
unsigned ref; /**< reference count from queues */
unsigned tls_overhead; /**< overhead of TLS layer */
unsigned mtu; /**< path or CSM mtu */
uint64_t mtu; /**< path or CSM mtu */
coap_address_t local_if; /**< optional local interface address */
UT_hash_handle hh;
coap_addr_tuple_t addr_info; /**< key: remote/local address info */
@@ -74,6 +74,7 @@ typedef struct coap_session_t {
void *tls; /**< security parameters */
uint16_t tx_mid; /**< the last message id that was used in this session */
uint8_t con_active; /**< Active CON request sent */
uint8_t csm_block_supported; /**< CSM TCP blocks supported */
coap_tid_t last_ping_mid; /**< the last keepalive message id that was used in this session */
struct coap_queue_t *delayqueue; /**< list of delayed messages waiting to be sent */
size_t partial_write; /**< if > 0 indicates number of bytes already written from the pdu at the head of sendqueue */
+2 -2
View File
@@ -45,10 +45,10 @@ struct coap_session_t;
#ifndef COAP_DEFAULT_MAX_PDU_RX_SIZE
#if defined(WITH_CONTIKI) || defined(WITH_LWIP)
#define COAP_DEFAULT_MAX_PDU_RX_SIZE (COAP_MAX_MESSAGE_SIZE_TCP16+4)
#define COAP_DEFAULT_MAX_PDU_RX_SIZE (COAP_MAX_MESSAGE_SIZE_TCP16+4UL)
#else
/* 8 MiB max-message-size plus some space for options */
#define COAP_DEFAULT_MAX_PDU_RX_SIZE (8*1024*1024+256)
#define COAP_DEFAULT_MAX_PDU_RX_SIZE (8UL*1024*1024+256)
#endif
#endif /* COAP_DEFAULT_MAX_PDU_RX_SIZE */