Improve detection for `noexec` for default extraction location

Aperta
#1,059 2 commenti 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
java, sqlite
Ambito
database

Direzione di ricerca

Read SQLiteJDBCLoader.extractAndLoadLibraryFile around the permission-setting calls cited in the issue, then trace how extraction failures become UnsatisfiedLinkError. Check how File.setExecutable and canExecute behave for the extracted library on Linux with a noexec temporary directory. Done when users receive actionable troubleshooting information for permission failures, including how to select an executable temporary directory.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement

Is your feature request related to a problem? Please describe.
When /tmp is mounted as noexec on Linux, sqlite-jdbc fails to load the native library with an error similar to the following:

java.lang.UnsatisfiedLinkError: /tmp/sqlite-...-libsqlitejdbc.so: /tmp/sqlite-...-libsqlitejdbc.so: failed to map segment from shared object

Users can fix this by not mounting /temp as noexec, or by specifying a custom java.io.tmpdir or org.sqlite.tmpdir system property value pointing to an (existing) directory with execution permission.
But just based on the UnsatisfiedLinkError above, it might not obvious to users what the cause is, or how to fix it.

See related issues:

  • #97 (some of the comments there)
  • #571

Describe the solution you'd like
sqlite-jdbc should try to detect noexec or other permission errors and report them properly before trying to load the native library and causing an UnsatisfiedLinkError,
or better (?) trigger an UnsatisfiedLinkError but attach additional information, such as whether permissions are correct.

Additionally it could suggest to set the java.io.tmpdir or org.sqlite.tmpdir system property value to an (existing) directory with execution permission.

Additional context
Maybe the checks in SQLiteJDBCLoader.extractAndLoadLibraryFile should be improved:
https://github.com/xerial/sqlite-jdbc/blob/2e336d9ecd40cf00e76ae71564a903e67afc163b/src/main/java/org/sqlite/SQLiteJDBCLoader.java#L207-L209

Issues with the current implementation:

  • It does not check the return value of the setReadable, ... calls
  • After the setExecutable call it should call file.canExecute()
    It seems for noexec file.setExecutable(true) succeeds but file.canExecute() is still false afterwards, so it could be detected like this.

However, I am not that familiar with Linux and the implementation details of java.io.File, so maybe there are cases where for example setReadable, ... fails but the library can still be loaded.
So maybe these checks should only be performed if an UnsatisfiedLinkError occurs, to provide additional troubleshooting information.

Potentially useful: https://github.com/netty/netty/pull/6707, but I am not sure if using PosixFilePermission is really needed or if using the java.io.File API suffices.

Lingua principale
Java
Stelle
3.3k
Fork
676
Merge medio
1g 15h
PR unite (30g)
18

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di xerial/sqlite-jdbc

Tutte le issue di xerial/sqlite-jdbc

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.