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

Embedded server crashing on short connects to database which want to be sweeped [CORE6338] #6579

Closed
firebird-automations opened this issue Jun 19, 2020 · 11 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: @artyom-smirnov

Is related to CORE6360
Duplicates CORE5197

In some cases firebird server can craft such database, which crashes embedded server if embedded connection too short to complete sweep.

To reproduce stop firebird, make sure running user will have all permissions to work as embedded and run included script.
Script will emulate database crafting by disabling sweep, inserting data but nor commit nor rollback it and enabling sweep. Next connections CAN crash, but not always. If crafted database will be properly sweeped crashes disappearing.
Stacktraces telling it crashing during exit, but stack with segfault smashed.

Reproducing script:

https://gist.github.com/artyom-smirnov/9f7f3d873f34fc12dcd721cab92818e3

or

#⁠!/bin/bash
rm -f repro.fdb f

ISQL=bin/isql
GFIX=bin/gfix

cat << EOF > create.sql
create database 'repro.fdb';
create table test(test varchar(255));
EOF

cat << EOF > connect.sql
connect 'repro.fdb' user 'sysdba' password 'masterkey';
exit;
EOF

cat << EOF > gdbinit
set \$_exitcode = -1
run
if \$_exitcode != -1
quit
end
EOF

$ISQL -u sysdba -p masterkey -i create.sql
$GFIX -user sysdba -pass masterkey -h 0 repro.fdb

mkfifo f
cat f | $ISQL -u sysdba -p masterkey repro.fdb&
ISQL_PID=$!
exec 3>f
for i in `seq 1 1000`; do
cat << EOF > f
insert into test values('text');
EOF
done

kill -KILL $ISQL_PID

$GFIX -user sysdba -pass masterkey -h 1 repro.fdb

while true; do gdb -x gdbinit --args $ISQL -u sysdba -p masterkey -i connect.sql; done
#⁠while true; do $ISQL -u sysdba -p masterkey -i connect.sql; done

Stack with crash looks smashed:

Thread 6 "isql" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffebfff700 (LWP 90529)]
0x00007ffff53bfd72 in ?? ()
(gdb) bt
#⁠0 0x00007ffff53bfd72 in ?? ()
#⁠1 0x0000000000000010 in ?? ()
#⁠2 0x00007ffff7bc6340 in ?? ()
#⁠3 0x00000000ebffecb0 in ?? ()
#⁠4 0x00007ffff58e60e2 in ?? ()
#⁠5 0x0000000000000001 in ?? ()
#⁠6 0x0000000014000218 in ?? ()
#⁠7 0x0000000000000000 in ?? ()
(gdb)

@firebird-automations
Copy link
Collaborator Author

Modified by: @AlexPeshkoff

assignee: Alexander Peshkov [ alexpeshkoff ]

@firebird-automations
Copy link
Collaborator Author

Commented by: @artyom-smirnov

Looks like libEngine unloaded too early. During debugging gdb shows such error some steps before crash:

Temporarily disabling breakpoints for unloaded shared library "...../gen/Debug/firebird/plugins/libEngine12.so"

@firebird-automations
Copy link
Collaborator Author

Commented by: @artyom-smirnov

Also breakpointing on dlclose and then stepping reveals that dlclose called for modules, then engine crashed.

@firebird-automations
Copy link
Collaborator Author

Commented by: @AlexPeshkoff

Looks like I have an idea why this happens, next step is to fix segfault.

@firebird-automations
Copy link
Collaborator Author

Modified by: @artyom-smirnov

Version: 4.0 RC 1 [ 10930 ]

@firebird-automations
Copy link
Collaborator Author

Commented by: @artyom-smirnov

CryptoManager affected similar issue:

When CM thread starting it assigns its internal attachment flag "ATT_crypt_thread", but on short connection this attachment and shutdown racing and flag may be never assigned therefore attachment and CM thread can not properly stopped causing server hang.

Reproducing:

#⁠!/bin/bash
set -e

echo Auto = y > plugins/DbCrypt_example.conf

rm tmp.fdb
echo "create database 'tmp.fdb';" | bin/isql -u sysdba -p masterkey

while true; do
cp tmp.fdb repro.fdb; echo 'alter database encrypt with "DbCrypt_example";'| bin/isql -u sysdba -p masterkey repro.fdb
done

@firebird-automations
Copy link
Collaborator Author

Commented by: @AlexPeshkoff

Confirm, reproduced for crypt thread

@firebird-automations
Copy link
Collaborator Author

Modified by: @AlexPeshkoff

Link: This issue is related to CORE6360 [ CORE6360 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @AlexPeshkoff

Link: This issue duplicates CORE5197 [ CORE5197 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @AlexPeshkoff

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Duplicate [ 3 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

status: Resolved [ 5 ] => Closed [ 6 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants