Willena / sqlite-jdbc-crypt

SQLite JDBC Driver with encryption support
Apache License 2.0
172 stars 33 forks source link

org.sqlite.util.OSInfo.isMusl(): /proc/self/map_files: Operation not permitted #67

Closed jasonmattyd closed 2 years ago

jasonmattyd commented 2 years ago

I am using your library to access an encrypted sqlite database for an application I wrote, which is used in many different environments. I recently updated the library from 3.35.5.3 to 3.38.1.1 (the latest at the time), and in one particular environment there is a new issue.

Here is the relevant stack trace of the exception that is being thrown:

 org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97)
    at org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl.getIsolatedConnection(DdlTransactionIsolatorNonJtaImpl.java:69)
    at org.hibernate.tool.schema.internal.exec.ImprovedExtractionContextImpl.getJdbcConnection(ImprovedExtractionContextImpl.java:60)
    at org.hibernate.tool.schema.internal.exec.ImprovedExtractionContextImpl.getJdbcDatabaseMetaData(ImprovedExtractionContextImpl.java:67)
    at org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl.getTables(InformationExtractorJdbcDatabaseMetaDataImpl.java:329)
    at org.hibernate.tool.schema.extract.internal.DatabaseInformationImpl.getTablesInformation(DatabaseInformationImpl.java:120)
    at org.hibernate.tool.schema.internal.GroupedSchemaMigratorImpl.performTablesMigration(GroupedSchemaMigratorImpl.java:65)
    at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.performMigration(AbstractSchemaMigrator.java:207)
    at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.doMigration(AbstractSchemaMigrator.java:114)
    at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:183)
    at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:72)
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:313)
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:452)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:710)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:726)
    at au.com.bluecrystal.services.SQLiteConnectionService.initConnection(SQLiteConnectionService.java:31)
    at au.com.bluecrystal.services.ConfigurationConnectionService.initConnection(ConfigurationConnectionService.java:41)
    at au.com.bluecrystal.services.ConfigurationConnectionService.initialise(ConfigurationConnectionService.java:32)
    at au.com.bluecrystal.AgentMain.startApp(AgentMain.java:82)
    at au.com.bluecrystal.AgentMain.main(AgentMain.java:163)
Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!
    at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:118)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:692)
    at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:140)
    at org.hibernate.c3p0.internal.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:72)
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:180)
    at org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl.getIsolatedConnection(DdlTransactionIsolatorNonJtaImpl.java:43)
    ... 18 more
Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
    at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1507)
    at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:644)
    at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:554)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutAndMarkConnectionInUse(C3P0PooledConnectionPool.java:758)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:685)
    at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:140)
    at org.hibernate.c3p0.internal.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:72)
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:180)
    at org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl.getIsolatedConnection(DdlTransactionIsolatorNonJtaImpl.java:43)
    ... 18 more
Caused by: java.sql.SQLException: Error opening connection
    at org.sqlite.SQLiteConnection.open(SQLiteConnection.java:259)
    at org.sqlite.SQLiteConnection.<init>(SQLiteConnection.java:62)
    at org.sqlite.jdbc3.JDBC3Connection.<init>(JDBC3Connection.java:23)
    at org.sqlite.jdbc4.JDBC4Connection.<init>(JDBC4Connection.java:19)
    at org.sqlite.JDBC.createConnection(JDBC.java:104)
    at org.sqlite.JDBC.connect(JDBC.java:77)
    at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:161)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:161)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:147)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:202)
    at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1176)
    at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1163)
    at com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44)
    at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1908)
    at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)
