From ef11ceb0ae59b2fefbb23e6670ef6adca3e3a048 Mon Sep 17 00:00:00 2001 From: Sebastien Buisson Date: Mon, 27 Mar 2023 10:46:07 +0200 Subject: [PATCH] LU-16670 enc: make sure DoM files are correctly decrypted Make sure DoM files are decrypted upon read by loading their associated encryption context, via llcrypt_prepare_readdir()/ llcrypt_get_encryption_info(). Fix sanity-sec test_50 accordingly. Lustre-change: https://review.whamcloud.com/50429 Lustre-commit: 1c424252d37c64e3c223c19dced3cad2649c1f61 Signed-off-by: Sebastien Buisson Change-Id: Ie9ef3cbb08d2295a2fd10b9e9ab0862119c7723e Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/50430 Reviewed-by: Oleg Drokin Reviewed-by: Andreas Dilger Tested-by: jenkins Tested-by: Maloo --- lustre/llite/file.c | 5 +++-- lustre/llite/namei.c | 4 +--- lustre/tests/sanity-sec.sh | 26 +++++++++++++------------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/lustre/llite/file.c b/lustre/llite/file.c index db556b5..e7ecc77 100644 --- a/lustre/llite/file.c +++ b/lustre/llite/file.c @@ -463,10 +463,11 @@ static inline int ll_dom_readpage(void *data, struct page *page) kunmap_atomic(kaddr); if (inode && IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode)) { - if (!llcrypt_has_encryption_key(inode)) + if (!llcrypt_has_encryption_key(inode)) { CDEBUG(D_SEC, "no enc key for "DFID"\n", PFID(ll_inode2fid(inode))); - else { + rc = -ENOKEY; + } else { unsigned int offs = 0; while (offs < PAGE_SIZE) { diff --git a/lustre/llite/namei.c b/lustre/llite/namei.c index 6ad8770..0bcc053 100644 --- a/lustre/llite/namei.c +++ b/lustre/llite/namei.c @@ -761,8 +761,6 @@ static int ll_lookup_it_finish(struct ptlrpc_request *request, rc = llcrypt_get_encryption_info(inode); if (rc) GOTO(out, rc); - if (!llcrypt_has_encryption_key(inode)) - GOTO(out, rc = -ENOKEY); } } else if (!it_disposition(it, DISP_OPEN_CREATE)) { /* @@ -1230,6 +1228,7 @@ static int ll_atomic_open(struct inode *dir, struct dentry *dentry, rc = llcrypt_get_encryption_info(dir); if (rc) GOTO(out_release, rc); + encrypt = true; if (open_flags & O_CREAT) { /* For migration or mirroring without enc key, we still * need to be able to create a volatile file. @@ -1240,7 +1239,6 @@ static int ll_atomic_open(struct inode *dir, struct dentry *dentry, (open_flags & O_FILE_ENC) != O_FILE_ENC || !(open_flags & O_DIRECT))) GOTO(out_release, rc = -ENOKEY); - encrypt = true; } } diff --git a/lustre/tests/sanity-sec.sh b/lustre/tests/sanity-sec.sh index 7d4dabc..0d5670c 100755 --- a/lustre/tests/sanity-sec.sh +++ b/lustre/tests/sanity-sec.sh @@ -3946,7 +3946,7 @@ test_50() { cmp -bl $tmpfile $testfile || error "file $testfile is corrupted in memory" - cancel_lru_locks osc ; cancel_lru_locks mdc + remove_enc_key ; insert_enc_key # check that file read from server is correct cmp -bl $tmpfile $testfile || @@ -3955,7 +3955,7 @@ test_50() { # decrease size: truncate to PAGE_SIZE $TRUNCATE $tmpfile $pagesz $TRUNCATE $testfile $pagesz - cancel_lru_locks osc ; cancel_lru_locks mdc + remove_enc_key ; insert_enc_key cmp -bl $tmpfile $testfile || error "file $testfile is corrupted (1)" @@ -3963,7 +3963,7 @@ test_50() { sz=$((pagesz*2)) $TRUNCATE $tmpfile $sz $TRUNCATE $testfile $sz - cancel_lru_locks osc ; cancel_lru_locks mdc + remove_enc_key ; insert_enc_key cmp -bl $tmpfile $testfile || error "file $testfile is corrupted (2)" @@ -3971,7 +3971,7 @@ test_50() { sz=$((pagesz/2)) $TRUNCATE $tmpfile $sz $TRUNCATE $testfile $sz - cancel_lru_locks osc ; cancel_lru_locks mdc + remove_enc_key ; insert_enc_key cmp -bl $tmpfile $testfile || error "file $testfile is corrupted (3)" @@ -3979,7 +3979,7 @@ test_50() { sz=$((sz-7)) $TRUNCATE $tmpfile $sz $TRUNCATE $testfile $sz - cancel_lru_locks osc ; cancel_lru_locks mdc + remove_enc_key ; insert_enc_key cmp -bl $tmpfile $testfile || error "file $testfile is corrupted (4)" @@ -3987,7 +3987,7 @@ test_50() { sz=$((sz+18)) $TRUNCATE $tmpfile $sz $TRUNCATE $testfile $sz - cancel_lru_locks osc ; cancel_lru_locks mdc + remove_enc_key ; insert_enc_key cmp -bl $tmpfile $testfile || error "file $testfile is corrupted (5)" @@ -3995,12 +3995,12 @@ test_50() { sz=$((sz+pagesz+30)) $TRUNCATE $tmpfile $sz $TRUNCATE $testfile $sz - cancel_lru_locks osc ; cancel_lru_locks mdc + remove_enc_key ; insert_enc_key cmp -bl $tmpfile $testfile || error "file $testfile is corrupted (6)" rm -f $testfile - cancel_lru_locks osc ; cancel_lru_locks mdc + remove_enc_key ; insert_enc_key # write hole in file, data spread on MDT and OST tr '\0' '2' < /dev/zero | @@ -4012,7 +4012,7 @@ test_50() { cmp -bl $tmpfile $testfile || error "file $testfile is corrupted in memory" - cancel_lru_locks osc ; cancel_lru_locks mdc + remove_enc_key ; insert_enc_key # check that file read from server is correct cmp -bl $tmpfile $testfile || @@ -4023,7 +4023,7 @@ test_50() { sz=$((1024*1024+13)) $TRUNCATE $tmpfile $sz $TRUNCATE $testfile $sz - cancel_lru_locks osc ; cancel_lru_locks mdc + remove_enc_key ; insert_enc_key cmp -bl $tmpfile $testfile || error "file $testfile is corrupted (7)" @@ -4032,7 +4032,7 @@ test_50() { sz=7 $TRUNCATE $tmpfile $sz $TRUNCATE $testfile $sz - cancel_lru_locks osc ; cancel_lru_locks mdc + remove_enc_key ; insert_enc_key cmp -bl $tmpfile $testfile || error "file $testfile is corrupted (8)" @@ -4041,7 +4041,7 @@ test_50() { sz=$((1024*1024-13)) $TRUNCATE $tmpfile $sz $TRUNCATE $testfile $sz - cancel_lru_locks osc ; cancel_lru_locks mdc + remove_enc_key ; insert_enc_key cmp -bl $tmpfile $testfile || error "file $testfile is corrupted (9)" @@ -4050,7 +4050,7 @@ test_50() { sz=$((1024*1024+7)) $TRUNCATE $tmpfile $sz $TRUNCATE $testfile $sz - cancel_lru_locks osc ; cancel_lru_locks mdc + remove_enc_key ; insert_enc_key cmp -bl $tmpfile $testfile || error "file $testfile is corrupted (10)" -- 1.8.3.1