Skip to content
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

BSim: Update PostgreSQL (15.3->17.0) to fix SSL errors #7085

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gemesa
Copy link
Contributor

@gemesa gemesa commented Oct 23, 2024

Fixes #6115
Fixes #7084

As mentioned in the linked issues, on distros (Fedora, Arch etc.) with newer packages (especially OpenSSL), the currently used PostgreSQL (15.3) is not working properly resulting in SSL error(s) (detailed in the issues). In #7084 I fixed the SSL error by downgrading OpenSSL but this was a painful solution. In this PR I have upgraded the PostgreSQL version from 15.3 to 17.0 and now bsim_ctl start works on Fedora 40 with OpenSSL 3.2.2 and also on Ubuntu 22.04 with OpenSSL 3.0.2. Edit: I also added the dumpall and restore commands to bsim_ctl which can be used to migrate DBs from 15.3 to 17.0 (see #7085 (comment)).

$ uname -a
Linux fedora 6.10.12-200.fc40.x86_64 #1 SMP PREEMPT_DYNAMIC Mon Sep 30 21:38:25 UTC 2024 x86_64 GNU/Linux
$ openssl version
OpenSSL 3.2.2 4 Jun 2024 (Library: OpenSSL 3.2.2 4 Jun 2024)
$ ./support/bsim_ctl start ~/git-repos/bsim-db       
openjdk version "21.0.4" 2024-07-16 LTS
OpenJDK Runtime Environment Temurin-21.0.4+7 (build 21.0.4+7-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.4+7 (build 21.0.4+7-LTS, mixed mode)
No client authentication
Initializing data directory
Generating servers SSL certificate
Server started
BSim extension enabled
$ uname -a
Linux ubuntu-22 6.8.0-47-generic #47~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Oct  2 16:16:55 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
$ openssl version
OpenSSL 3.0.2 15 Mar 2022 (Library: OpenSSL 3.0.2 15 Mar 2022)
$ ./support/bsim_ctl start ~/git-repos/bsim-db/
openjdk version "21.0.4" 2024-07-16 LTS
OpenJDK Runtime Environment Temurin-21.0.4+7 (build 21.0.4+7-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.4+7 (build 21.0.4+7-LTS, mixed mode)
No client authentication
Initializing data directory
Generating servers SSL certificate
Server started
BSim extension enabled

@gemesa
Copy link
Contributor Author

gemesa commented Oct 24, 2024

I also compared pga_hba.conf from version 15.3 to 17.0 and found no differences, except in the comments.

Similarly I compared postgresql.conf from version 15.3 to 17.0. Some options were added, removed or had their default values changed but the customized options (listen_addresses, password_encryption, ssl, shared_buffers, work_mem, checkpoint_timeout) are not affected.

I have attached the 2 compare reports created by Beyond Compare. Remove the .txt extension and then they can be viewed in a browser.
postgresql.conf.diff.html.txt
pg_hba.conf.diff.html.txt

Copy link

@byt3exec byt3exec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*looking at the

@gemesa
Copy link
Contributor Author

gemesa commented Oct 25, 2024

I tested most of the main functionalities and everything seems to be working fine:

$ ./support/bsim_ctl start ~/git-repos/bsim-db
openjdk version "21.0.4" 2024-07-16 LTS
OpenJDK Runtime Environment Temurin-21.0.4+7 (build 21.0.4+7-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.4+7 (build 21.0.4+7-LTS, mixed mode)
No client authentication
Initializing data directory
Generating servers SSL certificate
Server started
BSim extension enabled

$ ./support/bsim_ctl adduser ~/git-repos/bsim-db test                   
openjdk version "21.0.4" 2024-07-16 LTS
OpenJDK Runtime Environment Temurin-21.0.4+7 (build 21.0.4+7-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.4+7 (build 21.0.4+7-LTS, mixed mode)
Added user: test

$ ./support/bsim_ctl adduser ~/git-repos/bsim-db test2 --user test
openjdk version "21.0.4" 2024-07-16 LTS
OpenJDK Runtime Environment Temurin-21.0.4+7 (build 21.0.4+7-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.4+7 (build 21.0.4+7-LTS, mixed mode)
Error connecting to the database
ERROR: permission denied to create role
  Detail: Only roles with the CREATEROLE attribute may create roles.

$ ./support/bsim_ctl changeprivilege test admin --user test      
openjdk version "21.0.4" 2024-07-16 LTS
OpenJDK Runtime Environment Temurin-21.0.4+7 (build 21.0.4+7-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.4+7 (build 21.0.4+7-LTS, mixed mode)
Granting admin privileges to test
Error connecting to the database
ERROR: permission denied to alter role
  Detail: Only roles with the SUPERUSER attribute may change the SUPERUSER attribute.

$ ./support/bsim_ctl changeprivilege test admin            
openjdk version "21.0.4" 2024-07-16 LTS
OpenJDK Runtime Environment Temurin-21.0.4+7 (build 21.0.4+7-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.4+7 (build 21.0.4+7-LTS, mixed mode)
Granting admin privileges to test

$ ./support/bsim_ctl dropuser ~/git-repos/bsim-db test --user test 
openjdk version "21.0.4" 2024-07-16 LTS
OpenJDK Runtime Environment Temurin-21.0.4+7 (build 21.0.4+7-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.4+7 (build 21.0.4+7-LTS, mixed mode)
Error connecting to the database
ERROR: current user cannot be dropped

$ ./support/bsim_ctl dropuser ~/git-repos/bsim-db test            
openjdk version "21.0.4" 2024-07-16 LTS
OpenJDK Runtime Environment Temurin-21.0.4+7 (build 21.0.4+7-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.4+7 (build 21.0.4+7-LTS, mixed mode)
Removed user: test

$ ./support/bsim createdatabase postgresql://localhost:5432/repo medium_64 -n repo
openjdk version "21.0.4" 2024-07-16 LTS
OpenJDK Runtime Environment Temurin-21.0.4+7 (build 21.0.4+7-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.4+7 (build 21.0.4+7-LTS, mixed mode)
Max-Memory: 3.4 GBytes
Created database: repo
   owner       = Example Owner
   description = A medium sized (~10 million functions) database tuned for 64-bit executables
   template    = medium_64
 
$ ./support/bsim generatesigs ghidra://localhost/repo ~/git-repos/bsim-xml --bsim postgresql://localhost/repo --commit 
openjdk version "21.0.4" 2024-07-16 LTS
OpenJDK Runtime Environment Temurin-21.0.4+7 (build 21.0.4+7-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.4+7 (build 21.0.4+7-LTS, mixed mode)
Max-Memory: 3.4 GBytes
Using configuration for:
 Database: repo
 Owner:    Example Owner
 
Repository Server: localhost
Password: 
Generating signatures for: hello 
Writing signatures for sigs_585c70eef0bbd516c846dcd3103dced7

$ ./support/bsim delete postgresql://localhost/repo --name hello
openjdk version "21.0.4" 2024-07-16 LTS
OpenJDK Runtime Environment Temurin-21.0.4+7 (build 21.0.4+7-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.4+7 (build 21.0.4+7-LTS, mixed mode)
Max-Memory: 3.4 GBytes
Successfully deleted hello(10 functions)585c70eef0bbd516c846dcd3103dced7

$ ./support/bsim generatesigs ghidra://localhost/repo ~/git-repos/bsim-xml --bsim postgresql://localhost/repo --commit
openjdk version "21.0.4" 2024-07-16 LTS
OpenJDK Runtime Environment Temurin-21.0.4+7 (build 21.0.4+7-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.4+7 (build 21.0.4+7-LTS, mixed mode)
Max-Memory: 3.4 GBytes
Using configuration for:
 Database: repo
 Owner:    Example Owner
 
Repository Server: localhost
Password: 
WARN  Signature file already exists for: hello (SignatureRepository)  
Writing signatures for sigs_585c70eef0bbd516c846dcd3103dced7

$ ./support/bsim listexes postgresql://localhost/repo    
openjdk version "21.0.4" 2024-07-16 LTS
OpenJDK Runtime Environment Temurin-21.0.4+7 (build 21.0.4+7-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.4+7 (build 21.0.4+7-LTS, mixed mode)
Max-Memory: 3.4 GBytes
585c70eef0bbd516c846dcd3103dced7 hello x86:LE:64:default gcc 
1 executables found

$ ./support/bsim getexecount postgresql://localhost/repo
openjdk version "21.0.4" 2024-07-16 LTS
OpenJDK Runtime Environment Temurin-21.0.4+7 (build 21.0.4+7-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.4+7 (build 21.0.4+7-LTS, mixed mode)
Max-Memory: 3.4 GBytes
Matching executable count: 1

$ ./support/bsim listfuncs postgresql://localhost/repo --name hello
openjdk version "21.0.4" 2024-07-16 LTS
OpenJDK Runtime Environment Temurin-21.0.4+7 (build 21.0.4+7-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.4+7 (build 21.0.4+7-LTS, mixed mode)
Max-Memory: 3.4 GBytes
585c70eef0bbd516c846dcd3103dced7 hello x86:LE:64:default gcc
  FUN_00401020 585c70eef0bbd516c846dcd3103dced7 hello x86:LE:64:default gcc
  __do_global_dtors_aux 585c70eef0bbd516c846dcd3103dced7 hello x86:LE:64:default gcc
  _dl_relocate_static_pie 585c70eef0bbd516c846dcd3103dced7 hello x86:LE:64:default gcc
  _fini 585c70eef0bbd516c846dcd3103dced7 hello x86:LE:64:default gcc
  _init 585c70eef0bbd516c846dcd3103dced7 hello x86:LE:64:default gcc
  _start 585c70eef0bbd516c846dcd3103dced7 hello x86:LE:64:default gcc
  deregister_tm_clones 585c70eef0bbd516c846dcd3103dced7 hello x86:LE:64:default gcc
  main 585c70eef0bbd516c846dcd3103dced7 hello x86:LE:64:default gcc
  print_hello 585c70eef0bbd516c846dcd3103dced7 hello x86:LE:64:default gcc
  register_tm_clones 585c70eef0bbd516c846dcd3103dced7 hello x86:LE:64:default gcc

$ ./support/bsim dropindex postgresql://localhost/repo    
openjdk version "21.0.4" 2024-07-16 LTS
OpenJDK Runtime Environment Temurin-21.0.4+7 (build 21.0.4+7-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.4+7 (build 21.0.4+7-LTS, mixed mode)
Max-Memory: 3.4 GBytes
Successfully dropped index for database repo (repo  (postgres: localhost))

$ ./support/bsim rebuildindex postgresql://localhost/repo
openjdk version "21.0.4" 2024-07-16 LTS
OpenJDK Runtime Environment Temurin-21.0.4+7 (build 21.0.4+7-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.4+7 (build 21.0.4+7-LTS, mixed mode)
Max-Memory: 3.4 GBytes
Starting rebuild ...
Successfully rebuilt index for database repo (repo  (postgres: localhost))

$ ./support/bsim dumpsigs postgresql://localhost/repo ~/git-repos/bsim-xml --name hello 
openjdk version "21.0.4" 2024-07-16 LTS
OpenJDK Runtime Environment Temurin-21.0.4+7 (build 21.0.4+7-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.4+7 (build 21.0.4+7-LTS, mixed mode)
Max-Memory: 3.4 GBytes
$ head -n 10 sigs_585c70eef0bbd516c846dcd3103dced7 
<description layout_version="5" major="6" minor="1" settings="0x49">
<execlist>
<exe>
  <md5>585c70eef0bbd516c846dcd3103dced7</md5>
  <name>hello</name>
  <arch>x86:LE:64:default</arch>
  <compiler>gcc</compiler>
  <date millis="0x2b5">0x671be47b</date>
  <repository>ghidra://localhost/repo</repository>
</exe>

$ rm -rf ~/git-repos/bsim-db
$ mkdir ~/git-repos/bsim-db
$ ./support/bsim_ctl start ~/git-repos/bsim-db --auth pki --dn=CN=gemesa --cafile=/home/gemesa/git-repos/bsim-pki/ca.crt --cert=/home/gemesa/git-repos/bsim-pki/client.p12
openjdk version "21.0.4" 2024-07-16 LTS
OpenJDK Runtime Environment Temurin-21.0.4+7 (build 21.0.4+7-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.4+7 (build 21.0.4+7-LTS, mixed mode)
Remote client authentication with PKI certificates
Initializing data directory
Generating servers SSL certificate
Server started
BSim extension enabled

$ ./support/bsim_ctl stop ~/git-repos/bsim-db 
openjdk version "21.0.4" 2024-07-16 LTS
OpenJDK Runtime Environment Temurin-21.0.4+7 (build 21.0.4+7-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.4+7 (build 21.0.4+7-LTS, mixed mode)
Server shutdown complete

@gemesa
Copy link
Contributor Author

gemesa commented Oct 27, 2024

I also added the dumpall and restore commands to bsim_ctl which can be used to migrate DBs from 15.3 to 17.0.

Dump DBs with PostgreSQL version 15.3

Prerequisites:

  • run ./make-postgres.sh with POSTGRES=postgresql-15.3
  • init a db with ./support/bsim_ctl start
  • add some signatures with ./support/bsim commitsigs

I added this one:

$ head -n 10 ~/git-repos/bsim-xml/sigs_585c70eef0bbd516c846dcd3103dced7 
<description layout_version="5" major="6" minor="1" settings="0x49">
<execlist>
<exe>
  <md5>585c70eef0bbd516c846dcd3103dced7</md5>
  <name>hello</name>
  <arch>x86:LE:64:default</arch>
  <compiler>gcc</compiler>
  <date millis="0x2b5">0x671be47b</date>
  <repository>ghidra://localhost/repo</repository>
</exe>

Dump the databases (I am prompted for the password 4 times because there are 4 databases so 4 connections made):

$ ./support/bsim_ctl dumpall mydump-15.3.sql
openjdk version "21.0.4" 2024-07-16 LTS
OpenJDK Runtime Environment Temurin-21.0.4+7 (build 21.0.4+7-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.4+7 (build 21.0.4+7-LTS, mixed mode)
Password: 
Password: 
Password: 
Password: 
Databases dumped to /home/gemesa/git-repos/ghidra/build/dist/ghidra_11.3_DEV/mydump-15.3.sql

Inspect the content:

$ grep version mydump-15.3.sql 
-- Dumped from database version 15.3
-- Dumped by pg_dump version 15.3
-- Dumped from database version 15.3
-- Dumped by pg_dump version 15.3
-- Dumped from database version 15.3
-- Dumped by pg_dump version 15.3

$ grep hello mydump-15.3.sql                           
9	print_hello	1	-1810480557466029468	0	4198694
1	585c70eef0bbd516c846dcd3103dced7	hello	1	1	2024-10-25 20:33:31.693+02	1	0

Restore DBs with PostgreSQL version 17.0

Prerequisites:

  • run ./make-postgres.sh with POSTGRES=postgresql-17.0
  • init a db with ./support/bsim_ctl start

Restore the databases:

$ ./support/bsim_ctl restore mydump-15.3.sql 
openjdk version "21.0.4" 2024-07-16 LTS
OpenJDK Runtime Environment Temurin-21.0.4+7 (build 21.0.4+7-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.4+7 (build 21.0.4+7-LTS, mixed mode)
Password for user gemesa: 
Databases restored from /home/gemesa/git-repos/ghidra/build/dist/ghidra_11.3_DEV/mydump-15.3.sql

Inspect the content:

$ ./support/bsim listexes postgresql://localhost/repo
openjdk version "21.0.4" 2024-07-16 LTS
OpenJDK Runtime Environment Temurin-21.0.4+7 (build 21.0.4+7-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.4+7 (build 21.0.4+7-LTS, mixed mode)
Max-Memory: 3.4 GBytes
BSim Database Server: repo  (postgres: localhost)
Password: 
585c70eef0bbd516c846dcd3103dced7 hello x86:LE:64:default gcc 
1 executables found

$ ./support/bsim listfuncs postgresql://localhost/repo -n hello
openjdk version "21.0.4" 2024-07-16 LTS
OpenJDK Runtime Environment Temurin-21.0.4+7 (build 21.0.4+7-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.4+7 (build 21.0.4+7-LTS, mixed mode)
Max-Memory: 3.4 GBytes
BSim Database Server: repo  (postgres: localhost)
Password: 
585c70eef0bbd516c846dcd3103dced7 hello x86:LE:64:default gcc
  FUN_00401020 585c70eef0bbd516c846dcd3103dced7 hello x86:LE:64:default gcc
  __do_global_dtors_aux 585c70eef0bbd516c846dcd3103dced7 hello x86:LE:64:default gcc
  _dl_relocate_static_pie 585c70eef0bbd516c846dcd3103dced7 hello x86:LE:64:default gcc
  _fini 585c70eef0bbd516c846dcd3103dced7 hello x86:LE:64:default gcc
  _init 585c70eef0bbd516c846dcd3103dced7 hello x86:LE:64:default gcc
  _start 585c70eef0bbd516c846dcd3103dced7 hello x86:LE:64:default gcc
  deregister_tm_clones 585c70eef0bbd516c846dcd3103dced7 hello x86:LE:64:default gcc
  main 585c70eef0bbd516c846dcd3103dced7 hello x86:LE:64:default gcc
  print_hello 585c70eef0bbd516c846dcd3103dced7 hello x86:LE:64:default gcc
  register_tm_clones 585c70eef0bbd516c846dcd3103dced7 hello x86:LE:64:default gcc

@ghidracadabra ghidracadabra added Status: Prioritize This is currently being prioritized and removed Status: Triage Information is being gathered labels Nov 7, 2024
@ghidracadabra ghidracadabra added Status: Internal This is being tracked internally by the Ghidra team and removed Status: Prioritize This is currently being prioritized labels Dec 5, 2024
@ghidra1
Copy link
Collaborator

ghidra1 commented Dec 20, 2024

For the time being we will be updating to postgresql 15.10 which works with openssl 3.2.2 and was updated on 18-Nov-2024. Support for postgresql 15.x continues until 11-Nov-2027 (see Postgrsql Releases).

@gemesa
Copy link
Contributor Author

gemesa commented Dec 20, 2024

This is awesome news. Let me know if you want to include any changes from this PR in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature: BSim Status: Internal This is being tracked internally by the Ghidra team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bsim_ctl start fails on Fedora 40 First bsim_ctl start unsuccessful during BSim Postgres setup
5 participants