Skip to content

Commit 6936bfd

Browse files
markovamariardementi
authored andcommitted
Harden DLL loading, enable SSL for pcm-sensor-server on Windows CI
Security: - Add SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_SYSTEM32) to PCM_SET_DLL_DIR macro in utils.h to prevent DLL planting attacks (CWE-427) - Update WINDOWS_HOWTO.md with DLL planting prevention guidance SSL enablement: - Set OPENSSL_ROOT_DIR and pass LIB_EAY_RELEASE/SSL_EAY_RELEASE to CMake so FindOpenSSL locates the static libraries in lib/VC/x64/MT/ - Remove premature include(FindOpenSSL) from src/CMakeLists.txt - Link crypt32 and ws2_32 on MSVC for static OpenSSL dependencies
1 parent 41faa0b commit 6936bfd

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

.github/workflows/ci-windows.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88

99
env:
1010
BUILD_TYPE: Release
11+
OPENSSL_ROOT_DIR: "C:\\Program Files\\OpenSSL-Win64"
1112

1213
permissions:
1314
contents: read
@@ -30,7 +31,11 @@ jobs:
3031
- name: Configure CMake
3132
run: |
3233
if (Test-Path ${{github.workspace}}\build){ Remove-Item ${{github.workspace}}\build -Recurse }
33-
cmake -B ${{github.workspace}}\build
34+
$cryptoLib = "$env:OPENSSL_ROOT_DIR\lib\VC\x64\MT\libcrypto_static.lib"
35+
$sslLib = "$env:OPENSSL_ROOT_DIR\lib\VC\x64\MT\libssl_static.lib"
36+
cmake -B ${{github.workspace}}\build `
37+
-DLIB_EAY_RELEASE:FILEPATH="$cryptoLib" `
38+
-DSSL_EAY_RELEASE:FILEPATH="$sslLib"
3439
- name: Build
3540
run: |
3641
cmake --build ${{github.workspace}}\build --config ${{env.BUILD_TYPE}} --parallel

doc/WINDOWS_HOWTO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ Starting from this release, **pcm-sensor-server** is now supported on Windows. T
122122
123123
### Running pcm-sensor-server on Windows
124124
125-
1. Choose or create a directory for PCM (e.g., `C:\Program Files\PCM\` or `C:\Program Files (x86)\PCM\`). Copy `msr.sys` and `pcm-sensor-server.exe` to this directory.
125+
1. Create a directory for PCM in a protected location (e.g., `C:\Program Files\PCM\` or `C:\Program Files (x86)\PCM\`). Copy `msr.sys` and `pcm-sensor-server.exe` to this directory. **Important:** Do not place PCM binaries in user-writable directories (e.g., Downloads, Desktop, `C:\Users\Public\`) to prevent DLL planting attacks.
126126
127127
2. Run as Administrator (required for MSR access):
128128
```

src/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# SPDX-License-Identifier: BSD-3-Clause
22
# Copyright (c) 2022-2025, Intel Corporation
33

4-
include(FindOpenSSL)
5-
64
# All pcm-* executables
75
set(PROJECT_NAMES pcm pcm-numa pcm-latency pcm-power pcm-msr pcm-memory pcm-tsx pcm-pcie pcm-core pcm-iio pcm-pcicfg pcm-mmio pcm-tpmi pcm-raw pcm-accel pcm-sensor-server)
86

@@ -220,6 +218,10 @@ if(PCM_BUILD_EXECUTABLES)
220218
message(STATUS "OpenSSL version ${OPENSSL_VERSION} >= ${MINIMUM_OPENSSL_VERSION}, OpenSSL support enabled")
221219
target_compile_options(${PROJECT_NAME} PRIVATE "-DUSE_SSL")
222220
set(LIBS ${LIBS} OpenSSL::SSL OpenSSL::Crypto)
221+
if(MSVC)
222+
# Static OpenSSL on Windows depends on these system libraries
223+
set(LIBS ${LIBS} crypt32 ws2_32)
224+
endif()
223225
else()
224226
message(STATUS "OpenSSL support has been disabled, the version is less than ${MINIMUM_OPENSSL_VERSION}")
225227
endif()

src/utils.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ namespace pcm {
8787
}
8888

8989
#ifdef _MSC_VER
90-
#define PCM_SET_DLL_DIR SetDllDirectory(_T(""));
90+
// Security hardening: remove the current working directory from the DLL search
91+
// order to prevent DLL planting attacks (CWE-427). This ensures DLLs are only
92+
// loaded from trusted system directories.
93+
#define PCM_SET_DLL_DIR SetDllDirectory(_T("")); SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_SYSTEM32);
9194
#else
9295
#define PCM_SET_DLL_DIR
9396
#endif

0 commit comments

Comments
 (0)