Skip to content

Commit eff3060

Browse files
authored
Add file read entitlement check to library load functions (#122494)
1 parent c8836a8 commit eff3060

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

libs/entitlement/qa/entitlement-test-plugin/src/main/java/org/elasticsearch/entitlement/qa/test/LoadNativeLibrariesCheckActions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
class LoadNativeLibrariesCheckActions {
1313
static void runtimeLoad() {
1414
try {
15-
Runtime.getRuntime().load("libSomeLibFile.so");
15+
Runtime.getRuntime().load(FileCheckActions.readDir().resolve("libSomeLibFile.so").toString());
1616
} catch (UnsatisfiedLinkError ignored) {
1717
// The library does not exist, so we expect to fail loading it
1818
}
1919
}
2020

2121
static void systemLoad() {
2222
try {
23-
System.load("libSomeLibFile.so");
23+
System.load(FileCheckActions.readDir().resolve("libSomeLibFile.so").toString());
2424
} catch (UnsatisfiedLinkError ignored) {
2525
// The library does not exist, so we expect to fail loading it
2626
}

libs/entitlement/qa/entitlement-test-plugin/src/main/java/org/elasticsearch/entitlement/qa/test/NativeActions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ static void memorySegmentReinterpretWithSizeAndCleanup() {
113113
@EntitlementTest(expectedAccess = PLUGINS)
114114
static void symbolLookupWithPath() {
115115
try {
116-
SymbolLookup.libraryLookup(Path.of("/foo/bar/libFoo.so"), Arena.ofAuto());
116+
SymbolLookup.libraryLookup(FileCheckActions.readDir().resolve("libFoo.so"), Arena.ofAuto());
117117
} catch (IllegalArgumentException e) {
118118
// IllegalArgumentException is thrown if path does not point to a valid library (and it does not)
119119
}

libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/api/ElasticsearchEntitlementChecker.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ public void checkSelectorProviderInheritedChannel(Class<?> callerClass, Selector
836836

837837
@Override
838838
public void check$java_lang_Runtime$load(Class<?> callerClass, Runtime that, String filename) {
839-
// TODO: check filesystem entitlement READ
839+
policyManager.checkFileRead(callerClass, Path.of(filename));
840840
policyManager.checkLoadingNativeLibraries(callerClass);
841841
}
842842

@@ -847,7 +847,7 @@ public void checkSelectorProviderInheritedChannel(Class<?> callerClass, Selector
847847

848848
@Override
849849
public void check$java_lang_System$$load(Class<?> callerClass, String filename) {
850-
// TODO: check filesystem entitlement READ
850+
policyManager.checkFileRead(callerClass, Path.of(filename));
851851
policyManager.checkLoadingNativeLibraries(callerClass);
852852
}
853853

@@ -931,7 +931,7 @@ public void checkSelectorProviderInheritedChannel(Class<?> callerClass, Selector
931931

932932
@Override
933933
public void check$java_lang_foreign_SymbolLookup$$libraryLookup(Class<?> callerClass, Path path, Arena arena) {
934-
// TODO: check filesystem entitlement READ
934+
policyManager.checkFileRead(callerClass, path);
935935
policyManager.checkLoadingNativeLibraries(callerClass);
936936
}
937937

0 commit comments

Comments
 (0)