Bastien Nocera 49b48d2
From 717df38fd8509bf883b70d680c9b1b3cf36732ee Mon Sep 17 00:00:00 2001
Bastien Nocera 49b48d2
From: Bastien Nocera <hadess@hadess.net>
Bastien Nocera 49b48d2
Date: Thu, 6 Jul 2017 20:02:00 +0200
Bastien Nocera 49b48d2
Subject: [PATCH] comics: Remove support for tar and tar-like commands
Bastien Nocera 49b48d2
Bastien Nocera 49b48d2
When handling tar files, or using a command with tar-compatible syntax,
Bastien Nocera 49b48d2
to open comic-book archives, both the archive name (the name of the
Bastien Nocera 49b48d2
comics file) and the filename (the name of a page within the archive)
Bastien Nocera 49b48d2
are quoted to not be interpreted by the shell.
Bastien Nocera 49b48d2
Bastien Nocera 49b48d2
But the filename is completely with the attacker's control and can start
Bastien Nocera 49b48d2
with "--" which leads to tar interpreting it as a command line flag.
Bastien Nocera 49b48d2
Bastien Nocera 49b48d2
This can be exploited by creating a CBT file (a tar archive with the
Bastien Nocera 49b48d2
.cbt suffix) with an embedded file named something like this:
Bastien Nocera 49b48d2
"--checkpoint-action=exec=bash -c 'touch ~/hacked;'.jpg"
Bastien Nocera 49b48d2
Bastien Nocera 49b48d2
CBT files are infinitely rare (CBZ is usually used for DRM-free
Bastien Nocera 49b48d2
commercial releases, CBR for those from more dubious provenance), so
Bastien Nocera 49b48d2
removing support is the easiest way to avoid the bug triggering. All
Bastien Nocera 49b48d2
this code was rewritten in the development release for GNOME 3.26 to not
Bastien Nocera 49b48d2
shell out to any command, closing off this particular attack vector.
Bastien Nocera 49b48d2
Bastien Nocera 49b48d2
This also removes the ability to use libarchive's bsdtar-compatible
Bastien Nocera 49b48d2
binary for CBZ (ZIP), CB7 (7zip), and CBR (RAR) formats. The first two
Bastien Nocera 49b48d2
are already supported by unzip and 7zip respectively. libarchive's RAR
Bastien Nocera 49b48d2
support is limited, so unrar is a requirement anyway.
Bastien Nocera 49b48d2
Bastien Nocera 49b48d2
Discovered by Felix Wilhelm from the Google Security Team.
Bastien Nocera 49b48d2
Bastien Nocera 49b48d2
https://bugzilla.gnome.org/show_bug.cgi?id=784630
Bastien Nocera 49b48d2
---
Bastien Nocera 49b48d2
 backend/comics/comics-document.c | 40 +---------------------------------------
Bastien Nocera 49b48d2
 configure.ac                     |  2 +-
Bastien Nocera 49b48d2
 2 files changed, 2 insertions(+), 40 deletions(-)
Bastien Nocera 49b48d2
Bastien Nocera 49b48d2
diff --git a/backend/comics/comics-document.c b/backend/comics/comics-document.c
Bastien Nocera 49b48d2
index 4c747310..641d7856 100644
Bastien Nocera 49b48d2
--- a/backend/comics/comics-document.c
Bastien Nocera 49b48d2
+++ b/backend/comics/comics-document.c
Bastien Nocera 49b48d2
@@ -56,8 +56,7 @@ typedef enum
Bastien Nocera 49b48d2
 	RARLABS,
Bastien Nocera 49b48d2
 	GNAUNRAR,
Bastien Nocera 49b48d2
 	UNZIP,
Bastien Nocera 49b48d2
-	P7ZIP,
Bastien Nocera 49b48d2
-	TAR
Bastien Nocera 49b48d2
+	P7ZIP
Bastien Nocera 49b48d2
 } ComicBookDecompressType;
Bastien Nocera 49b48d2
 
Bastien Nocera 49b48d2
 typedef struct _ComicsDocumentClass ComicsDocumentClass;
Bastien Nocera 49b48d2
@@ -117,9 +116,6 @@ static const ComicBookDecompressCommand command_usage_def[] = {
Bastien Nocera 49b48d2
 
Bastien Nocera 49b48d2
         /* 7zip */
Bastien Nocera 49b48d2
 	{NULL               , "%s l -- %s"     , "%s x -y %s -o%s", FALSE, OFFSET_7Z},
Bastien Nocera 49b48d2
-
Bastien Nocera 49b48d2
-        /* tar */
Bastien Nocera 49b48d2
-	{"%s -xOf"          , "%s -tf %s"      , NULL             , FALSE, NO_OFFSET}
Bastien Nocera 49b48d2
 };
Bastien Nocera 49b48d2
 
Bastien Nocera 49b48d2
 static GSList*    get_supported_image_extensions (void);
Bastien Nocera 49b48d2
@@ -364,13 +360,6 @@ comics_check_decompress_command	(gchar          *mime_type,
Bastien Nocera 49b48d2
 			comics_document->command_usage = GNAUNRAR;
Bastien Nocera 49b48d2
 			return TRUE;
Bastien Nocera 49b48d2
 		}
