aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincenzo Maffione <vmaffione@FreeBSD.org>2022-03-16 06:57:54 +0000
committerVincenzo Maffione <vmaffione@FreeBSD.org>2022-03-19 17:37:13 +0000
commit95602165e33a3045a27245cc1e61e67bf4feeed1 (patch)
tree01972ab465daa730bf00a615d0b24cb9a3e6804e
parentc457983b9613de2c808bc1157c35e0d7e2305aee (diff)
netmap: Fix integer overflow in nmreq_copyin
An unsanitized field in an option could be abused, causing an integer overflow followed by kernel memory corruption. This might be used to escape jails/containers. Reported by: Reno Robert and Lucas Leong (@_wmliang_) of Trend Micro Zero Day Initiative Security: CVE-2022-23085 (cherry picked from commit 694ea59c7021c25417e6d516362d2f59b4e2c343)
-rw-r--r--sys/dev/netmap/netmap.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/sys/dev/netmap/netmap.c b/sys/dev/netmap/netmap.c
index 6532856b21a1..cefc72c60817 100644
--- a/sys/dev/netmap/netmap.c
+++ b/sys/dev/netmap/netmap.c
@@ -3086,7 +3086,7 @@ nmreq_opt_size_by_type(uint32_t nro_reqtype, uint64_t nro_size)
int
nmreq_copyin(struct nmreq_header *hdr, int nr_body_is_user)
{
- size_t rqsz, optsz, bufsz;
+ size_t rqsz, optsz, bufsz, optbodysz;
int error = 0;
char *ker = NULL, *p;
struct nmreq_option **next, *src, **opt_tab;
@@ -3134,8 +3134,18 @@ nmreq_copyin(struct nmreq_header *hdr, int nr_body_is_user)
error = copyin(src, &buf, sizeof(*src));
if (error)
goto out_err;
+ /* Validate nro_size to avoid integer overflow of optsz and bufsz. */
+ if (buf.nro_size > NETMAP_REQ_MAXSIZE) {
+ error = EMSGSIZE;
+ goto out_err;
+ }
optsz += sizeof(*src);
- optsz += nmreq_opt_size_by_type(buf.nro_reqtype, buf.nro_size);
+ optbodysz = nmreq_opt_size_by_type(buf.nro_reqtype, buf.nro_size);
+ if (optbodysz > NETMAP_REQ_MAXSIZE) {
+ error = EMSGSIZE;
+ goto out_err;
+ }
+ optsz += optbodysz;
if (rqsz + optsz > NETMAP_REQ_MAXSIZE) {
error = EMSGSIZE;
goto out_err;