Whamcloud - gitweb
LU-16670 enc: make sure DoM files are correctly decrypted 29/50429/5
authorSebastien Buisson <sbuisson@ddn.com>
Mon, 27 Mar 2023 08:46:07 +0000 (10:46 +0200)
committerOleg Drokin <green@whamcloud.com>
Tue, 18 Apr 2023 03:22:43 +0000 (03:22 +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.

Signed-off-by: Sebastien Buisson <sbuisson@ddn.com>
Change-Id: Ie9ef3cbb08d2295a2fd10b9e9ab0862119c7723e
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/50429
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Patrick Farrell <pfarrell@whamcloud.com>
Reviewed-by: Mikhail Pershin <mpershin@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/llite/file.c
lustre/llite/namei.c
lustre/tests/sanity-sec.sh

index c672b2b..5d70521 100644 (file)
@@ -458,15 +458,14 @@ static inline int ll_dom_readpage(void *data, struct page *page)
        if (lnb->lnb_len < PAGE_SIZE)
                memset(kaddr + lnb->lnb_len, 0,
                       PAGE_SIZE - lnb->lnb_len);
-       flush_dcache_page(page);
-       SetPageUptodate(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) {
@@ -486,6 +485,10 @@ static inline int ll_dom_readpage(void *data, struct page *page)
                        }
                }
        }
+       if (!rc) {
+               flush_dcache_page(page);
+               SetPageUptodate(page);
+       }
        unlock_page(page);
 
        return rc;
index 2f0aebd..eb06ecd 100644 (file)
@@ -759,8 +759,6 @@ static int ll_lookup_it_finish(struct ptlrpc_request *request,
                        rc = llcrypt_prepare_readdir(inode);
                        if (rc)
                                GOTO(out, rc);
-                       if (!llcrypt_has_encryption_key(inode))
-                               GOTO(out, rc = -ENOKEY);
                }
        } else if (!it_disposition(it, DISP_OPEN_CREATE)) {
                /*
@@ -1218,6 +1216,7 @@ static int ll_atomic_open(struct inode *dir, struct dentry *dentry,
                rc = llcrypt_prepare_readdir(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.
@@ -1228,7 +1227,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 546f8e7..fa99f98 100755 (executable)
@@ -3981,7 +3981,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 ||
@@ -3990,7 +3990,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)"
 
@@ -3998,7 +3998,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)"
 
@@ -4006,7 +4006,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)"
 
@@ -4014,7 +4014,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)"
 
@@ -4022,7 +4022,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)"
 
@@ -4030,12 +4030,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 |
@@ -4047,7 +4047,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 ||
@@ -4058,7 +4058,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)"
 
@@ -4067,7 +4067,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)"
 
@@ -4076,7 +4076,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)"
 
@@ -4085,7 +4085,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)"