diff options
author | luigi <luigi@FreeBSD.org> | 2014-06-06 10:50:14 +0000 |
---|---|---|
committer | luigi <luigi@FreeBSD.org> | 2014-06-06 10:50:14 +0000 |
commit | 2bd9920d99a647add45dde2d47a90ee50f720958 (patch) | |
tree | b0e83e6372bceeceb68b538fb2d1429382a788a0 | |
parent | 797957e4e569d08045e48904413b9e8f6ce5e2ec (diff) | |
download | FreeBSD-src-2bd9920d99a647add45dde2d47a90ee50f720958.zip FreeBSD-src-2bd9920d99a647add45dde2d47a90ee50f720958.tar.gz |
add checks for invalid buffer pointers and lengths
-rw-r--r-- | sys/dev/netmap/netmap_vale.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/sys/dev/netmap/netmap_vale.c b/sys/dev/netmap/netmap_vale.c index 242185d..47738c8 100644 --- a/sys/dev/netmap/netmap_vale.c +++ b/sys/dev/netmap/netmap_vale.c @@ -959,6 +959,14 @@ nm_bdg_preflush(struct netmap_vp_adapter *na, u_int ring_nr, ft[ft_i].ft_next = NM_FT_NULL; buf = ft[ft_i].ft_buf = (slot->flags & NS_INDIRECT) ? (void *)(uintptr_t)slot->ptr : BDG_NMB(&na->up, slot); + if (unlikely(buf == NULL)) { + RD(5, "NULL %s buffer pointer from %s slot %d len %d", + (slot->flags & NS_INDIRECT) ? "INDIRECT" : "DIRECT", + kring->name, j, ft[ft_i].ft_len); + buf = ft[ft_i].ft_buf = NMB_VA(0); /* the 'null' buffer */ + ft[ft_i].ft_len = 0; + ft[ft_i].ft_flags = 0; + } __builtin_prefetch(buf); ++ft_i; if (slot->flags & NS_MOREFRAG) { @@ -1312,6 +1320,7 @@ nm_bdg_flush(struct nm_bdg_fwd *ft, u_int n, struct netmap_vp_adapter *na, needed = d->bq_len + brddst->bq_len; if (unlikely(dst_na->virt_hdr_len != na->virt_hdr_len)) { + RD(3, "virt_hdr_mismatch, src %d len %d", na->virt_hdr_len, dst_na->virt_hdr_len); /* There is a virtio-net header/offloadings mismatch between * source and destination. The slower mismatch datapath will * be used to cope with all the mismatches. @@ -1412,6 +1421,11 @@ retry: /* round to a multiple of 64 */ copy_len = (copy_len + 63) & ~63; + if (unlikely(copy_len > NETMAP_BUF_SIZE || + copy_len > NETMAP_BUF_SIZE)) { + RD(5, "invalid len %d, down to 64", (int)copy_len); + copy_len = dst_len = 64; // XXX + } if (ft_p->ft_flags & NS_INDIRECT) { if (copyin(src, dst, copy_len)) { // invalid user pointer, pretend len is 0 |