From patchwork Tue Apr 1 20:47:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 4203 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:6c6:b0:60a:d70a:d3c7 with SMTP id j6csp3104253maw; Tue, 1 Apr 2025 13:47:52 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUX4Q788ktI98spgnvly9inN2M88jrhdtaz+QYRH6abCzc4MdOClvwguJtxhYJDlKQm1iU5a2N6hIY=@openvpn.net X-Google-Smtp-Source: AGHT+IHuysjXtsRZHdolepBXhp8pFD5eNnSeFQ+AP+XJHIc5x/jRxRvuTfhOEmvJ1q+uJd5OIJ+m X-Received: by 2002:a05:6602:29a9:b0:85d:f74b:f8a8 with SMTP id ca18e2360f4ac-85ed7bf214cmr1564639f.2.1743540472261; Tue, 01 Apr 2025 13:47:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1743540472; cv=none; d=google.com; s=arc-20240605; b=eq7KP9Ik9dswF16ziUTjZv5Iu8JvYKni5u7GYvzOdFxg+brlFD3Xj5MgiiN2SsDXor IozgjY6SNBlsiNohNVPz/n5oUEkrQZqBff+MxwWbnMe3IfrSGB2bIXNoAvsRmdn1a0vq q1aX+TEj7SXFbZEOJeubL4EHHRVo60nkTOORlezRIik6AR+cTDrMt0hKZtZavmngCB+g mp/r2os2QAiIJXoNLEBG1RLXbC3rLK7NHJtYvJ8UW+AW/ijf18x98WZbNfvMdqd/pfgm x2SpnRZuwwPEl7CGYW9MpuS2tXngp//0Nk4mN4zhxVVsXq/T6jQjbu2HbO8h/NvW479F KzSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature; bh=BXP/a/hzvikrFf9tkOCAMaFjY9pu1GkDWcijLtL3YtE=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=FSsF/w2hPrMcjLapHQcxMv4k2qAV2ebJB0nHpIfGktVv44dn1SXJefRWklH3eDBioD mWe8dB8xUCZklLzczuRRfKnbApex1pa8hP708mCP9ArRA9XdqLJoRLMNMAJY+sphrlrE WqzceGn8g8G6PQ98ueSLClnFB2Q2RQawy9TqMIu8bDrFZxxMdm5EJuBHSGAwRsuxYNf6 P4pH3rPTxuRL+ksK7LXUmSLYdtqiQXuMLxQUy2IB46JUeB5Hi9HQAtJ87romej32oETn KsdW7XpHLiNOYDUe3iz7jHJ9TviQJmiP+SO9bDgMv9NtlMuRiBjuAGX/lNMX1uWiJnuL VN5g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=FkG2M+sE; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=VFE+ONUa; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id ca18e2360f4ac-85e901f09a0si1002858339f.117.2025.04.01.13.47.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Apr 2025 13:47:52 -0700 (PDT) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=FkG2M+sE; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=VFE+ONUa; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1tziWQ-0006OK-P0; Tue, 01 Apr 2025 20:47:47 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1tziWP-0006OB-Fo for openvpn-devel@lists.sourceforge.net; Tue, 01 Apr 2025 20:47:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=FIuCtghubDD/bOV0D2ua5NqbPE6cCfsnuDjn0codIFU=; b=FkG2M+sETD5F/hp3tXcghV/8h3 1bp4SmX0EJPZhEaJ7fOvDUjoSufjbL4uYas/FTA612P4ELaPc9D7goGpMQmWIQMVivqOchwC3n0w5 TxH5eJYuCGsEMPugWQq8sgQIJwnLm7JFnqLlczxfXVANQ39cUveFNje2AIcqi8uPifVg=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=FIuCtghubDD/bOV0D2ua5NqbPE6cCfsnuDjn0codIFU=; b=VFE+ONUaOrkuYaZWxzWNB1ugOz TzZZQ+7ioAQRkyZOOKHcoCWKH5kZyKcWEhoMboCVLyJliY0qrw7ORQ8OvwzV7q6vxY1+IJn5XUN82 JNqnOa6ckeUB11sr/HPnDiKBa0A5MP8E8CUZUYWN+nS/zKqBPTBuSpfAwiwFON+dqtuM=; Received: from dhcp-174.greenie.muc.de ([193.149.48.174] helo=blue.greenie.muc.de) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1tziW9-0003wC-Bb for openvpn-devel@lists.sourceforge.net; Tue, 01 Apr 2025 20:47:45 +0000 Received: from blue.greenie.muc.de (localhost [127.0.0.1]) by blue.greenie.muc.de (8.17.1.9/8.17.1.9) with ESMTP id 531KlHBl031731 for ; Tue, 1 Apr 2025 22:47:17 +0200 Received: (from gert@localhost) by blue.greenie.muc.de (8.17.1.9/8.17.1.9/Submit) id 531KlHQE031730 for openvpn-devel@lists.sourceforge.net; Tue, 1 Apr 2025 22:47:17 +0200 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Tue, 1 Apr 2025 22:47:09 +0200 Message-ID: <20250401204716.31659-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Score: 0.0 (/) X-Spam-Report: Spam detection software, running on the system "util-spamd-2.v13.lw.sourceforge.com", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Lev Stipakov The OVERLAPPED structure must remain valid for the entire duration of an asynchronous operation. Previously, when a TCP connection was pending inside the NEW_PEER call, the OVERLAPPED structure was de [...] Content analysis details: (0.0 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 RCVD_IN_VALIDITY_RPBL_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [193.149.48.174 listed in bl.score.senderscore.com] 0.0 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [193.149.48.174 listed in sa-trusted.bondedsender.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record X-Headers-End: 1tziW9-0003wC-Bb Subject: [Openvpn-devel] [PATCH v1] dco-win: Fix crash when cancelling pending operation X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1828225143005195587?= X-GMAIL-MSGID: =?utf-8?q?1828234694129060851?= From: Lev Stipakov The OVERLAPPED structure must remain valid for the entire duration of an asynchronous operation. Previously, when a TCP connection was pending inside the NEW_PEER call, the OVERLAPPED structure was defined as a local variable within dco_p2p_new_peer(). When CancelIo() was called later from close_tun_handle(), the OVERLAPPED structure was already out of scope, resulting in undefined behavior and stack corruption. This fix moves the OVERLAPPED structure to the tuntap struct, ensuring it remains valid throughout the operation's lifetime. GitHub: #715 Change-Id: Ib1db457c42a80f6b8fc0e3ceb4a895d4cf7f0155 Signed-off-by: Lev Stipakov Acked-by: Gert Doering --- This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master. Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/928 This mail reflects revision 1 of this Change. Acked-by according to Gerrit (reflected above): Gert Doering diff --git a/src/openvpn/dco_win.c b/src/openvpn/dco_win.c index 8b47124..a386e53 100644 --- a/src/openvpn/dco_win.c +++ b/src/openvpn/dco_win.c @@ -321,7 +321,7 @@ } void -dco_p2p_new_peer(HANDLE handle, struct link_socket *sock, struct signal_info *sig_info) +dco_p2p_new_peer(HANDLE handle, OVERLAPPED *ov, struct link_socket *sock, struct signal_info *sig_info) { msg(D_DCO_DEBUG, "%s", __func__); @@ -395,8 +395,8 @@ ASSERT(0); } - OVERLAPPED ov = { 0 }; - if (!DeviceIoControl(handle, OVPN_IOCTL_NEW_PEER, &peer, sizeof(peer), NULL, 0, NULL, &ov)) + CLEAR(*ov); + if (!DeviceIoControl(handle, OVPN_IOCTL_NEW_PEER, &peer, sizeof(peer), NULL, 0, NULL, ov)) { DWORD err = GetLastError(); if (err != ERROR_IO_PENDING) @@ -405,7 +405,7 @@ } else { - dco_connect_wait(handle, &ov, get_server_poll_remaining_time(sock->server_poll_timeout), sig_info); + dco_connect_wait(handle, ov, get_server_poll_remaining_time(sock->server_poll_timeout), sig_info); } } } diff --git a/src/openvpn/dco_win.h b/src/openvpn/dco_win.h index 95c95c8..e8e4e22 100644 --- a/src/openvpn/dco_win.h +++ b/src/openvpn/dco_win.h @@ -63,7 +63,7 @@ dco_mp_start_vpn(HANDLE handle, struct link_socket *sock); void -dco_p2p_new_peer(HANDLE handle, struct link_socket *sock, struct signal_info *sig_info); +dco_p2p_new_peer(HANDLE handle, OVERLAPPED *ov, struct link_socket *sock, struct signal_info *sig_info); void dco_start_tun(struct tuntap *tt); diff --git a/src/openvpn/socket.c b/src/openvpn/socket.c index 09de1b0..beb31fa 100644 --- a/src/openvpn/socket.c +++ b/src/openvpn/socket.c @@ -2242,7 +2242,7 @@ } else { - dco_p2p_new_peer(c->c1.tuntap->hand, sock, sig_info); + dco_p2p_new_peer(c->c1.tuntap->hand, &c->c1.tuntap->dco_new_peer_ov, sock, sig_info); } sock->sockflags |= SF_DCO_WIN; diff --git a/src/openvpn/tun.h b/src/openvpn/tun.h index b616f5d..bcc23b4 100644 --- a/src/openvpn/tun.h +++ b/src/openvpn/tun.h @@ -215,6 +215,7 @@ #ifdef _WIN32 HANDLE hand; + OVERLAPPED dco_new_peer_ov; /* used for async NEW_PEER dco call, which might wait for TCP connect */ struct overlapped_io reads; struct overlapped_io writes; struct rw_handle rw_handle;