Received: from list by lists.gnu.org with archive (Exim 4.71) id 1dLaZM-0004G1-5S for mharc-grub-devel@gnu.org; Thu, 15 Jun 2017 15:36:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42783) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dLaZI-0004Ew-IZ for grub-devel@gnu.org; Thu, 15 Jun 2017 15:36:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dLaZF-0006dN-B6 for grub-devel@gnu.org; Thu, 15 Jun 2017 15:36:36 -0400 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]:32785) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dLaZF-0006cQ-3M for grub-devel@gnu.org; Thu, 15 Jun 2017 15:36:33 -0400 Received: by mail-pg0-x244.google.com with SMTP id a70so2653827pge.0 for ; Thu, 15 Jun 2017 12:36:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=A6DjZU2PO5ms3nZVFyoWI0W3Q7TCbvUi36xMlABPNjA=; b=WJRqVXli+f6XaVOsmle/ioqURdFHlcVe0AejquYcyQyIVuVg7X/25mkZ4C0HfjzMK7 5T7LoRI7t16u21LSDnb2fBWOedQ+0Z8/3NU7X1PgOfpq3+tV5hG1XyQoxlw/JWIF9lfX oO3RRr8lCIhKalYX2dzvv7p4WGCXTm8sXkgvyw68sJvj7NJI/BV5oFuFCksxv/AYfSZ4 rfNCZtcab/PTDP+yEKWwSDgRuk032HGgLvPxP6U838o4QDMLHckSw4i1GrkuIzn26vT+ jK4NdHEKYrWERTygGLQ6MoRnK7xPXJiooAFArwM9y9gBaULWeHnKsdWDoiyiaTt3xjvJ 19fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=A6DjZU2PO5ms3nZVFyoWI0W3Q7TCbvUi36xMlABPNjA=; b=BNZRyloBrCgWwzxwp8tH04ijAyOCmr1q4vDvBZuOvehtCEbWLyMz7nvzU+0hP5Derw SVpcrcTQKgkbo1jZKS9mxpEa5dc1tO1TPmI7NnIN46k+6NdJHho7H/sVl4nVARymD3iM I8WEuzTTVlE4rrAl0GiVsoaIwKW2Ivz9VDtjeVs7TOUWNCzK5Hg2Jx0F9ROhF948EK3w YqIBNZ8f00ZtefMEuIROdEfqaKEokV8aaoNLtf+F9qiRDest4m9q5s99SxbM8IoEwfkY si7pz4/osaTRd8Ful9FzckXJOISRlOZY04hB6XFFHx38PrYp3FJ8Flu0TM7oeanF3jUf 7+KQ== X-Gm-Message-State: AKS2vOxM1GqFBe4WhABFb9w3Sp9vwPC7iIfE/NSJW+xKcQ9IaE+WIsXN qyo1/wsAc3Uy3GfMLiQ= X-Received: by 10.84.214.150 with SMTP id j22mr8009224pli.137.1497555391864; Thu, 15 Jun 2017 12:36:31 -0700 (PDT) Received: from zzz.hsd1.wa.comcast.net (c-73-239-167-150.hsd1.wa.comcast.net. [73.239.167.150]) by smtp.gmail.com with ESMTPSA id z4sm134528pgc.22.2017.06.15.12.36.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Jun 2017 12:36:30 -0700 (PDT) From: Eric Biggers To: grub-devel@gnu.org Cc: Eric Biggers Subject: [PATCH v2] ext2: support EXT4_FEATURE_INCOMPAT_ENCRYPT Date: Thu, 15 Jun 2017 12:34:32 -0700 Message-Id: <20170615193432.19823-1-ebiggers3@gmail.com> X-Mailer: git-send-email 2.13.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::244 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Jun 2017 19:36:39 -0000 From: Eric Biggers Allow GRUB to mount ext2/3/4 filesystems that have the encryption feature. On such a filesystem, inodes may have EXT4_ENCRYPT_FLAG set. For a regular file, this means its contents are encrypted; for a directory, this means the filenames in its directory entries are encrypted; and for a symlink, this means its target is encrypted. Since GRUB cannot decrypt encrypted contents or filenames, just issue an error if it would need to do so. This is sufficient to allow unencrypted boot files to co-exist with encrypted files elsewhere on the filesystem. (Note that encrypted regular files and symlinks will not normally be encountered outside an encrypted directory; however, it's possible via hard links, so they still need to be handled.) Tested by booting from an ext4 /boot partition on which I had run 'tune2fs -O encrypt'. I also verified that the expected error messages are printed when trying to access encrypted directories, files, and symlinks from the GRUB command line. Also ran 'sudo ./grub-fs-tester ext4_encrypt'; note that this requires e2fsprogs v1.43+ and Linux v4.1+. Signed-off-by: Eric Biggers --- v2: don't mark the error messages for translation, and test '-O encrypt' in grub-fs-tester. grub-core/fs/ext2.c | 23 ++++++++++++++++++++++- tests/ext234_test.in | 1 + tests/util/grub-fs-tester.in | 10 ++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/grub-core/fs/ext2.c b/grub-core/fs/ext2.c index cdce63bcc..ac6b7220a 100644 --- a/grub-core/fs/ext2.c +++ b/grub-core/fs/ext2.c @@ -102,6 +102,7 @@ GRUB_MOD_LICENSE ("GPLv3+"); #define EXT4_FEATURE_INCOMPAT_64BIT 0x0080 #define EXT4_FEATURE_INCOMPAT_MMP 0x0100 #define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200 +#define EXT4_FEATURE_INCOMPAT_ENCRYPT 0x10000 /* The set of back-incompatible features this driver DOES support. Add (OR) * flags here as the related features are implemented into the driver. */ @@ -109,7 +110,8 @@ GRUB_MOD_LICENSE ("GPLv3+"); | EXT4_FEATURE_INCOMPAT_EXTENTS \ | EXT4_FEATURE_INCOMPAT_FLEX_BG \ | EXT2_FEATURE_INCOMPAT_META_BG \ - | EXT4_FEATURE_INCOMPAT_64BIT) + | EXT4_FEATURE_INCOMPAT_64BIT \ + | EXT4_FEATURE_INCOMPAT_ENCRYPT) /* List of rationales for the ignored "incompatible" features: * needs_recovery: Not really back-incompatible - was added as such to forbid * ext2 drivers from mounting an ext3 volume with a dirty @@ -138,6 +140,7 @@ GRUB_MOD_LICENSE ("GPLv3+"); #define EXT3_JOURNAL_FLAG_DELETED 4 #define EXT3_JOURNAL_FLAG_LAST_TAG 8 +#define EXT4_ENCRYPT_FLAG 0x800 #define EXT4_EXTENTS_FLAG 0x80000 /* The ext2 superblock. */ @@ -706,6 +709,12 @@ grub_ext2_read_symlink (grub_fshelp_node_t node) grub_ext2_read_inode (diro->data, diro->ino, &diro->inode); if (grub_errno) return 0; + + if (diro->inode.flags & grub_cpu_to_le32_compile_time (EXT4_ENCRYPT_FLAG)) + { + grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "symlink is encrypted"); + return 0; + } } symlink = grub_malloc (grub_le_to_cpu32 (diro->inode.size) + 1); @@ -749,6 +758,12 @@ grub_ext2_iterate_dir (grub_fshelp_node_t dir, return 0; } + if (diro->inode.flags & grub_cpu_to_le32_compile_time (EXT4_ENCRYPT_FLAG)) + { + grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "directory is encrypted"); + return 0; + } + /* Search the file. */ while (fpos < grub_le_to_cpu32 (diro->inode.size)) { @@ -859,6 +874,12 @@ grub_ext2_open (struct grub_file *file, const char *name) goto fail; } + if (fdiro->inode.flags & grub_cpu_to_le32_compile_time (EXT4_ENCRYPT_FLAG)) + { + err = grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "file is encrypted"); + goto fail; + } + grub_memcpy (data->inode, &fdiro->inode, sizeof (struct grub_ext2_inode)); grub_free (fdiro); diff --git a/tests/ext234_test.in b/tests/ext234_test.in index 892b99cbd..4f1eb527e 100644 --- a/tests/ext234_test.in +++ b/tests/ext234_test.in @@ -30,3 +30,4 @@ fi "@builddir@/grub-fs-tester" ext3 "@builddir@/grub-fs-tester" ext4 "@builddir@/grub-fs-tester" ext4_metabg +"@builddir@/grub-fs-tester" ext4_encrypt diff --git a/tests/util/grub-fs-tester.in b/tests/util/grub-fs-tester.in index 88cbe7365..6d21705c5 100644 --- a/tests/util/grub-fs-tester.in +++ b/tests/util/grub-fs-tester.in @@ -156,6 +156,12 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do # Could go further but what's the point? MAXBLKSIZE=$((65536*1024)) ;; + xext4_encrypt) + # OS LIMITATION: Linux currently only allows the 'encrypt' feature + # in combination with block_size = PAGE_SIZE (4096 bytes on x86). + MINBLKSIZE=$(getconf PAGE_SIZE) + MAXBLKSIZE=$MINBLKSIZE + ;; xext*) MINBLKSIZE=1024 if [ $MINBLKSIZE -lt $SECSIZE ]; then @@ -796,6 +802,10 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do MKE2FS_DEVICE_SECTSIZE=$SECSIZE "mkfs.ext4" -O meta_bg,^resize_inode -b $BLKSIZE -L "$FSLABEL" -q "${MOUNTDEVICE}" MOUNTFS=ext4 ;; + xext4_encrypt) + MKE2FS_DEVICE_SECTSIZE=$SECSIZE "mkfs.ext4" -O encrypt -b $BLKSIZE -L "$FSLABEL" -q "${MOUNTDEVICE}" + MOUNTFS=ext4 + ;; xext*) MKE2FS_DEVICE_SECTSIZE=$SECSIZE "mkfs.$fs" -b $BLKSIZE -L "$FSLABEL" -q "${MOUNTDEVICE}" ;; xxfs) -- 2.13.1