Prevent Magisk database race condition

The database should only be accessed by a single process, which is magiskd.
This means 'magisk --sqlite [SQL]' has to be updated to pass the SQL command to the daemon.
In addition, open the database connection with SQLITE_OPEN_FULLMUTEX to support multithread in magiskd.
This commit is contained in:
topjohnwu
2018-11-16 03:20:30 -05:00
parent ba70269398
commit ab5fedda0b
8 changed files with 130 additions and 150 deletions
+6
View File
@@ -18,6 +18,7 @@
#include "utils.h"
#include "daemon.h"
#include "selinux.h"
#include "db.h"
#include "flags.h"
static void get_client_cred(int fd, struct ucred *cred) {
@@ -39,6 +40,7 @@ static void *request_handler(void *args) {
case POST_FS_DATA:
case LATE_START:
case BOOT_COMPLETE:
case SQLITE_CMD:
if (credential.uid != 0) {
write_int(client, ROOT_REQUIRED);
close(client);
@@ -75,6 +77,10 @@ static void *request_handler(void *args) {
case HANDSHAKE:
/* Do NOT close the client, make it hold */
break;
case SQLITE_CMD:
exec_sql(client);
close(client);
break;
default:
close(client);
break;