aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuigi Rizzo <luigi@FreeBSD.org>2014-06-06 10:50:14 +0000
committerLuigi Rizzo <luigi@FreeBSD.org>2014-06-06 10:50:14 +0000
commite31c6ec7e22ffd2f7b28eabe2c9816acaf60579c (patch)
treeb0e83e6372bceeceb68b538fb2d1429382a788a0
parent441ab64f52aefea2fa99c06bcbec122ca9143af0 (diff)
downloadsrc-e31c6ec7e22ffd2f7b28eabe2c9816acaf60579c.tar.gz
src-e31c6ec7e22ffd2f7b28eabe2c9816acaf60579c.zip
add checks for invalid buffer pointers and lengths
Notes
Notes: svn path=/head/; revision=267151
-rw-r--r--sys/dev/netmap/netmap_vale.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/sys/dev/netmap/netmap_vale.c b/sys/dev/netmap/netmap_vale.c
index 242185da6029..47738c89e4bc 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