-
Notifications
You must be signed in to change notification settings - Fork 67
8727 Native data and metadata encryption for zfs #124
Conversation
|
Can one of the admins verify this patch? |
|
@zettabot go |
| @@ -39,7 +39,7 @@ MODSRCS_DIR = ../../../common/modules/zfs | |||
| GENUNIX_DIR = ../../../common/modules/genunix | |||
|
|
|||
| CPPFLAGS += -I../../../../../lib/libzpool/common \ | |||
| -I../../../../../uts/common/fs/zfs | |||
| -I../../../../../uts/common/fs/zfs -I../../../../../common/zfs | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are a little easier to read (and manage later) if written one-per-line.
47c1067 to
5e1f9c1
Compare
|
@zettabot go |
usr/src/cmd/zfs/zfs_main.c
Outdated
| @@ -204,6 +206,7 @@ static zfs_command_t command_table[] = { | |||
| { "holds", zfs_do_holds, HELP_HOLDS }, | |||
| { "release", zfs_do_release, HELP_RELEASE }, | |||
| { "diff", zfs_do_diff, HELP_DIFF }, | |||
| { "key", zfs_do_crypto, HELP_CRYPTO }, | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless there's a good reason, these 3 strings should have the same "x":
"x", zfs_do_x, HELP_X
It looks like the indentation is wrong here, but maybe that's just github.
|
One high-level question about this work: Is any of it derived from the old OpenSolaris "zfs-crypto" project? If so, can we get some references to (and/or differences from) the previous code? |
usr/src/uts/common/fs/zfs/dmu.c
Outdated
| { DMU_BSWAP_UINT64, TRUE, FALSE, "DSL deadlist map hdr" }, | ||
| { DMU_BSWAP_ZAP, TRUE, FALSE, "DSL dir clones" }, | ||
| { DMU_BSWAP_UINT64, TRUE, FALSE, "bpobj subobj" }, | ||
| { DMU_BSWAP_ZAP, TRUE, FALSE, "DSL Keychain" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless there's a really good reason, we should use the DMU_OTN_* types rather than adding a new object type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used DMU_OT_* because I wanted the DSL keychain to appear with a name in zdb. Of course, I can change this easily. May I ask what the reason is for not wanting to add more types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I know it isn't as nice for debugging :-(
The types here are statically allocated, so if someone else wants to add a new type, they would use the same enum value as you. Then it's impossible to integrate the two features into one codebase. For example, we have implemented several new features at Delphix that introduce new metadata objects. If we added new enum values here, we wouldn't be able to integrate both our features and your feature upstream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick question: I'm adding this change right now and everything works. Only problem is that zdb core dumps. The reason is that DSL Keychain is no longer a designated type. Instead it is now just a generic ZAP. As a result, zap_lookup() from dump_zap() panics because it should be using zap_lookup_uint64(). So my question is essentially what is the best way to fix this?
I can modify zap_dump_stats() to also return zap_phys_t->zap_flags in the zap stats. I could then look for this flag in dump_zap() . However, this gets messy because (technically) dump_zap() doesn't use the stats directly; it just calls dump_zap_stats(). So now dump_zap_stats() needs to return the flags by reference somehow (which is a messy) and all callers need to be changed to deal with this.
So should I do all of this work or leave DMU_OT_DSL_KEYCHAIN in the enum? Personally I still think being able to tell an object is a keychain in ZDB without looking for its parent is valuable as well, but that's just me.
EDIT:
To clarify what I meant above, in broader terms, with the DMU_OTN_* interface, we lose the ability to create behaviors for specific object types. Linux IOCTL definitions actually solve this exact problem by including a magic number bitmask However, they have 32 bits to work with and we have 8, so this probably won't help us much.
I see that this is a lot of text over a little zdb print function and I'm quickly leaving the scope of 'ZFS Encryption', so I can just make the change as I stated before, even if its not the cleanest code in the world. However, I think this topic will probably come up again sometime as people add new object types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about adding an accessor function to get both kinds of flags:
int zap_get_flags(objset_t *os, uint64_t object, int *normflagsp, zap_flags_t *flagsp);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did something a little different in the end. I added attr.za_binary_key boolean to the ZAP iterator API. Basically the field is set if the ZAP uses binary keys.
|
All the indention issues are just my emacs setting, I will get to fixing them. (Don't suppose there is an official .emacs for illumos? :) ) |
|
For those of you who don't know me, I am the person maintaining the original version of this PR in ZFS on Linux. I would like to apologize upfront for any style errors you might have found. I made a grievous mistake with my editor early in development and did not notice it for a long time.
It is to a small extent. When I first started working on this project I was using it as a reference. The first iteration of the changes in |
No idea what that means. looks like I missed |
|
Ok, I have done the indentation fixes, where I could find them, and also ran all the source files through I should point out I had to rewrite zdb.c logic pointing uint64_t to hopefully, I got it right |
4278e74 to
8748ffb
Compare
|
sorry to report that send/receive (see Aug. 18th/19th) still crashes when testing with more than 10GB of data: panic[cpu1]/thread=ffffff000faf4c40: ffffff000faf4750 unix:real_mode_stop_cpu_stage2_end+b21c () |
ad60b8f to
bc464bb
Compare
|
I think you missed this from ZOL in the latest update: diff --git a/usr/src/uts/common/fs/zfs/bptree.c b/usr/src/uts/common/fs/zfs/bptree.c
index c74d072..25c08f6 100644
--- a/usr/src/uts/common/fs/zfs/bptree.c
+++ b/usr/src/uts/common/fs/zfs/bptree.c
@@ -211,7 +211,8 @@ bptree_iterate(objset_t *os, uint64_t obj, boolean_t free, bptree_itor_t func,
err = 0;
for (i = ba.ba_phys->bt_begin; i < ba.ba_phys->bt_end; i++) {
bptree_entry_phys_t bte;
- int flags = TRAVERSE_PREFETCH_METADATA | TRAVERSE_POST;
+ int flags = TRAVERSE_PREFETCH_METADATA | TRAVERSE_POST |
+ TRAVERSE_NO_DECRYPT;
err = dmu_read(os, obj, i * sizeof (bte), sizeof (bte),
&bte, DMU_READ_NO_PREFETCH);(without it, after the recent change to turn async destroy back on for encrypted datasets, you get a panic) Matching code in ZOL at https://github.com/zfsonlinux/zfs/blob/master/module/zfs/bptree.c#L215 |
|
Ah well spotted, thanks! |
|
Re: the dump issues, doing this: diff --git a/usr/src/uts/common/fs/zfs/zvol.c b/usr/src/uts/common/fs/zfs/zvol.c
index c6a6338..080b2cd 100644
--- a/usr/src/uts/common/fs/zfs/zvol.c
+++ b/usr/src/uts/common/fs/zfs/zvol.c
@@ -2157,6 +2157,9 @@ zvol_dumpify(zvol_state_t *zv)
if (zv->zv_flags & ZVOL_RDONLY)
return (SET_ERROR(EROFS));
+ if (os->os_encrypted)
+ return (SET_ERROR(ENOTSUP));
+
if (zap_lookup(zv->zv_objset, ZVOL_ZAP_OBJ, ZVOL_DUMPSIZE,
8, 1, &dumpsize) != 0 || dumpsize != zv->zv_volsize) {
boolean_t resize = (dumpsize > 0);Seems to be good enough to guard against dumpifying encrypted zvols, preventing the panic. Attempting to use |
|
I prefer |
|
you can use 'print' instead of 'echo' - it is applicable for portability. |
|
I agree with everything you say, I already have had to change a quite a few things to the $ENV version on osx. It certainly would be nice if such a standard was agreed upon |
|
Looks like we managed to pass all tests finally. I plan to squash everything into one single commit unless there is some other number of commits people would prefer..? |
|
i think single commit will be fine. |
b4a2aaf to
6ce01a1
Compare
43e9d1a to
9bb6c76
Compare
This change incorporates three major pieces:
The first change is a keystore that manages wrapping
and encryption keys for encrypted datasets. These
commands mostly involve manipulating the new
DSL Crypto Key ZAP Objects that live in the MOS. Each
encrypted dataset has its own DSL Crypto Key that is
protected with a user's key. This level of indirection
allows users to change their keys without re-encrypting
their entire datasets. The change implements the new
subcommands "zfs load-key", "zfs unload-key" and
"zfs change-key" which allow the user to manage their
encryption keys and settings. In addition, several new
flags and properties have been added to allow dataset
creation and to make mounting and unmounting more
convenient.
The second piece of this patch provides the ability to
encrypt, decyrpt, and authenticate protected datasets.
Each object set maintains a Merkel tree of Message
Authentication Codes that protect the lower layers,
similarly to how checksums are maintained. This part
impacts the zio layer, which handles the actual
encryption and generation of MACs, as well as the ARC
and DMU, which need to be able to handle encrypted
buffers and protected data.
The last addition is the ability to do raw, encrypted
sends and receives. The idea here is to send raw
encrypted and compressed data and receive it exactly
as is on a backup system. This means that the dataset
on the receiving system is protected using the same
user key that is in use on the sending side. By doing
so, datasets can be efficiently backed up to an
untrusted system without fear of data being
compromised.
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Jorgen Lundman <lundman@lundman.net>
Signed-off-by: Tom Caputi <tcaputi@datto.com>
Send / Recv Fixes following b52563
This patch fixes several issues discovered after
the encryption patch was merged:
Fixed a bug where encrypted datasets could attempt
to receive embedded data records.
Fixed a bug where dirty records created by the recv
code wasn't properly setting the dr_raw flag.
Fixed a typo where a dmu_tx_commit() was changed to
dmu_tx_abort()
Fixed a few error handling bugs unrelated to the
encryption patch in dmu_recv_stream()
Signed-off-by: Tom Caputi <tcaputi@datto.com>
Encryption patch follow-up
* HKDF implementation moved to its own file and tests added to ensure
correctness.
* Ztest can now create and test encrypted datasets. This is currently
disabled until issue ZOL #6526 is resolved, but otherwise functions as
advertised.
* Several small bug fixes discovered after enabling ztest to run on
encrypted datasets.
* Fixed coverity defects added by the encryption patch.
* Updated man pages for encrypted send / receive behavior.
* Fixed a bug where encrypted datasets could receive
DRR_WRITE_EMBEDDED records.
* Minor code cleanups / consolidation.
Disable crypto tests in ztest
* Includes fix in dmu_free_long_object_impl
Unless permission is given to compile the crypto framework in userland
the crypto tests in ztest are disabled on IllumOS.
|
@lundman This PR is just the first encryption commit from ZoL, right? In that case please squash to one commit. To raise the visibility of this, you might open a new PR and mention in the description that you think this is ready to integrate, and also call for any additional help you might need (e.g. testing and code review?). |
|
@ahrens This is the first PR, followed by all fixes, two more PRs and fixes. It has everything in it that ZoL has. I don't think it is so much about what I need, but what you want to happen next. |
|
Closed in favour of #489 |
Original ZOL PR openzfs/zfs#5769