Caused by: java.io.UncheckedIOException: java.nio.file.FileSystemException: /proc/self/map_files: Operation not permitted
    at java.nio.file.Files$2.hasNext(Unknown Source) ~[?:?]
    at java.util.Spliterators$IteratorSpliterator.tryAdvance(Unknown Source) ~[?:?]
    at java.util.stream.ReferencePipeline.forEachWithCancel(Unknown Source) ~[?:?]
    at java.util.stream.AbstractPipeline.copyIntoWithCancel(Unknown Source) ~[?:?]
    at java.util.stream.AbstractPipeline.copyInto(Unknown Source) ~[?:?]
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source) ~[?:?]
    at java.util.stream.MatchOps$MatchOp.evaluateSequential(Unknown Source) ~[?:?]
    at java.util.stream.MatchOps$MatchOp.evaluateSequential(Unknown Source) ~[?:?]
    at java.util.stream.AbstractPipeline.evaluate(Unknown Source) ~[?:?]
    at java.util.stream.ReferencePipeline.anyMatch(Unknown Source) ~[?:?]
    at org.sqlite.util.OSInfo.isMusl(OSInfo.java:127)
    at org.sqlite.util.OSInfo.translateOSNameToFolderName(OSInfo.java:226)
    at org.sqlite.util.OSInfo.getOSName(OSInfo.java:108)
    at org.sqlite.util.OSInfo.getNativeLibFolderPathForCurrentOS(OSInfo.java:104)
    at org.sqlite.SQLiteJDBCLoader.loadSQLiteNativeLibrary(SQLiteJDBCLoader.java:348)
    at org.sqlite.SQLiteJDBCLoader.initialize(SQLiteJDBCLoader.java:65)
    at org.sqlite.core.NativeDB.load(NativeDB.java:56)
    at org.sqlite.SQLiteConnection.open(SQLiteConnection.java:256)
    at org.sqlite.SQLiteConnection.<init>(SQLiteConnection.java:62)
    at org.sqlite.jdbc3.JDBC3Connection.<init>(JDBC3Connection.java:23)
    at org.sqlite.jdbc4.JDBC4Connection.<init>(JDBC4Connection.java:19)
    at org.sqlite.JDBC.createConnection(JDBC.java:104)
    at org.sqlite.JDBC.connect(JDBC.java:77)
    at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:161)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:161)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:147)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:202)
    at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1176)
    at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1163)
    at com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44)
    at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1908)
    at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)
Caused by: java.nio.file.FileSystemException: /proc/self/map_files: Operation not permitted
    at sun.nio.fs.UnixException.translateToIOException(Unknown Source) ~[?:?]
    at sun.nio.fs.UnixException.asIOException(Unknown Source) ~[?:?]
    at sun.nio.fs.UnixDirectoryStream$UnixDirectoryIterator.readNextEntry(Unknown Source) ~[?:?]
    at sun.nio.fs.UnixDirectoryStream$UnixDirectoryIterator.hasNext(Unknown Source) ~[?:?]
    at java.nio.file.Files$2.hasNext(Unknown Source) ~[?:?]
    at java.util.Spliterators$IteratorSpliterator.tryAdvance(Unknown Source) ~[?:?]
    at java.util.stream.ReferencePipeline.forEachWithCancel(Unknown Source) ~[?:?]
    at java.util.stream.AbstractPipeline.copyIntoWithCancel(Unknown Source) ~[?:?]
    at java.util.stream.AbstractPipeline.copyInto(Unknown Source) ~[?:?]
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source) ~[?:?]
    at java.util.stream.MatchOps$MatchOp.evaluateSequential(Unknown Source) ~[?:?]
    at java.util.stream.MatchOps$MatchOp.evaluateSequential(Unknown Source) ~[?:?]
    at java.util.stream.AbstractPipeline.evaluate(Unknown Source) ~[?:?]
    at java.util.stream.ReferencePipeline.anyMatch(Unknown Source) ~[?:?]
    at org.sqlite.util.OSInfo.isMusl(OSInfo.java:127)
    at org.sqlite.util.OSInfo.translateOSNameToFolderName(OSInfo.java:226)
    at org.sqlite.util.OSInfo.getOSName(OSInfo.java:108)
    at org.sqlite.util.OSInfo.getNativeLibFolderPathForCurrentOS(OSInfo.java:104)
    at org.sqlite.SQLiteJDBCLoader.loadSQLiteNativeLibrary(SQLiteJDBCLoader.java:348)
    at org.sqlite.SQLiteJDBCLoader.initialize(SQLiteJDBCLoader.java:65)
    at org.sqlite.core.NativeDB.load(NativeDB.java:56)
    at org.sqlite.SQLiteConnection.open(SQLiteConnection.java:256)
    at org.sqlite.SQLiteConnection.<init>(SQLiteConnection.java:62)
    at org.sqlite.jdbc3.JDBC3Connection.<init>(JDBC3Connection.java:23)
    at org.sqlite.jdbc4.JDBC4Connection.<init>(JDBC4Connection.java:19)
    at org.sqlite.JDBC.createConnection(JDBC.java:104)
    at org.sqlite.JDBC.connect(JDBC.java:77)
    at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:161)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:161)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:147)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:202)
    at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1176)
    at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1163)
    at com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44)
    at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1908)
    at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)

The user running the application does not have root access in this environment, nor is able to be given root access. The /proc/self/map_files folder has permission dr-x------ and is owned by root.

Reverting back to the older version, before the isMusl method was added, has worked in this environment.

Willena commented 2 years ago

This has already been reported in the upstream repository in January: xerial/sqlite-jdbc/issues/706 The fix is available and will be integrated in my next synchronization with the upstream repo. I'll close the issue with the next release.

Willena commented 2 years ago

Version 3.39.2 has been released and contains the previously mentioned fix.

jasonmattyd commented 2 years ago

That's awesome, thanks for the quick turn around! Keep up the good work.