Skip to content

Commit 69bd402

Browse files
committed
Merged PR 11480212: Update store APIs to also update HKLM (#3660) (#3853)
Update store APIs to also update HKLM (#3660) (#3853) Cherry-picked from commit `462b8e3c`. ---- #### AI description (iteration 1) #### PR Classification API change to update store APIs to also update HKLM. #### PR Summary This pull request updates the store APIs to handle both HKCU and HKLM registry keys, ensuring that operations are attempted on both keys and errors are suppressed if access to HKLM is denied. - `ebpf_store_helper.c`: Added functions to update and delete program and section information for both HKCU and HKLM. - `store_helper_internal.cpp`: Modified functions to handle both HKCU and HKLM registry keys. - `Product.wxs`: Updated installer scripts to clear and set up eBPF store for both HKCU and HKLM. - `ebpf_store_helper.h` and `ebpf_registry_helper.cpp`: Introduced separate variables for HKCU and HKLM root keys.
1 parent ae6fb79 commit 69bd402

File tree

5 files changed

+190
-33
lines changed

5 files changed

+190
-33
lines changed

include/ebpf_store_helper.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ extern "C"
1616

1717
typedef HKEY ebpf_store_key_t;
1818

19-
extern ebpf_store_key_t ebpf_store_root_key;
19+
extern ebpf_store_key_t ebpf_store_hkcu_root_key;
20+
extern ebpf_store_key_t ebpf_store_hklm_root_key;
2021
extern const wchar_t* ebpf_store_root_sub_key;
2122

2223
/**

installer/Product.wxs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,17 @@ SPDX-License-Identifier: MIT
5757
<Custom Action="NetEbpfExt_Driver_uninstall_rollback" Before="NetEbpfExt_Driver_install">NOT Installed</Custom>
5858

5959
<!--Install sequence-->
60-
<Custom Action="Clear_eBPF_store" After="InstallFiles">NOT Installed</Custom>
61-
<Custom Action="Setup_eBPF_store" After="Clear_eBPF_store">NOT Installed</Custom>
60+
<Custom Action="Clear_eBPF_store_HKLM" After="InstallFiles">NOT Installed</Custom>
61+
<Custom Action="Setup_eBPF_store_HKLM" After="Clear_eBPF_store_HKLM">NOT Installed</Custom>
62+
<Custom Action="Clear_eBPF_store_HKCU" After="Setup_eBPF_store_HKLM">NOT Installed</Custom>
63+
<Custom Action="Setup_eBPF_store_HKCU" After="Clear_eBPF_store_HKCU">NOT Installed</Custom>
6264

63-
<Custom Action="eBPF_netsh_helper_install" After="Setup_eBPF_store">NOT Installed</Custom>
65+
<Custom Action="eBPF_netsh_helper_install" After="Setup_eBPF_store_HKCU">NOT Installed</Custom>
6466

65-
<Custom Action="eBPFCore_Driver_install" After="Setup_eBPF_store">NOT Installed</Custom>
67+
<Custom Action="eBPFCore_Driver_install" After="Setup_eBPF_store_HKCU">NOT Installed</Custom>
6668
<Custom Action="eBPFCore_Driver_start" After="eBPFCore_Driver_install">NOT Installed</Custom>
6769

68-
<Custom Action="NetEbpfExt_Driver_install" After="Setup_eBPF_store">NOT Installed</Custom>
70+
<Custom Action="NetEbpfExt_Driver_install" After="Setup_eBPF_store_HKCU">NOT Installed</Custom>
6971
<Custom Action="NetEbpfExt_Driver_start" After="NetEbpfExt_Driver_install">NOT Installed</Custom>
7072

7173
<!--Uninstall sequence-->
@@ -77,7 +79,8 @@ SPDX-License-Identifier: MIT
7779
<Custom Action="NetEbpfExt_Driver_stop" After="InstallInitialize">REMOVE="ALL"</Custom>
7880
<Custom Action="NetEbpfExt_Driver_uninstall" After="NetEbpfExt_Driver_stop">REMOVE="ALL"</Custom>
7981

80-
<Custom Action="Clear_eBPF_store_uninstall" After="NetEbpfExt_Driver_uninstall">REMOVE="ALL"</Custom>
82+
<Custom Action="Clear_eBPF_store_uninstall_HKLM" After="NetEbpfExt_Driver_uninstall">REMOVE="ALL"</Custom>
83+
<Custom Action="Clear_eBPF_store_uninstall_HKCU" After="Clear_eBPF_store_uninstall_HKLM">REMOVE="ALL"</Custom>
8184
<Custom Action="eBPFCore_Driver_uninstall_flush" After="InstallFinalize">REMOVE="ALL"</Custom>
8285
</InstallExecuteSequence>
8386

@@ -192,10 +195,14 @@ SPDX-License-Identifier: MIT
192195
</ComponentGroup>
193196

194197
<!--Clear/Setup the eBPF store-->
195-
<CustomAction Id="Clear_eBPF_store" ExeCommand='"[#EXPORT_PROGRAM_INFO.EXE]" --clear' Directory="INSTALLFOLDER" Execute="deferred" Return="check" Impersonate="yes"/>
196-
<CustomAction Id="Clear_eBPF_store_uninstall" ExeCommand='"[#EXPORT_PROGRAM_INFO.EXE]" --clear' Directory="INSTALLFOLDER" Execute="deferred" Return="ignore" Impersonate="yes"/>
197-
<SetProperty Id="Setup_eBPF_store" Value='"[#EXPORT_PROGRAM_INFO.EXE]"' Before="Setup_eBPF_store" Sequence="execute"/>
198-
<CustomAction Id="Setup_eBPF_store" BinaryKey="WixCA" DllEntry="WixQuietExec64" Execute="deferred" Return="check" Impersonate="yes"/>
198+
<CustomAction Id="Clear_eBPF_store_HKLM" ExeCommand='"[#EXPORT_PROGRAM_INFO.EXE]" --clear' Directory="INSTALLFOLDER" Execute="deferred" Return="check" Impersonate="no"/>
199+
<CustomAction Id="Clear_eBPF_store_HKCU" ExeCommand='"[#EXPORT_PROGRAM_INFO.EXE]" --clear' Directory="INSTALLFOLDER" Execute="deferred" Return="check" Impersonate="yes"/>
200+
<CustomAction Id="Clear_eBPF_store_uninstall_HKLM" ExeCommand='"[#EXPORT_PROGRAM_INFO.EXE]" --clear' Directory="INSTALLFOLDER" Execute="deferred" Return="ignore" Impersonate="no"/>
201+
<CustomAction Id="Clear_eBPF_store_uninstall_HKCU" ExeCommand='"[#EXPORT_PROGRAM_INFO.EXE]" --clear' Directory="INSTALLFOLDER" Execute="deferred" Return="ignore" Impersonate="yes"/>
202+
<SetProperty Id="Setup_eBPF_store_HKLM" Value='"[#EXPORT_PROGRAM_INFO.EXE]"' Before="Setup_eBPF_store_HKLM" Sequence="execute"/>
203+
<CustomAction Id="Setup_eBPF_store_HKLM" BinaryKey="WixCA" DllEntry="WixQuietExec64" Execute="deferred" Return="check" Impersonate="no"/>
204+
<SetProperty Id="Setup_eBPF_store_HKCU" Value='"[#EXPORT_PROGRAM_INFO.EXE]"' Before="Setup_eBPF_store_HKCU" Sequence="execute"/>
205+
<CustomAction Id="Setup_eBPF_store_HKCU" BinaryKey="WixCA" DllEntry="WixQuietExec64" Execute="deferred" Return="check" Impersonate="yes"/>
199206

200207
<!--Install/Uninstall the netsh helper-->
201208
<!--qtexec does not currently support a working directory (ref. https://github.com/wixtoolset/issues/issues/1265)-->

libs/api_common/store_helper_internal.cpp

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "utilities.hpp"
1313

1414
ebpf_store_key_t root_registry_key_current_user = HKEY_CURRENT_USER;
15+
ebpf_store_key_t root_registry_key_local_machine = HKEY_LOCAL_MACHINE;
1516

1617
static ebpf_result_t
1718
_open_ebpf_store_key(_Out_ ebpf_store_key_t* store_key)
@@ -21,9 +22,18 @@ _open_ebpf_store_key(_Out_ ebpf_store_key_t* store_key)
2122
// Open root registry path.
2223
*store_key = nullptr;
2324

24-
// Open the HKCU registry key.
25+
// First try to open the HKCU registry key.
2526
ebpf_result_t result =
2627
ebpf_open_registry_key(root_registry_key_current_user, EBPF_STORE_REGISTRY_PATH, KEY_READ, store_key);
28+
if (result != ERROR_SUCCESS) {
29+
// Failed to open ebpf store path in HKCU. Fall back to HKLM.
30+
EBPF_LOG_MESSAGE_UINT64(
31+
EBPF_TRACELOG_LEVEL_WARNING,
32+
EBPF_TRACELOG_KEYWORD_BASE,
33+
"_open_ebpf_store_key: Failed to open HKCU registry key. Falling back to HKLM. Error:",
34+
result);
35+
result = ebpf_open_registry_key(root_registry_key_local_machine, EBPF_STORE_REGISTRY_PATH, KEY_READ, store_key);
36+
}
2737

2838
EBPF_RETURN_RESULT(result);
2939
}
@@ -886,8 +896,9 @@ ebpf_store_clear(_In_ const ebpf_store_key_t root_key_path)
886896
EBPF_RETURN_RESULT(result);
887897
}
888898

889-
ebpf_result_t
890-
ebpf_store_delete_global_helper_information(_In_ ebpf_helper_function_prototype_t* helper_info)
899+
static ebpf_result_t
900+
_ebpf_store_delete_global_helper_information(
901+
ebpf_store_key_t root_store_key, _In_ ebpf_helper_function_prototype_t* helper_info)
891902
{
892903
ebpf_result_t result = EBPF_SUCCESS;
893904
ebpf_store_key_t root_key = NULL;
@@ -903,7 +914,7 @@ ebpf_store_delete_global_helper_information(_In_ ebpf_helper_function_prototype_
903914
}
904915

905916
// Open root registry key.
906-
result = ebpf_open_registry_key(ebpf_store_root_key, EBPF_ROOT_RELATIVE_PATH, REG_CREATE_FLAGS, &root_key);
917+
result = ebpf_open_registry_key(root_store_key, EBPF_ROOT_RELATIVE_PATH, REG_CREATE_FLAGS, &root_key);
907918
if (result != EBPF_SUCCESS) {
908919
if (result == EBPF_FILE_NOT_FOUND) {
909920
result = EBPF_SUCCESS;
@@ -941,3 +952,27 @@ ebpf_store_delete_global_helper_information(_In_ ebpf_helper_function_prototype_
941952

942953
EBPF_RETURN_RESULT(result);
943954
}
955+
956+
ebpf_result_t
957+
ebpf_store_delete_global_helper_information(_In_ ebpf_helper_function_prototype_t* helper_info)
958+
{
959+
ebpf_result_t result = EBPF_SUCCESS;
960+
961+
EBPF_LOG_ENTRY();
962+
963+
// First delete from HKCU root key.
964+
result = _ebpf_store_delete_global_helper_information(root_registry_key_current_user, helper_info);
965+
if (result != EBPF_SUCCESS) {
966+
goto Exit;
967+
}
968+
969+
// Next delete from HKLM root key. It possible that the user does not have permission to the HKLM root key.
970+
// Suppress error in that case.
971+
result = _ebpf_store_delete_global_helper_information(root_registry_key_local_machine, helper_info);
972+
if (result == EBPF_ACCESS_DENIED) {
973+
result = EBPF_SUCCESS;
974+
}
975+
976+
Exit:
977+
EBPF_RETURN_RESULT(result);
978+
}

libs/store_helper/ebpf_store_helper.c

Lines changed: 130 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ _ebpf_store_update_extension_header_information(ebpf_store_key_t key, _In_ const
2222
}
2323

2424
static ebpf_result_t
25-
_ebpf_store_open_or_create_provider_registry_key(_Out_ ebpf_store_key_t* provider_key)
25+
_ebpf_store_open_or_create_provider_registry_key(ebpf_store_key_t root_store_key, _Out_ ebpf_store_key_t* provider_key)
2626
{
2727
ebpf_result_t result = EBPF_SUCCESS;
2828
ebpf_store_key_t root_key = NULL;
2929
*provider_key = NULL;
3030

3131
// Open (or create) root eBPF registry path.
32-
result = ebpf_create_registry_key(ebpf_store_root_key, ebpf_store_root_sub_key, REG_CREATE_FLAGS, &root_key);
32+
result = ebpf_create_registry_key(root_store_key, ebpf_store_root_sub_key, REG_CREATE_FLAGS, &root_key);
3333

3434
if (!IS_SUCCESS(result)) {
3535
goto Exit;
@@ -106,9 +106,11 @@ _ebpf_store_update_helper_prototype(
106106
return result;
107107
}
108108

109-
ebpf_result_t
110-
ebpf_store_update_global_helper_information(
111-
_In_reads_(helper_info_count) ebpf_helper_function_prototype_t* helper_info, uint32_t helper_info_count)
109+
static ebpf_result_t
110+
_ebpf_store_update_global_helper_information(
111+
ebpf_store_key_t root_key,
112+
_In_reads_(helper_info_count) ebpf_helper_function_prototype_t* helper_info,
113+
uint32_t helper_info_count)
112114
{
113115
ebpf_result_t result = EBPF_SUCCESS;
114116
ebpf_store_key_t provider_key = NULL;
@@ -124,7 +126,7 @@ ebpf_store_update_global_helper_information(
124126
}
125127

126128
// Open (or create) provider registry path.
127-
result = _ebpf_store_open_or_create_provider_registry_key(&provider_key);
129+
result = _ebpf_store_open_or_create_provider_registry_key(root_key, &provider_key);
128130
if (!IS_SUCCESS(result)) {
129131
goto Exit;
130132
}
@@ -151,8 +153,31 @@ ebpf_store_update_global_helper_information(
151153
}
152154

153155
ebpf_result_t
154-
ebpf_store_update_section_information(
155-
_In_reads_(section_info_count) const ebpf_program_section_info_t* section_info, uint32_t section_info_count)
156+
ebpf_store_update_global_helper_information(
157+
_In_reads_(helper_info_count) ebpf_helper_function_prototype_t* helper_info, uint32_t helper_info_count)
158+
{
159+
// First update the HKCU root key.
160+
ebpf_result_t result =
161+
_ebpf_store_update_global_helper_information(ebpf_store_hkcu_root_key, helper_info, helper_info_count);
162+
if (!IS_SUCCESS(result)) {
163+
return result;
164+
}
165+
166+
// Next update the HKLM root key. It possible that the user does not have permission to update the HKLM root key.
167+
// Suppress error in that case.
168+
result = _ebpf_store_update_global_helper_information(ebpf_store_hklm_root_key, helper_info, helper_info_count);
169+
if (result == EBPF_ACCESS_DENIED) {
170+
result = EBPF_SUCCESS;
171+
}
172+
173+
return result;
174+
}
175+
176+
static ebpf_result_t
177+
_ebpf_store_update_section_information(
178+
ebpf_store_key_t root_key,
179+
_In_reads_(section_info_count) const ebpf_program_section_info_t* section_info,
180+
uint32_t section_info_count)
156181
{
157182
ebpf_result_t result = EBPF_SUCCESS;
158183
ebpf_store_key_t provider_key = NULL;
@@ -163,7 +188,7 @@ ebpf_store_update_section_information(
163188
}
164189

165190
// Open (or create) provider registry path.
166-
result = _ebpf_store_open_or_create_provider_registry_key(&provider_key);
191+
result = _ebpf_store_open_or_create_provider_registry_key(root_key, &provider_key);
167192
if (!IS_SUCCESS(result)) {
168193
goto Exit;
169194
}
@@ -240,6 +265,28 @@ ebpf_store_update_section_information(
240265
return result;
241266
}
242267

268+
ebpf_result_t
269+
ebpf_store_update_section_information(
270+
_In_reads_(section_info_count) const ebpf_program_section_info_t* section_info, uint32_t section_info_count)
271+
{
272+
ebpf_result_t result = EBPF_SUCCESS;
273+
274+
// First update the HKCU root key.
275+
result = _ebpf_store_update_section_information(ebpf_store_hkcu_root_key, section_info, section_info_count);
276+
if (!IS_SUCCESS(result)) {
277+
return result;
278+
}
279+
280+
// Next update the HKLM root key. It possible that the user does not have permission to update the HKLM root key.
281+
// Suppress error in that case.
282+
result = _ebpf_store_update_section_information(ebpf_store_hklm_root_key, section_info, section_info_count);
283+
if (result == EBPF_ACCESS_DENIED) {
284+
result = EBPF_SUCCESS;
285+
}
286+
287+
return result;
288+
}
289+
243290
static ebpf_result_t
244291
_ebpf_store_update_program_descriptor(
245292
ebpf_store_key_t descriptor_key, _In_ const ebpf_program_type_descriptor_t* program_type_descriptor)
@@ -351,9 +398,11 @@ _ebpf_store_update_program_info(ebpf_store_key_t program_key, _In_ const ebpf_pr
351398
return result;
352399
}
353400

354-
ebpf_result_t
355-
ebpf_store_update_program_information_array(
356-
_In_reads_(program_info_count) const ebpf_program_info_t* program_info, uint32_t program_info_count)
401+
static ebpf_result_t
402+
_ebpf_store_update_program_information_array(
403+
ebpf_store_key_t root_key,
404+
_In_reads_(program_info_count) const ebpf_program_info_t* program_info,
405+
uint32_t program_info_count)
357406
{
358407
ebpf_result_t result = EBPF_SUCCESS;
359408
ebpf_store_key_t provider_key = NULL;
@@ -365,7 +414,7 @@ ebpf_store_update_program_information_array(
365414
}
366415

367416
// Open (or create) provider registry path.
368-
result = _ebpf_store_open_or_create_provider_registry_key(&provider_key);
417+
result = _ebpf_store_open_or_create_provider_registry_key(root_key, &provider_key);
369418
if (!IS_SUCCESS(result)) {
370419
goto Exit;
371420
}
@@ -428,14 +477,36 @@ ebpf_store_update_program_information_array(
428477
}
429478

430479
ebpf_result_t
431-
ebpf_store_delete_program_information(_In_ const ebpf_program_info_t* program_info)
480+
ebpf_store_update_program_information_array(
481+
_In_reads_(program_info_count) const ebpf_program_info_t* program_info, uint32_t program_info_count)
482+
{
483+
ebpf_result_t result = EBPF_SUCCESS;
484+
485+
// First update the HKCU root key.
486+
result = _ebpf_store_update_program_information_array(ebpf_store_hkcu_root_key, program_info, program_info_count);
487+
if (!IS_SUCCESS(result)) {
488+
return result;
489+
}
490+
491+
// Next update the HKLM root key. It possible that the user does not have permission to update the HKLM root key.
492+
// Suppress error in that case.
493+
result = _ebpf_store_update_program_information_array(ebpf_store_hklm_root_key, program_info, program_info_count);
494+
if (result == EBPF_ACCESS_DENIED) {
495+
result = EBPF_SUCCESS;
496+
}
497+
498+
return result;
499+
}
500+
501+
static ebpf_result_t
502+
_ebpf_store_delete_program_information(ebpf_store_key_t root_key, _In_ const ebpf_program_info_t* program_info)
432503
{
433504
ebpf_result_t result = EBPF_SUCCESS;
434505
ebpf_store_key_t provider_key = NULL;
435506
ebpf_store_key_t program_info_key = NULL;
436507

437508
// Open (or create) provider registry path.
438-
result = _ebpf_store_open_or_create_provider_registry_key(&provider_key);
509+
result = _ebpf_store_open_or_create_provider_registry_key(root_key, &provider_key);
439510
if (!IS_SUCCESS(result)) {
440511
goto Exit;
441512
}
@@ -467,14 +538,35 @@ ebpf_store_delete_program_information(_In_ const ebpf_program_info_t* program_in
467538
}
468539

469540
ebpf_result_t
470-
ebpf_store_delete_section_information(_In_ const ebpf_program_section_info_t* section_info)
541+
ebpf_store_delete_program_information(_In_ const ebpf_program_info_t* program_info)
542+
{
543+
ebpf_result_t result = EBPF_SUCCESS;
544+
545+
// First delete from HKCU root key.
546+
result = _ebpf_store_delete_program_information(ebpf_store_hkcu_root_key, program_info);
547+
if (!IS_SUCCESS(result)) {
548+
return result;
549+
}
550+
551+
// Next delete from HKLM root key. It possible that the user does not have permission to delete from the HKLM root
552+
// key. Suppress error in that case.
553+
result = _ebpf_store_delete_program_information(ebpf_store_hklm_root_key, program_info);
554+
if (result == EBPF_ACCESS_DENIED) {
555+
result = EBPF_SUCCESS;
556+
}
557+
558+
return result;
559+
}
560+
561+
static ebpf_result_t
562+
_ebpf_store_delete_section_information(ebpf_store_key_t root_key, _In_ const ebpf_program_section_info_t* section_info)
471563
{
472564
ebpf_result_t result = EBPF_SUCCESS;
473565
ebpf_store_key_t provider_key = NULL;
474566
ebpf_store_key_t section_info_key = NULL;
475567

476568
// Open (or create) provider registry path.
477-
result = _ebpf_store_open_or_create_provider_registry_key(&provider_key);
569+
result = _ebpf_store_open_or_create_provider_registry_key(root_key, &provider_key);
478570
if (!IS_SUCCESS(result)) {
479571
goto Exit;
480572
}
@@ -496,3 +588,24 @@ ebpf_store_delete_section_information(_In_ const ebpf_program_section_info_t* se
496588

497589
return result;
498590
}
591+
592+
ebpf_result_t
593+
ebpf_store_delete_section_information(_In_ const ebpf_program_section_info_t* section_info)
594+
{
595+
ebpf_result_t result = EBPF_SUCCESS;
596+
597+
// First delete from HKCU root key.
598+
result = _ebpf_store_delete_section_information(ebpf_store_hkcu_root_key, section_info);
599+
if (!IS_SUCCESS(result)) {
600+
return result;
601+
}
602+
603+
// Next delete from HKLM root key. It possible that the user does not have permission to delete from the HKLM root
604+
// key. Suppress error in that case.
605+
result = _ebpf_store_delete_section_information(ebpf_store_hklm_root_key, section_info);
606+
if (result == EBPF_ACCESS_DENIED) {
607+
result = EBPF_SUCCESS;
608+
}
609+
610+
return result;
611+
}

libs/store_helper/user/ebpf_registry_helper.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
#define GUID_STRING_LENGTH 38 // not including the null terminator.
1717
#define _EBPF_RESULT(x) win32_error_code_to_ebpf_result(x)
1818

19-
ebpf_store_key_t ebpf_store_root_key = HKEY_CURRENT_USER; // TODO: Issue #1231 Change to using HKEY_LOCAL_MACHINE
19+
ebpf_store_key_t ebpf_store_hkcu_root_key = HKEY_CURRENT_USER;
20+
ebpf_store_key_t ebpf_store_hklm_root_key = HKEY_LOCAL_MACHINE;
2021
const wchar_t* ebpf_store_root_sub_key = EBPF_ROOT_RELATIVE_PATH;
2122

2223
wchar_t*

0 commit comments

Comments
 (0)