lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20190109012701.26441-14-mark@harmstone.com>
Date:   Wed,  9 Jan 2019 01:26:56 +0000
From:   Mark Harmstone <mark@...mstone.com>
To:     unlisted-recipients:; (no To-header on input)
Cc:     mark@...mstone.com, Chris Mason <clm@...com>,
        Josef Bacik <josef@...icpanda.com>,
        David Sterba <dsterba@...e.com>, linux-btrfs@...r.kernel.org,
        linux-kernel@...r.kernel.org
Subject: [RFC PATCH 14/19] btrfs: allow reading compressed encrypted extents

Signed-off-by: Mark Harmstone <mark@...mstone.com>
---
 fs/btrfs/compression.c | 22 ++++++++++++++++++++++
 fs/btrfs/compression.h |  7 +++++++
 2 files changed, 29 insertions(+)

diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index 2955a4ea2fa8..55d7b97a7dc9 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -26,6 +26,7 @@
 #include "compression.h"
 #include "extent_io.h"
 #include "extent_map.h"
+#include "encryption.h"
 
 static const char* const btrfs_compress_types[] = { "", "zlib", "lzo", "zstd" };
 
@@ -139,6 +140,20 @@ static void end_compressed_bio_read(struct bio *bio)
 	if (ret)
 		goto csum_failed;
 
+	if (cb->key_number != 0) {
+		struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
+		unsigned int i;
+
+		for (i = 0; i < cb->nr_pages; i++) {
+			ret = btrfs_decrypt_page(fs_info,
+				cb->compressed_pages[i], cb->key_number,
+				cb->iv);
+
+			if (ret)
+				goto csum_failed;
+		}
+	}
+
 	/* ok, we're the last bio for this extent, lets start
 	 * the decompression.
 	 */
@@ -568,6 +583,13 @@ blk_status_t btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
 	em_len = em->len;
 	em_start = em->start;
 
+	if (em->encrypt_type == BTRFS_ENCRYPTION_NONE) {
+		cb->key_number = 0;
+	} else {
+		cb->key_number = em->key_number;
+		memcpy(cb->iv, em->iv, BTRFS_ENCRYPTION_BLOCK_LENGTH);
+	}
+
 	free_extent_map(em);
 	em = NULL;
 
diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h
index ddda9b80bf20..86a536d8cd5f 100644
--- a/fs/btrfs/compression.h
+++ b/fs/btrfs/compression.h
@@ -7,6 +7,7 @@
 #define BTRFS_COMPRESSION_H
 
 #include <linux/sizes.h>
+#include <linux/btrfs_tree.h>
 
 /*
  * We want to make sure that amount of RAM required to uncompress an extent is
@@ -54,6 +55,12 @@ struct compressed_bio {
 	int errors;
 	int mirror_num;
 
+	/* encryption key number */
+	u64 key_number;
+
+	/* encryption initialization vector */
+	char iv[BTRFS_ENCRYPTION_BLOCK_LENGTH];
+
 	/* for reads, this is the bio we are copying the data into */
 	struct bio *orig_bio;
 
-- 
2.19.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