summaryrefslogtreecommitdiff
path: root/dist/sqlite3.c
diff options
context:
space:
mode:
authorJosh Gao <jmgao@google.com>2018-08-21 18:44:26 -0700
committerJosh Gao <jmgao@google.com>2018-08-22 15:29:05 -0700
commitc427784c78a18efc63e36abe3f3bd3c5e66d582e (patch)
tree1333a7bb0be3165be4d63a24a23854ecf8510e99 /dist/sqlite3.c
parent427f01927f67c4c653d3e90643ad5c170b85c411 (diff)
Perfunctory fdsan support for sqlite fds.
Add some basic fdsan support to sqlite, where ownership enforcement is only at a sqlite level (i.e. other code is prevented from accidentally closing sqlite's file descriptors, but sqlite can accidentally close its own file descriptors). Test: debuggerd `pidof system_server` | grep " fd " Change-Id: I8ba23fa174dabb408f92be76b5476e0fe9e6c5dc
Diffstat (limited to 'dist/sqlite3.c')
-rw-r--r--dist/sqlite3.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/dist/sqlite3.c b/dist/sqlite3.c
index a12fd3e..791332c 100644
--- a/dist/sqlite3.c
+++ b/dist/sqlite3.c
@@ -30672,6 +30672,10 @@ SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){
# include <sys/mount.h>
#endif
+#if defined(__BIONIC__)
+# include <android/fdsan.h>
+#endif
+
#ifdef HAVE_UTIME
# include <utime.h>
#endif
@@ -31422,6 +31426,12 @@ static int robust_open(const char *z, int f, mode_t m){
#if defined(FD_CLOEXEC) && (!defined(O_CLOEXEC) || O_CLOEXEC==0)
osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
#endif
+
+#if defined(__BIONIC__) && __ANDROID_API__ >= __ANDROID_API_Q__
+ uint64_t tag = android_fdsan_create_owner_tag(
+ ANDROID_FDSAN_OWNER_TYPE_SQLITE, fd);
+ android_fdsan_exchange_owner_tag(fd, 0, tag);
+#endif
}
return fd;
}
@@ -31954,7 +31964,13 @@ static int unixLogErrorAtLine(
** and move on.
*/
static void robust_close(unixFile *pFile, int h, int lineno){
+#if defined(__BIONIC__) && __ANDROID_API__ >= __ANDROID_API_Q__
+ uint64_t tag = android_fdsan_create_owner_tag(
+ ANDROID_FDSAN_OWNER_TYPE_SQLITE, h);
+ if( android_fdsan_close_with_tag(h, tag) ){
+#else
if( osClose(h) ){
+#endif
unixLogErrorAtLine(SQLITE_IOERR_CLOSE, "close",
pFile ? pFile->zPath : 0, lineno);
}