PR27571: debuginfod client cache - file permissions
authorFrank Ch. Eigler <fche@redhat.com>
Mon, 26 Apr 2021 16:21:03 +0000 (12:21 -0400)
committerFrank Ch. Eigler <fche@redhat.com>
Sat, 1 May 2021 18:15:32 +0000 (14:15 -0400)
Files in the download cache should be read-only.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
debuginfod/ChangeLog
debuginfod/debuginfod-client.c
tests/ChangeLog
tests/run-debuginfod-find.sh

index 9af641e..3909100 100644 (file)
@@ -1,5 +1,11 @@
 2021-04-26  Frank Ch. Eigler <fche@redhat.com>
 
+       PR27571
+       * debuginfod-client.c (debuginfod_query_server): Chmod 0400 files
+       delivered into the cache to prevent accidental modification.
+
+2021-04-26  Frank Ch. Eigler <fche@redhat.com>
+
        PR26125
        * debuginfod-client.c (debuginfod_clean_cache): For directory
        rmdir, check mtime first.
index 0170500..374989e 100644 (file)
@@ -720,7 +720,7 @@ debuginfod_query_server (debuginfod_client *c,
   /* Because of a race with cache cleanup / rmdir, try to mkdir/mkstemp up to twice. */
   for(int i=0; i<2; i++) {
     /* (re)create target directory in cache */
-    (void) mkdir(target_cache_dir, 0700);
+    (void) mkdir(target_cache_dir, 0700); /* files will be 0400 later */
 
     /* NB: write to a temporary file first, to avoid race condition of
        multiple clients checking the cache, while a partially-written or empty
@@ -1054,6 +1054,9 @@ debuginfod_query_server (debuginfod_client *c,
   tvs[0].tv_usec = tvs[1].tv_usec = 0;
   (void) futimes (fd, tvs);  /* best effort */
 
+  /* PR27571: make cache files casually unwriteable; dirs are already 0700 */
+  (void) fchmod(fd, 0400);
+                
   /* rename tmp->real */
   rc = rename (target_cache_tmppath, target_cache_path);
   if (rc < 0)
index 0d2c5ed..f6e540d 100644 (file)
@@ -1,3 +1,8 @@
+2021-04-26  Frank Ch. Eigler <fche@redhat.com>
+
+       PR27571
+       * run-debuginfod-find.sh: Add test case for unwriteable cache files.
+
 2021-04-23  Omar Sandoval  <osandov@fb.com>
 
        * run-low_high_pc-dw-form-indirect.sh: New file.
index 3b9a5a6..d17a8d8 100755 (executable)
@@ -177,6 +177,10 @@ testrun ${abs_builddir}/debuginfod_build_id_find -e F/prog 1
 rm -rf $DEBUGINFOD_CACHE_PATH # clean it from previous tests
 filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID`
 cmp $filename F/prog.debug
+if [ -w $filename ]; then
+    echo "cache file writable, boo"
+    exit 1
+fi
 
 filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find executable F/prog`
 cmp $filename F/prog