From patchwork Sun Feb 24 07:12:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Rozman X-Patchwork-Id: 690 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director11.mail.ord1d.rsapps.net ([172.30.191.6]) by backend30.mail.ord1d.rsapps.net with LMTP id GKI8Iv7eclwNMwAAIUCqbw for ; Sun, 24 Feb 2019 13:14:22 -0500 Received: from proxy12.mail.ord1d.rsapps.net ([172.30.191.6]) by director11.mail.ord1d.rsapps.net with LMTP id cFkjIv7eclwFUgAAvGGmqA ; Sun, 24 Feb 2019 13:14:22 -0500 Received: from smtp39.gate.ord1d ([172.30.191.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy12.mail.ord1d.rsapps.net with LMTP id QEOrIf7eclwdLAAA7PHxkg ; Sun, 24 Feb 2019 13:14:22 -0500 X-Spam-Threshold: 95 X-Spam-Score: 0 X-Spam-Flag: NO X-Virus-Scanned: OK X-Orig-To: openvpnslackdevel@openvpn.net X-Originating-Ip: [216.105.38.7] Authentication-Results: smtp39.gate.ord1d.rsapps.net; iprev=pass policy.iprev="216.105.38.7"; spf=pass smtp.mailfrom="openvpn-devel-bounces@lists.sourceforge.net" smtp.helo="lists.sourceforge.net"; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dkim=fail (signature verification failed) header.d=rozman.si; dmarc=fail (p=none; dis=none) header.from=rozman.si X-Suspicious-Flag: YES X-Classification-ID: 01ccde66-3860-11e9-af1c-525400a97bbc-1-1 Received: from [216.105.38.7] ([216.105.38.7:64053] helo=lists.sourceforge.net) by smtp39.gate.ord1d.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id A6/D4-06375-DFED27C5; Sun, 24 Feb 2019 13:14:21 -0500 Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1gxyHI-0002Up-4d; Sun, 24 Feb 2019 18:13:28 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1gxyHF-0002Uc-Ot for openvpn-devel@lists.sourceforge.net; Sun, 24 Feb 2019 18:13:25 +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:Cc:To:From:Sender:Reply-To: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=bNuA2gssGqR9Qdy5hdjzFU61Xq9wuGyNaYFPjVYPM90=; b=BehssAth+MJ1RBsFIgo47ZPC/B MzQQ7OccNy6afelh3Eok90UZceeArJc8WRJrfiSquSZ7y39GFebR4uWbbDOvy4evLtQ4M3cEbklU8 5dMTer/aanuFoBCUOCOkWIQfi94L2LKSI435JTja/IUAgOQytKxedqy9uhHCErNQrXBQ=; 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:Cc:To:From:Sender:Reply-To: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=bNuA2gssGqR9Qdy5hdjzFU61Xq9wuGyNaYFPjVYPM90=; b=ahU/r0GBKveNONKmyX3odJcFH1 abXsUMY+OcImOwNdVQh2XZgJ92zTS75m13pokPwIpZEKVuw8297PKMxUwMHk8SPeKYirH/rLjVuZk dLtCfR69CYcih5fTLIisCJdpjBWcbKw/84lXNmnZZC+XfzAGZU/tFr66yQ0rL7oDJbvI=; Received: from pub5.amebis.si ([213.250.55.21]) by sfi-mx-3.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) id 1gxyHB-00D3cD-5t for openvpn-devel@lists.sourceforge.net; Sun, 24 Feb 2019 18:13:25 +0000 Received: by pub5.amebis.si (Postfix, from userid 115) id F171720E21; Sun, 24 Feb 2019 19:13:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=rozman.si; s=default; t=1551031990; bh=+HToIXHFa0h1AJzCZpK01px5MJuvbBQknH5Ch0qroBI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=foYpj4kaeNf67HKzzY36xSvdu5sSknV8//ME+n7yS2xEdjhGiW4Mte3bSg/Ht4MSF C6/DUPeWjqFQxkpxyJTxnRHyLGfcrc8vebtCeXikEvBqRCuGnii/msf+4avcUDUcXf edCX6zXiMAcOaitz2OKUJgmXnYq1NdwNP30eQmI8= X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on brana.amebis.doma X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,RDNS_NONE autolearn=no autolearn_force=no version=3.4.2 Received: from gw0.selo.doma (unknown [IPv6:2a00:ee2:1206:8101::1]) by pub5.amebis.si (Postfix) with ESMTPS id B313720522; Sun, 24 Feb 2019 19:13:09 +0100 (CET) Received: from s0.selo.doma (s0.selo.doma [IPv6:2a00:ee2:1206:8101::d]) by gw0.selo.doma (Postfix) with ESMTP id 4F99421B982A; Sun, 24 Feb 2019 19:13:09 +0100 (CET) From: Simon Rozman To: openvpn-devel@lists.sourceforge.net Date: Sun, 24 Feb 2019 19:12:52 +0100 Message-Id: <20190224181252.43996-1-simon@rozman.si> X-Mailer: git-send-email 2.19.0.windows.1 In-Reply-To: <20190117155829.GA92142@greenie.muc.de> References: <20190117155829.GA92142@greenie.muc.de> MIME-Version: 1.0 X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 0.0 URIBL_BLOCKED ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [URIs: rozman.si] -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-Headers-End: 1gxyHB-00D3cD-5t Subject: [Openvpn-devel] [PATCH] Disambiguate thread local storage references from TLS 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 Since OpenVPN is security software, "TLS" usually stands for Transport Layer Security. Furthermore, repetitive copy&paste code was refactored using a macro. This patch follows Gert's recommendations from [openvpn-devel]. Signed-off-by: Simon Rozman Message-ID: <20190117155829.GA92142@greenie.muc.de> Acked-by: Gert Doering --- src/openvpnmsica/dllmain.c | 30 +++++++++++++++--------------- src/openvpnmsica/openvpnmsica.c | 20 +++++--------------- src/openvpnmsica/openvpnmsica.h | 18 ++++++++++++++---- 3 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/openvpnmsica/dllmain.c b/src/openvpnmsica/dllmain.c index 50231e4c..5f5092a0 100644 --- a/src/openvpnmsica/dllmain.c +++ b/src/openvpnmsica/dllmain.c @@ -36,7 +36,7 @@ #include -DWORD openvpnmsica_tlsidx_session = TLS_OUT_OF_INDEXES; +DWORD openvpnmsica_thread_data_idx = TLS_OUT_OF_INDEXES; /** @@ -54,9 +54,9 @@ DllMain( switch (dwReason) { case DLL_PROCESS_ATTACH: - /* Allocate TLS index. */ - openvpnmsica_tlsidx_session = TlsAlloc(); - if (openvpnmsica_tlsidx_session == TLS_OUT_OF_INDEXES) + /* Allocate thread local storage index. */ + openvpnmsica_thread_data_idx = TlsAlloc(); + if (openvpnmsica_thread_data_idx == TLS_OUT_OF_INDEXES) { return FALSE; } @@ -64,25 +64,25 @@ DllMain( case DLL_THREAD_ATTACH: { - /* Create TLS data. */ - struct openvpnmsica_tls_data *s = (struct openvpnmsica_tls_data *)malloc(sizeof(struct openvpnmsica_tls_data)); - memset(s, 0, sizeof(struct openvpnmsica_tls_data)); - TlsSetValue(openvpnmsica_tlsidx_session, s); + /* Create thread local storage data. */ + struct openvpnmsica_thread_data *s = (struct openvpnmsica_thread_data *)malloc(sizeof(struct openvpnmsica_thread_data)); + memset(s, 0, sizeof(struct openvpnmsica_thread_data)); + TlsSetValue(openvpnmsica_thread_data_idx, s); break; } case DLL_PROCESS_DETACH: - if (openvpnmsica_tlsidx_session != TLS_OUT_OF_INDEXES) + if (openvpnmsica_thread_data_idx != TLS_OUT_OF_INDEXES) { - /* Free TLS data and TLS index. */ - free(TlsGetValue(openvpnmsica_tlsidx_session)); - TlsFree(openvpnmsica_tlsidx_session); + /* Free thread local storage data and index. */ + free(TlsGetValue(openvpnmsica_thread_data_idx)); + TlsFree(openvpnmsica_thread_data_idx); } break; case DLL_THREAD_DETACH: - /* Free TLS data. */ - free(TlsGetValue(openvpnmsica_tlsidx_session)); + /* Free thread local storage data. */ + free(TlsGetValue(openvpnmsica_thread_data_idx)); break; } @@ -105,7 +105,7 @@ x_msg_va(const unsigned int flags, const char *format, va_list arglist) /* Secure last error before it is overridden. */ DWORD dwResult = (flags & M_ERRNO) != 0 ? GetLastError() : ERROR_SUCCESS; - struct openvpnmsica_tls_data *s = (struct openvpnmsica_tls_data *)TlsGetValue(openvpnmsica_tlsidx_session); + struct openvpnmsica_thread_data *s = (struct openvpnmsica_thread_data *)TlsGetValue(openvpnmsica_thread_data_idx); if (s->hInstall == 0) { /* No MSI session, no fun. */ diff --git a/src/openvpnmsica/openvpnmsica.c b/src/openvpnmsica/openvpnmsica.c index 3232a47c..b8108b99 100644 --- a/src/openvpnmsica/openvpnmsica.c +++ b/src/openvpnmsica/openvpnmsica.c @@ -435,9 +435,7 @@ FindSystemInfo(_In_ MSIHANDLE hInstall) BOOL bIsCoInitialized = SUCCEEDED(CoInitialize(NULL)); - /* Set MSI session handle in TLS. */ - struct openvpnmsica_tls_data *s = (struct openvpnmsica_tls_data *)TlsGetValue(openvpnmsica_tlsidx_session); - s->hInstall = hInstall; + OPENVPNMSICA_SAVE_MSI_SESSION(hInstall); openvpnmsica_set_driver_certification(hInstall); openvpnmsica_set_openvpnserv_state(hInstall); @@ -462,9 +460,7 @@ FindTAPInterfaces(_In_ MSIHANDLE hInstall) UINT uiResult; BOOL bIsCoInitialized = SUCCEEDED(CoInitialize(NULL)); - /* Set MSI session handle in TLS. */ - struct openvpnmsica_tls_data *s = (struct openvpnmsica_tls_data *)TlsGetValue(openvpnmsica_tlsidx_session); - s->hInstall = hInstall; + OPENVPNMSICA_SAVE_MSI_SESSION(hInstall); /* Get available network interfaces. */ struct tap_interface_node *pInterfaceList = NULL; @@ -677,9 +673,7 @@ StartOpenVPNGUI(_In_ MSIHANDLE hInstall) UINT uiResult; BOOL bIsCoInitialized = SUCCEEDED(CoInitialize(NULL)); - /* Set MSI session handle in TLS. */ - struct openvpnmsica_tls_data *s = (struct openvpnmsica_tls_data *)TlsGetValue(openvpnmsica_tlsidx_session); - s->hInstall = hInstall; + OPENVPNMSICA_SAVE_MSI_SESSION(hInstall); /* Create and populate a MSI record. */ MSIHANDLE hRecord = MsiCreateRecord(1); @@ -759,9 +753,7 @@ EvaluateTAPInterfaces(_In_ MSIHANDLE hInstall) UINT uiResult; BOOL bIsCoInitialized = SUCCEEDED(CoInitialize(NULL)); - /* Set MSI session handle in TLS. */ - struct openvpnmsica_tls_data *s = (struct openvpnmsica_tls_data *)TlsGetValue(openvpnmsica_tlsidx_session); - s->hInstall = hInstall; + OPENVPNMSICA_SAVE_MSI_SESSION(hInstall); /* List of deferred custom actions EvaluateTAPInterfaces prepares operation sequence for. */ static const LPCTSTR szActionNames[] = @@ -1052,9 +1044,7 @@ ProcessDeferredAction(_In_ MSIHANDLE hInstall) UINT uiResult; BOOL bIsCoInitialized = SUCCEEDED(CoInitialize(NULL)); - /* Set MSI session handle in TLS. */ - struct openvpnmsica_tls_data *s = (struct openvpnmsica_tls_data *)TlsGetValue(openvpnmsica_tlsidx_session); - s->hInstall = hInstall; + OPENVPNMSICA_SAVE_MSI_SESSION(hInstall); BOOL bIsCleanup = MsiGetMode(hInstall, MSIRUNMODE_COMMIT) || MsiGetMode(hInstall, MSIRUNMODE_ROLLBACK); diff --git a/src/openvpnmsica/openvpnmsica.h b/src/openvpnmsica/openvpnmsica.h index 382064b6..d6a09127 100644 --- a/src/openvpnmsica/openvpnmsica.h +++ b/src/openvpnmsica/openvpnmsica.h @@ -33,18 +33,28 @@ /** - * TLS data + * Thread local storage data */ -struct openvpnmsica_tls_data +struct openvpnmsica_thread_data { MSIHANDLE hInstall; /** Handle to the installation session. */ }; /** - * MSI session handle TLS index + * MSI session handle thread local storage index */ -extern DWORD openvpnmsica_tlsidx_session; +extern DWORD openvpnmsica_thread_data_idx; + + +/** + * Set MSI session handle in thread local storage. + */ +#define OPENVPNMSICA_SAVE_MSI_SESSION(hInstall) \ +{ \ + struct openvpnmsica_thread_data *s = (struct openvpnmsica_thread_data *)TlsGetValue(openvpnmsica_thread_data_idx); \ + s->hInstall = (hInstall); \ +} /*