Skip to content

Commit

Permalink
Bug #792 avoid assertion and other fixes
Browse files Browse the repository at this point in the history
SLL (Linux cooked packets v1) caused a crash due to an overly aggressive assert.

While here, fixed an issue where resultant packets were corrupt (wrong size, incorrect protocol)
  • Loading branch information
fklassen committed Jun 8, 2024
1 parent 6c32ff1 commit 70a7843
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 3 additions & 1 deletion docs/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
- configure.ac: unify search dirs for pcap and add lib32 (#819)
- CVE-2023-4256 double free in tcprewrite DLT_JUNIPER_ETHER (#813 #851)
- dlt_jnpr_ether_cleanup: check config before cleanup (#812 #851)
- nanosecond timestamps (#796)
- SEGV on invalid Juniper Ethernet header length (#811)
- nanosecond timestamps support (#796)
- Linux cooked packet fatal error (#792)
- low PPS values run at full speed after several days (#779)
- create DLT_LINUX_SLL2 plugin (#727)

Expand Down
14 changes: 9 additions & 5 deletions src/tcpedit/plugins/dlt_en10mb/en10mb.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,9 +519,9 @@ dlt_en10mb_encode(tcpeditdlt_t *ctx, u_char *packet, int pktlen, tcpr_dir_t dir)
}

/* newl2len for some other DLT -> ethernet */
else if (config->vlan == TCPEDIT_VLAN_ADD) {
/* if add a vlan then 18, */
newl2len = TCPR_802_1Q_H;
else {
newl2len = config->vlan == TCPEDIT_VLAN_ADD ? TCPR_802_1Q_H : TCPR_802_3_H;
oldl2len = ctx->l2len;
}

if ((uint32_t)pktlen < newl2len || pktlen + newl2len - ctx->l2len > MAXPACKET) {
Expand Down Expand Up @@ -555,7 +555,6 @@ dlt_en10mb_encode(tcpeditdlt_t *ctx, u_char *packet, int pktlen, tcpr_dir_t dir)

/* update the total packet length */
pktlen += (int)(newl2len - oldl2len);
ctx->l2len += (int)(newl2len - oldl2len);

/* set the src & dst address as the first 12 bytes */
eth = (struct tcpr_ethernet_hdr *)(packet + ctx->l2offset);
Expand Down Expand Up @@ -665,6 +664,11 @@ dlt_en10mb_encode(tcpeditdlt_t *ctx, u_char *packet, int pktlen, tcpr_dir_t dir)
}
}

if (newl2len == TCPR_802_3_H) {
/* all we need for 802.3 is the proto */
eth->ether_type = ctx->proto;
}

if (config->vlan == TCPEDIT_VLAN_ADD || (config->vlan == TCPEDIT_VLAN_OFF && extra->vlan)) {
vlan_hdr = (struct tcpr_802_1q_hdr *)(packet + extra->vlan_offset);
if (config->vlan == TCPEDIT_VLAN_ADD) {
Expand Down Expand Up @@ -812,7 +816,7 @@ dlt_en10mb_merge_layer3(tcpeditdlt_t *ctx, u_char *packet, int pktlen, u_char *i
if (l2len == -1 || pktlen < l2len)
return NULL;

assert(ctx->decoded_extra_size == sizeof(*extra));
assert(ctx->decoded_extra_size >= sizeof(*extra));
extra = (en10mb_extra_t *)ctx->decoded_extra;
eth = (struct tcpr_ethernet_hdr *)(packet + ctx->l2offset);
assert(eth);
Expand Down

0 comments on commit 70a7843

Please sign in to comment.