From nobody Mon Oct 17 09:05:44 2022 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 4MrWLJ3ycrz4fL3l; Mon, 17 Oct 2022 09:05:44 +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 4MrWLJ3Kjzz3RN1; Mon, 17 Oct 2022 09:05:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1665997544; 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=BSU/6yWTyBNUVWNA5XJ1hAelZJXAnribvlhWyBjBqlY=; b=cO2RN9eiHSuhmsu1DpFs/CwDWy4DJ/XSNAzuey1X9t+a0NpSRkdVsfQZncjj6OBO0L3Fwx WL3BnTs8isTye6FAptdPTkUzYAd9TsWKDkyvy6eCykpGibMb3IMUqswCCFLHbeSNuSClA8 cJe2p3DaX66PC8JDxPeMtQYkZkdXTqy5pc1vzIxS2unAr5VN5yznvRcp8pfFluBzNFql1U 7YP57+AU0ysGcyz+dxEJk9MyJkzEKzqBYSVPc6AKt/fEkbRNDRrZ6IiEVctNPawj7i/xW4 KyPcIUgGJ1BUQdY4S6VdoElABctjfX+u5o4N8ATHoq0ULKLNTeP+D0OnVLfuxg== 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 4MrWLJ2FPpzls5; Mon, 17 Oct 2022 09:05:44 +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 29H95i3T020229; Mon, 17 Oct 2022 09:05:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 29H95iSu020228; Mon, 17 Oct 2022 09:05:44 GMT (envelope-from git) Date: Mon, 17 Oct 2022 09:05:44 GMT Message-Id: <202210170905.29H95iSu020228@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: b136983a8a78 - main - if_ovpn: fix use-after-free 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: kp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b136983a8a786677967b532fe74ae7975deec47b Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1665997544; 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=BSU/6yWTyBNUVWNA5XJ1hAelZJXAnribvlhWyBjBqlY=; b=mcITwQRtqLRrR6KOFgztU63XgHx4cUzmo1b+Fn/3/EnhWOSRHUL/IAN3eMV9/LjC7ZDRuM aS9bXTP4hp8np7yrlE2lLTDLdHJf2Yw9b5P9vO3TcwCDPUW+Yn5713RVl4p4Gn9WGnM649 3Tzw+R9Zqrf63gRD8TADvojg6K42si/ZUw2A5I4rQaQbCR9oMgBsOEp+mTGUKTznjE5rEV ojmp5ELtdePBAxMiJihErxKhySQuaDdGKTzFOXmvHpgucBLU60Re74oZHh2LtCqmFy2afz 2I1XtYI2RTtQQM5fXij2QenmiNU02jnkeAlZ5LIRGIUCX5B/2qd8crUz74L1gA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1665997544; a=rsa-sha256; cv=none; b=ryHsgsevS/o6yFNE0tt6wGPXFEx1JgZPmjZDgpbRv8Mj/nERpvISnR+dM4lcYJK2CXQ/AD FE/tTz0aCl70D0VQuO+zSF8DXZlHnHx8GPmwFem2KKybJn9N04CY5t41y3Th1/KT24dduD sT/YICw0xMh9LENQ00N3UimJfpKvc9E4e8B0hS5+OfOxqy1nybj9BJAfyKFXE3fYli13F9 2bXjsxE2I+AC6n3GS1eHSyIogsnGV3U5EkfofmKNVQIojffl5artEwQG/nPoTDAXJ98JfP BnUlWPQlzJagvMYSQRWlqP+lLg3kG6A2ptO+tDlGOVT3MxOuOsDOOtIO/+UW7w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=b136983a8a786677967b532fe74ae7975deec47b commit b136983a8a786677967b532fe74ae7975deec47b Author: Kristof Provost AuthorDate: 2022-10-17 07:24:41 +0000 Commit: Kristof Provost CommitDate: 2022-10-17 07:24:41 +0000 if_ovpn: fix use-after-free ovpn_encrypt_tx_cb() calls ovpn_encap() to transmit a packet, then adds the length of the packet to the "tunnel_bytes_sent" counter. However, after ovpn_encap() returns 0, the mbuf chain may have been freed, so the load of m->m_pkthdr.len may be a use-after-free. Reported by: markj Sponsored by: Rubicon Communications, LLC ("Netgate") --- sys/net/if_ovpn.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sys/net/if_ovpn.c b/sys/net/if_ovpn.c index 55da53ae3eb6..524640639e76 100644 --- a/sys/net/if_ovpn.c +++ b/sys/net/if_ovpn.c @@ -1382,6 +1382,7 @@ ovpn_encrypt_tx_cb(struct cryptop *crp) struct ovpn_kpeer *peer = crp->crp_opaque; struct ovpn_softc *sc = peer->sc; struct mbuf *m = crp->crp_buf.cb_mbuf; + int tunnel_len; int ret; if (crp->crp_etype != 0) { @@ -1397,11 +1398,11 @@ ovpn_encrypt_tx_cb(struct cryptop *crp) MPASS(crp->crp_buf.cb_type == CRYPTO_BUF_MBUF); + tunnel_len = m->m_pkthdr.len - sizeof(struct ovpn_wire_header); ret = ovpn_encap(sc, peer->peerid, m); if (ret == 0) { OVPN_COUNTER_ADD(sc, sent_data_pkts, 1); - OVPN_COUNTER_ADD(sc, tunnel_bytes_sent, m->m_pkthdr.len - - sizeof(struct ovpn_wire_header)); + OVPN_COUNTER_ADD(sc, tunnel_bytes_sent, tunnel_len); } CURVNET_RESTORE();