Whamcloud - gitweb
LU-16670 enc: make sure DoM files are correctly decrypted 30/50430/5
authorSebastien Buisson <sbuisson@ddn.com>
Mon, 27 Mar 2023 08:46:07 +0000 (10:46 +0200)
committerOleg Drokin <green@whamcloud.com>
Wed, 19 Apr 2023 03:31:56 +0000 (03:31 +0000)
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 <sbuisson@ddn.com>
Change-Id: Ie9ef3cbb08d2295a2fd10b9e9ab0862119c7723e
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/50430
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/llite/file.c
lustre/llite/namei.c
lustre/tests/sanity-sec.sh

index db556b5..e7ecc77 100644 (file)
@@ -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) {
index 6ad8770..0bcc053 100644 (file)
@@ -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;
                }
        }
 
index 7d4dabc..0d5670c 100755 (executable)
@@ -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)"