-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Move exec syscall filtering to NativeAccess #108970
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
8d4a458
Move exec syscall filtering to NativeAccess
rjernst d648156
use var handle without offset
rjernst ffc033f
address feedback
rjernst 607ea10
spotless
rjernst 59c16d0
Merge branch 'main' into native/exec_sandbox
rjernst 1ce8edc
try syncing job object struct explicitly
rjernst bf5cfb4
Merge branch 'main' into native/exec_sandbox
rjernst 082c71a
fix windows to set exec sandbox state
rjernst 4b48c16
Merge branch 'main' into native/exec_sandbox
rjernst 9a3e867
Merge branch 'main' into native/exec_sandbox
rjernst 75b9cbd
add debug for existing path in bwc test
rjernst ccbbe68
more debugging, who is opening the node lock?
rjernst 1db6ca4
more debug
rjernst 5cbd971
try to wait for cluster to be ready before moving versions
rjernst b5fbb11
Merge branch 'main' into native/exec_sandbox
rjernst d7cee93
another try
rjernst 45e8a3b
Merge branch 'main' into native/exec_sandbox
rjernst b18e03e
Merge branch 'main' into native/exec_sandbox
rjernst 21e13cd
Merge branch 'main' into native/exec_sandbox
rjernst 18adbd5
Merge branch 'main' into native/exec_sandbox
rjernst 12e2fae
Merge branch 'main' into native/exec_sandbox
rjernst b773880
Merge branch 'main' into native/exec_sandbox
rjernst d5e8578
Merge branch 'main' into native/exec_sandbox
rjernst b234bda
Merge branch 'main' into native/exec_sandbox
rjernst 2762c19
remove debugging
rjernst 8797e23
spotless
rjernst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
libs/native/jna/src/main/java/org/elasticsearch/nativeaccess/jna/JnaLinuxCLibrary.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| package org.elasticsearch.nativeaccess.jna; | ||
|
|
||
| import com.sun.jna.Library; | ||
| import com.sun.jna.Memory; | ||
| import com.sun.jna.Native; | ||
| import com.sun.jna.NativeLong; | ||
| import com.sun.jna.Pointer; | ||
| import com.sun.jna.Structure; | ||
|
|
||
| import org.elasticsearch.nativeaccess.lib.LinuxCLibrary; | ||
|
|
||
| import java.nio.ByteBuffer; | ||
| import java.nio.ByteOrder; | ||
|
|
||
| class JnaLinuxCLibrary implements LinuxCLibrary { | ||
|
|
||
| @Structure.FieldOrder({ "len", "filter" }) | ||
| public static final class JnaSockFProg extends Structure implements Structure.ByReference, SockFProg { | ||
| public short len; // number of filters | ||
| public Pointer filter; // filters | ||
|
|
||
| JnaSockFProg(SockFilter filters[]) { | ||
| len = (short) filters.length; | ||
| // serialize struct sock_filter * explicitly, its less confusing than the JNA magic we would need | ||
| Memory filter = new Memory(len * 8); | ||
| ByteBuffer bbuf = filter.getByteBuffer(0, len * 8); | ||
| bbuf.order(ByteOrder.nativeOrder()); // little endian | ||
| for (SockFilter f : filters) { | ||
| bbuf.putShort(f.code()); | ||
| bbuf.put(f.jt()); | ||
| bbuf.put(f.jf()); | ||
| bbuf.putInt(f.k()); | ||
| } | ||
| this.filter = filter; | ||
| } | ||
|
|
||
| @Override | ||
| public long address() { | ||
| return Pointer.nativeValue(getPointer()); | ||
| } | ||
| } | ||
|
|
||
| private interface NativeFunctions extends Library { | ||
|
|
||
| /** | ||
| * maps to prctl(2) | ||
| */ | ||
| int prctl(int option, NativeLong arg2, NativeLong arg3, NativeLong arg4, NativeLong arg5); | ||
|
|
||
| /** | ||
| * used to call seccomp(2), its too new... | ||
| * this is the only way, DON'T use it on some other architecture unless you know wtf you are doing | ||
| */ | ||
| NativeLong syscall(NativeLong number, Object... args); | ||
| } | ||
|
|
||
| private final NativeFunctions functions; | ||
|
|
||
| JnaLinuxCLibrary() { | ||
| try { | ||
| this.functions = Native.load("c", NativeFunctions.class); | ||
| } catch (UnsatisfiedLinkError e) { | ||
| throw new UnsupportedOperationException( | ||
| "seccomp unavailable: could not link methods. requires kernel 3.5+ " | ||
| + "with CONFIG_SECCOMP and CONFIG_SECCOMP_FILTER compiled in" | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public SockFProg newSockFProg(SockFilter[] filters) { | ||
| var prog = new JnaSockFProg(filters); | ||
| prog.write(); | ||
| return prog; | ||
| } | ||
|
|
||
| @Override | ||
| public int prctl(int option, long arg2, long arg3, long arg4, long arg5) { | ||
| return functions.prctl(option, new NativeLong(arg2), new NativeLong(arg3), new NativeLong(arg4), new NativeLong(arg5)); | ||
| } | ||
|
|
||
| @Override | ||
| public long syscall(long number, int operation, int flags, long address) { | ||
| return functions.syscall(new NativeLong(number), operation, flags, address).longValue(); | ||
| } | ||
| } |
59 changes: 59 additions & 0 deletions
59
libs/native/jna/src/main/java/org/elasticsearch/nativeaccess/jna/JnaMacCLibrary.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| package org.elasticsearch.nativeaccess.jna; | ||
|
|
||
| import com.sun.jna.Library; | ||
| import com.sun.jna.Native; | ||
| import com.sun.jna.Pointer; | ||
| import com.sun.jna.ptr.PointerByReference; | ||
|
|
||
| import org.elasticsearch.nativeaccess.lib.MacCLibrary; | ||
|
|
||
| class JnaMacCLibrary implements MacCLibrary { | ||
| static class JnaErrorReference implements ErrorReference { | ||
| final PointerByReference ref = new PointerByReference(); | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return ref.getValue().getString(0); | ||
| } | ||
| } | ||
|
|
||
| private interface NativeFunctions extends Library { | ||
| int sandbox_init(String profile, long flags, PointerByReference errorbuf); | ||
|
|
||
| void sandbox_free_error(Pointer errorbuf); | ||
| } | ||
|
|
||
| private final NativeFunctions functions; | ||
|
|
||
| JnaMacCLibrary() { | ||
| this.functions = Native.load("c", NativeFunctions.class); | ||
| } | ||
|
|
||
| @Override | ||
| public ErrorReference newErrorReference() { | ||
| return new JnaErrorReference(); | ||
| } | ||
|
|
||
| @Override | ||
| public int sandbox_init(String profile, long flags, ErrorReference errorbuf) { | ||
| assert errorbuf instanceof JnaErrorReference; | ||
| var jnaErrorbuf = (JnaErrorReference) errorbuf; | ||
| return functions.sandbox_init(profile, flags, jnaErrorbuf.ref); | ||
| } | ||
|
|
||
| @Override | ||
| public void sandbox_free_error(ErrorReference errorbuf) { | ||
| assert errorbuf instanceof JnaErrorReference; | ||
| var jnaErrorbuf = (JnaErrorReference) errorbuf; | ||
| functions.sandbox_free_error(jnaErrorbuf.ref.getValue()); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the corresponding classes/functions in
org/elasticsearch/bootstrap/JNAKernel32Library.javacan be cleaned up too (e.g. class JOBOBJECT_BASIC_LIMIT_INFORMATION)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh good catch, that entire class can be removed.