#7 don't do filesystem visibility checks when the DB doesn't require set id privs to access it (hg bundle attached)
Closed: Fixed Opened by pcordes.

I wanted to dump the contents of my mlocate DB without limiting it to directories that currently exist. (even as root, the access() checks fail with -ENOENT, so mlocate doesn't show you everything.)

I modified mlocate to disable the visibility checks when the user can read the DB. If I haven't made any mistakes, mlocate is as secure as it was before. A user with read access to the DB can do whatever they want, so why not have mlocate do it for them already.

BTW, I wanted this for recovering from a disk failure. I had a big XFS filesystem spanning a couple disks (LVM), so when the first 400GB of it went away, I ended up with a bunch of files and directories without names (actually, with inode numbers for names). I wanted my mlocate DB to remind myself what was missing, and exactly what filenames I used for things. I had a backup of my mlocate DB from before the crash, when the files were still there.

I was going to add a command line option for it (and have mlocate drop privs when it saw that option, before trying to open a DB). But then I decided to just always disable checks when privs aren't required for the DB.
hg bundle of this patch, (and a separate commit of the commented out command-line-option stuff which you might not want) is attached, but it's small enough to inline for you to look at before downloading/applying.

diff -r d2038ab166f6 -r 1a5e2863f146 src/locate.c
--- a/src/locate.c Sat Mar 21 17:44:02 2009 +0000
+++ b/src/locate.c Mon Apr 13 23:32:26 2009 -0300
@@ -511,9 +511,9 @@
return -1;
}

-/ Read and handle DATABASE, open as FD /
+/ Read and handle DATABASE, opened as FD /
static void
-handle_db (int fd, const char database)
+handle_db (int fd, const char
database, bool privileged)
{
struct db db;
struct db_header hdr;
@@ -530,6 +530,7 @@
if (db_read_name (&db, &path_obstack) != 0)
goto err_path;
obstack_1grow (&path_obstack, 0);
+ hdr.check_visibility &= privileged; // don't check visibility if we have read access to the db without set id
visible = hdr.check_visibility ? -1 : 1;
p = obstack_finish (&path_obstack);
if (handle_path (p, &visible) != 0)
@@ -976,7 +977,7 @@
}
if (keep_gid == false)
drop_setgid();
- handle_db (fd, entry); / Closes fd /
+ handle_db (fd, entry, keep_gid); / Closes fd /
err:
;
}

happy hacking.


the visibility changes, and the commented out command-line-option stuff
visibility-unprivilege.pjc.hg-bundle

Thanks for the patch, applied in mlocate-0.22.

Metadata