logoalt Hacker News

dgltoday at 5:32 AM0 repliesview on HN

Simple -- you just add a custom SQLite VFS that ensures particular SQLite pages are mapped into underlying OS pages that are appropriately mprotect()ed. Try to modify the executable pages and you crash (W^X). Or you know, don't try to use a hack like this where security matters.

SQLite's unix VFS is actually using a mixture of mmap and write() by default[1] and you'd need to combine that with mseal() and some more pieces to actually pull it off. It would probably be possible.

(There's prior art here; although done differently: https://sqlite.org/src/file/ext/misc/appendvfs.c).

[1]: https://sqlite.org/mmap.html