Skip to content

Commit

Permalink
OS-7591 viona should be strict about cksum offsets
Browse files Browse the repository at this point in the history
Reviewed by: Ryan Zezeski <rpz@joyent.com>
Reviewed by: Robert Mustacchi <rm@joyent.com>
Approved by: Robert Mustacchi <rm@joyent.com>
  • Loading branch information
pfmooney committed Feb 21, 2019
1 parent 15c5e8a commit 4522981
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions usr/src/uts/i86pc/io/viona/viona.c
Expand Up @@ -2532,9 +2532,18 @@ viona_tx_csum(viona_vring_t *ring, const struct virtio_net_hdr *hdr,
ipha_t *ipha = NULL;
uint8_t ipproto = IPPROTO_NONE; /* NONE is not exactly right, but ok */
uint16_t flags = 0;
const uint_t csum_start = hdr->vrh_csum_start;
const uint_t csum_stuff = hdr->vrh_csum_offset + csum_start;

if (MBLKL(mp) < sizeof (*eth)) {
/* Buffers shorter than an ethernet header are hopeless */
/*
* Validate that the checksum offsets provided by the guest are within
* the bounds of the packet. Additionally, ensure that the checksum
* contents field is within the headers mblk copied by viona_tx().
*/
if (csum_start >= len || csum_start < eth_len || csum_stuff >= len ||
(csum_stuff + sizeof (uint16_t)) > MBLKL(mp)) {
VIONA_PROBE2(fail_hcksum, viona_link_t *, link, mblk_t *, mp);
VIONA_RING_STAT_INCR(ring, fail_hcksum);
return (B_FALSE);
}

Expand Down Expand Up @@ -2634,17 +2643,13 @@ viona_tx_csum(viona_vring_t *ring, const struct virtio_net_hdr *hdr,
*/
if ((link->l_cap_csum & HCKSUM_INET_PARTIAL) != 0 &&
(ipproto == IPPROTO_TCP || ipproto == IPPROTO_UDP)) {
uint_t start, stuff, end;

/*
* MAC expects these offsets to be relative to the
* start of the L3 header rather than the L2 frame.
*/
start = hdr->vrh_csum_start - eth_len;
stuff = start + hdr->vrh_csum_offset;
end = len - eth_len;
flags |= HCK_PARTIALCKSUM;
mac_hcksum_set(mp, start, stuff, end, 0, flags);
mac_hcksum_set(mp, csum_start - eth_len, csum_stuff - eth_len,
len - eth_len, 0, flags);
return (B_TRUE);
}

Expand Down

0 comments on commit 4522981

Please sign in to comment.