Skip to content

Commit 72e615a

Browse files
committed
Add docs on JNA temp directory not being noexec (#35355)
If the underlying mount point for the JNA temporary directory is mounted noexec on Linux, then the JVM will not be able to map the native code in as executable. This will prevent JNA from executing and will prevent Elasticsearch from being able to execute some functions that rely on native code (e.g., memory locking, and installing system call filters). We do not want to get into the business of catching exceptions and parsing messages towards this because these exception messages can change on us. We also do not want to jump through a lot of hoops to check the underlying mount point for noexec. Instead, we will rely on documentation to address this problem. This commit adds to the important system configuration section of the docs that the JNA temporary directory is not on a mount point with the noexec mount option.
1 parent 6bd3f4c commit 72e615a

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

docs/reference/setup/sysconfig.asciidoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The following settings *must* be considered before going to production:
1313
* <<vm-max-map-count,Ensure sufficient virtual memory>>
1414
* <<max-number-of-threads,Ensure sufficient threads>>
1515
* <<networkaddress-cache-ttl,JVM DNS cache settings>>
16+
* <<executable-jna-tmpdir,Temporary directory not mounted with `noexec`>>
1617

1718
[[dev-vs-prod]]
1819
[float]
@@ -40,3 +41,5 @@ include::sysconfig/virtual-memory.asciidoc[]
4041
include::sysconfig/threads.asciidoc[]
4142

4243
include::sysconfig/dns-cache.asciidoc[]
44+
45+
include::sysconfig/executable-jna-tmpdir.asciidoc[]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[[executable-jna-tmpdir]]
2+
=== JNA temporary directory not mounted with `noexec`
3+
4+
[NOTE]
5+
This is only relevant for Linux.
6+
7+
Elasticsearch uses the Java Native Access (JNA) library for executing some
8+
platform-dependent native code. On Linux, the native code backing this library
9+
is extracted at runtime from the JNA archive. By default, this code is extracted
10+
to the Elasticsearch temporary directory which defaults to a sub-directory of
11+
`/tmp`. Alternatively, this location can be controlled with the JVM flag
12+
`-Djna.tmpdir=<path>`. As the native library is mapped into the JVM virtual
13+
address space as executable, the underlying mount point of the location that
14+
this code is extracted to must *not* be mounted with `noexec` as this prevents
15+
the JVM process from being able to map this code as executable. On some hardened
16+
Linux installations this is a default mount option for `/tmp`. One indication
17+
that the underlying mount is mounted with `noexec` is that at startup JNA will
18+
fail to load with a `java.lang.UnsatisfiedLinkerError` exception with a message
19+
along the lines of `failed to map segment from shared object`. Note that the
20+
exception message can differ amongst JVM versions. Additionally, the components
21+
of Elasticsearch that rely on execution of native code via JNA will fail with
22+
messages indicating that it is `because JNA is not available`. If you are seeing
23+
such error messages, you must remount the temporary directory used for JNA to
24+
not be mounted with `noexec`.

docs/reference/setup/sysconfig/swap.asciidoc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,14 @@ Systems using `systemd`::
9595

9696
Set `LimitMEMLOCK` to `infinity` in the <<systemd,systemd configuration>>.
9797

98-
Another possible reason why `mlockall` can fail is that the temporary directory
99-
(usually `/tmp`) is mounted with the `noexec` option. This can be solved by
100-
specifying a new temp directory using the `ES_JAVA_OPTS` environment variable:
98+
Another possible reason why `mlockall` can fail is that
99+
<<executable-jna-tmpdir,the JNA temporary directory (usually a sub-directory of
100+
`/tmp`) is mounted with the `noexec` option>>. This can be solved by specifying
101+
a new temporary directory for JNA using the `ES_JAVA_OPTS` environment variable:
101102

102103
[source,sh]
103104
--------------
104-
export ES_JAVA_OPTS="$ES_JAVA_OPTS -Djava.io.tmpdir=/path/to/temp/dir"
105+
export ES_JAVA_OPTS="$ES_JAVA_OPTS -Djna.tmpdir=<path>"
105106
./bin/elasticsearch
106107
--------------
107108

0 commit comments

Comments
 (0)