Bastien Nocera 49b48d2
-		comics_document->selected_command =
Bastien Nocera 49b48d2
-				g_find_program_in_path ("bsdtar");
Bastien Nocera 49b48d2
-		if (comics_document->selected_command) {
Bastien Nocera 49b48d2
-			comics_document->command_usage = TAR;
Bastien Nocera 49b48d2
-			return TRUE;
Bastien Nocera 49b48d2
-		}
Bastien Nocera 49b48d2
-
Bastien Nocera 49b48d2
 	} else if (g_content_type_is_a (mime_type, "application/x-cbz") ||
Bastien Nocera 49b48d2
 		   g_content_type_is_a (mime_type, "application/zip")) {
Bastien Nocera 49b48d2
 		/* InfoZIP's unzip program */
Bastien Nocera 49b48d2
@@ -396,12 +385,6 @@ comics_check_decompress_command	(gchar          *mime_type,
Bastien Nocera 49b48d2
 			comics_document->command_usage = P7ZIP;
Bastien Nocera 49b48d2
 			return TRUE;
Bastien Nocera 49b48d2
 		}
Bastien Nocera 49b48d2
-		comics_document->selected_command =
Bastien Nocera 49b48d2
-				g_find_program_in_path ("bsdtar");
Bastien Nocera 49b48d2
-		if (comics_document->selected_command) {
Bastien Nocera 49b48d2
-			comics_document->command_usage = TAR;
Bastien Nocera 49b48d2
-			return TRUE;
Bastien Nocera 49b48d2
-		}
Bastien Nocera 49b48d2
 
Bastien Nocera 49b48d2
 	} else if (g_content_type_is_a (mime_type, "application/x-cb7") ||
Bastien Nocera 49b48d2
 		   g_content_type_is_a (mime_type, "application/x-7z-compressed")) {
Bastien Nocera 49b48d2
@@ -425,27 +408,6 @@ comics_check_decompress_command	(gchar          *mime_type,
Bastien Nocera 49b48d2
 			comics_document->command_usage = P7ZIP;
Bastien Nocera 49b48d2
 			return TRUE;
Bastien Nocera 49b48d2
 		}
Bastien Nocera 49b48d2
-		comics_document->selected_command =
Bastien Nocera 49b48d2
-				g_find_program_in_path ("bsdtar");
Bastien Nocera 49b48d2
-		if (comics_document->selected_command) {
Bastien Nocera 49b48d2
-			comics_document->command_usage = TAR;
Bastien Nocera 49b48d2
-			return TRUE;
Bastien Nocera 49b48d2
-		}
Bastien Nocera 49b48d2
-	} else if (g_content_type_is_a (mime_type, "application/x-cbt") ||
Bastien Nocera 49b48d2
-		   g_content_type_is_a (mime_type, "application/x-tar")) {
Bastien Nocera 49b48d2
-		/* tar utility (Tape ARchive) */
Bastien Nocera 49b48d2
-		comics_document->selected_command =
Bastien Nocera 49b48d2
-				g_find_program_in_path ("tar");
Bastien Nocera 49b48d2
-		if (comics_document->selected_command) {
Bastien Nocera 49b48d2
-			comics_document->command_usage = TAR;
Bastien Nocera 49b48d2
-			return TRUE;
Bastien Nocera 49b48d2
-		}
Bastien Nocera 49b48d2
-		comics_document->selected_command =
Bastien Nocera 49b48d2
-				g_find_program_in_path ("bsdtar");
Bastien Nocera 49b48d2
-		if (comics_document->selected_command) {
Bastien Nocera 49b48d2
-			comics_document->command_usage = TAR;
Bastien Nocera 49b48d2
-			return TRUE;
Bastien Nocera 49b48d2
-		}
Bastien Nocera 49b48d2
 	} else {
Bastien Nocera 49b48d2
 		g_set_error (error,
Bastien Nocera 49b48d2
 			     EV_DOCUMENT_ERROR,
Bastien Nocera 49b48d2
diff --git a/configure.ac b/configure.ac
Bastien Nocera 49b48d2
index 9e9f8316..7eb0f1f3 100644
Bastien Nocera 49b48d2
--- a/configure.ac
Bastien Nocera 49b48d2
+++ b/configure.ac
Bastien Nocera 49b48d2
@@ -795,7 +795,7 @@ AC_SUBST(TIFF_MIME_TYPES)
Bastien Nocera 49b48d2
 AC_SUBST(APPDATA_TIFF_MIME_TYPES)
Bastien Nocera 49b48d2
 AM_SUBST_NOTMAKE(APPDATA_TIFF_MIME_TYPES)
Bastien Nocera 49b48d2
 if test "x$enable_comics" = "xyes"; then
Bastien Nocera 49b48d2
-        COMICS_MIME_TYPES="application/x-cbr;application/x-cbz;application/x-cb7;application/x-cbt;application/x-ext-cbr;application/x-ext-cbz;application/vnd.comicbook+zip;application/x-ext-cb7;application/x-ext-cbt"
7792b0d
+        COMICS_MIME_TYPES="application/x-cbr;application/x-cbz;application/x-cb7;application/x-ext-cbr;application/x-ext-cbz;application/vnd.comicbook+zip;application/x-ext-cb7"
Bastien Nocera 49b48d2
         APPDATA_COMICS_MIME_TYPES=$(echo "<mimetype>$COMICS_MIME_TYPES</mimetype>" | sed -e 's/;/<\/mimetype>\n    <mimetype>/g')
Bastien Nocera 49b48d2
         if test -z "$EVINCE_MIME_TYPES"; then
Bastien Nocera 49b48d2
            EVINCE_MIME_TYPES="${COMICS_MIME_TYPES}"
Bastien Nocera 49b48d2
-- 
Bastien Nocera 49b48d2
2.13.0
Bastien Nocera 49b48d2