From nobody Mon Nov 29 18:57:53 2021 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 87F1818AE06E; Mon, 29 Nov 2021 18:57:55 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4J2vkB0C4lz3FbM; Mon, 29 Nov 2021 18:57:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id B1FC7279C8; Mon, 29 Nov 2021 18:57:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1ATIvrrY020387; Mon, 29 Nov 2021 18:57:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1ATIvrkB020386; Mon, 29 Nov 2021 18:57:53 GMT (envelope-from git) Date: Mon, 29 Nov 2021 18:57:53 GMT Message-Id: <202111291857.1ATIvrkB020386@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 1c732c85911e - main - dummynet: Fix socket option length validation for IP_DUMMYNET3 List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 1c732c85911eb9e39071cbdb50dfb1f0d76de40f Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1638212274; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=L6vvSZ97LoBgCsw1vWwnhpjqp6rkcUhfom1yNkpxlSA=; b=ytPq4owkS/6QBGg7IXs0WRakJAWLy5g32+OnfC586DvV7HgSKNz1x/2j2F+Xq24bcOwdx7 PDR6SWnbH+5rw2xs9jdXPSL0tl+fL0eeqGbCbEb9HVkeZEKHsOUVyCzQVxng3znD50tU3N s6VKYFFvkbohPeb/5qKKrYbuRDIcN8+hzMWekjwjDOvMGdeeHqqosRS17tdcMARTRYHQUb JxlcnuhnQNqHqTyqU5N9Nk1Ia97zsMKelQzkIq88tIx4pNsdMofq4HgoItwhsHaRh1PYhI cV05GDn6fnPRSqKpY6W6NOEV8FidoCs+r0d2a+jokJgpxtl9Bbl53o1oln5BAw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1638212274; a=rsa-sha256; cv=none; b=hHNYgrXKV8OjjsygwpmAcg39JepzEX821bZoKeJSCRKV5nmTJ1ZOXe22pT+4cbjjk9Oeh3 wspACFFV/LCyavw6kXgh9blCuAooDgbv1l+OPDFCbEM0i+SUoXoTiyhYFFLg3y4iQz+hT6 Xl8TJStYTwYg7LM47hAchMprAPuMFGFUtZ0/doKepgoF6Ug7rgHBWztu1/qZN7Xae2dEsD A1LcHsjHzWq6fRC0dA6fxb83mULiAFvT50Ty+t7jn8RTTBTmLnHkw0UIhbD13tHA41gWGF ZVCP8kf2PEilgp53OUATQs+qSA9jQ3vrW7ctOdNH0gSLfXcrfl973s0aTFCnKQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=1c732c85911eb9e39071cbdb50dfb1f0d76de40f commit 1c732c85911eb9e39071cbdb50dfb1f0d76de40f Author: Mark Johnston AuthorDate: 2021-11-29 18:50:30 +0000 Commit: Mark Johnston CommitDate: 2021-11-29 18:57:24 +0000 dummynet: Fix socket option length validation for IP_DUMMYNET3 The socket option handler tries to ensure that the option length is no larger than some reasonable maximum, and no smaller than sizeof(struct dn_id). But the loaded option length is stored in an int, which is converted to an unsigned integer for the comparison with a size_t, so negative values are not caught and instead get passed to malloc(). Change the code to use a size_t for the buffer size. Reviewed by: kp MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D33133 --- sys/netpfil/ipfw/ip_dn_private.h | 2 +- sys/netpfil/ipfw/ip_dummynet.c | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/sys/netpfil/ipfw/ip_dn_private.h b/sys/netpfil/ipfw/ip_dn_private.h index cc084f2fcc0d..25015fe02c2d 100644 --- a/sys/netpfil/ipfw/ip_dn_private.h +++ b/sys/netpfil/ipfw/ip_dn_private.h @@ -437,7 +437,7 @@ int dn_compat_copy_queue(struct copy_args *a, void *_o); int dn_compat_copy_pipe(struct copy_args *a, void *_o); int copy_data_helper_compat(void *_o, void *_arg); int dn_compat_calc_size(void); -int do_config(void *p, int l); +int do_config(void *p, size_t l); /* function to drain idle object */ void dn_drain_scheduler(void); diff --git a/sys/netpfil/ipfw/ip_dummynet.c b/sys/netpfil/ipfw/ip_dummynet.c index 919445ff71d0..0cd606bd56b2 100644 --- a/sys/netpfil/ipfw/ip_dummynet.c +++ b/sys/netpfil/ipfw/ip_dummynet.c @@ -1991,7 +1991,7 @@ dummynet_flush(void) * processed on a config_sched. */ int -do_config(void *p, int l) +do_config(void *p, size_t l) { struct dn_id o; union { @@ -2015,7 +2015,7 @@ do_config(void *p, int l) while (l >= sizeof(o)) { memcpy(&o, (char *)p + off, sizeof(o)); if (o.len < sizeof(o) || l < o.len) { - D("bad len o.len %d len %d", o.len, l); + D("bad len o.len %d len %zu", o.len, l); err = EINVAL; break; } @@ -2487,7 +2487,8 @@ ip_dn_ctl(struct sockopt *sopt) { struct epoch_tracker et; void *p = NULL; - int error, l; + size_t l; + int error; error = priv_check(sopt->sopt_td, PRIV_NETINET_DUMMYNET); if (error) @@ -2516,14 +2517,14 @@ ip_dn_ctl(struct sockopt *sopt) error = ip_dummynet_compat(sopt); break; - case IP_DUMMYNET3 : + case IP_DUMMYNET3: if (sopt->sopt_dir == SOPT_GET) { error = dummynet_get(sopt, NULL); break; } l = sopt->sopt_valsize; if (l < sizeof(struct dn_id) || l > 12000) { - D("argument len %d invalid", l); + D("argument len %zu invalid", l); break; } p = malloc(l, M_TEMP, M_NOWAIT); @@ -2532,9 +2533,8 @@ ip_dn_ctl(struct sockopt *sopt) break; } error = sooptcopyin(sopt, p, l, l); - if (error) - break ; - error = do_config(p, l); + if (error == 0) + error = do_config(p, l); break; }