Skip to content

Commit b5695d0

Browse files
Roberto SassuTyler Hicks
authored andcommitted
eCryptfs: write lock requested keys
A requested key is write locked in order to prevent modifications on the authentication token while it is being used. Signed-off-by: Roberto Sassu <roberto.sassu@polito.it> Signed-off-by: Tyler Hicks <tyhicks@linux.vnet.ibm.com>
1 parent 950983f commit b5695d0

2 files changed

Lines changed: 23 additions & 7 deletions

File tree

‎fs/ecryptfs/keystore.c‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -516,17 +516,20 @@ ecryptfs_find_global_auth_tok_for_sig(
516516
goto out_invalid_auth_tok;
517517
}
518518

519+
down_write(&(walker->global_auth_tok_key->sem));
519520
rc = ecryptfs_verify_auth_tok_from_key(
520521
walker->global_auth_tok_key, auth_tok);
521522
if (rc)
522-
goto out_invalid_auth_tok;
523+
goto out_invalid_auth_tok_unlock;
523524

524525
(*auth_tok_key) = walker->global_auth_tok_key;
525526
key_get(*auth_tok_key);
526527
goto out;
527528
}
528529
rc = -ENOENT;
529530
goto out;
531+
out_invalid_auth_tok_unlock:
532+
up_write(&(walker->global_auth_tok_key->sem));
530533
out_invalid_auth_tok:
531534
printk(KERN_WARNING "Invalidating auth tok with sig = [%s]\n", sig);
532535
walker->flags |= ECRYPTFS_AUTH_TOK_INVALID;
@@ -869,8 +872,10 @@ ecryptfs_write_tag_70_packet(char *dest, size_t *remaining_bytes,
869872
out_unlock:
870873
mutex_unlock(s->tfm_mutex);
871874
out:
872-
if (auth_tok_key)
875+
if (auth_tok_key) {
876+
up_write(&(auth_tok_key->sem));
873877
key_put(auth_tok_key);
878+
}
874879
kfree(s);
875880
return rc;
876881
}
@@ -1106,8 +1111,10 @@ ecryptfs_parse_tag_70_packet(char **filename, size_t *filename_size,
11061111
(*filename_size) = 0;
11071112
(*filename) = NULL;
11081113
}
1109-
if (auth_tok_key)
1114+
if (auth_tok_key) {
1115+
up_write(&(auth_tok_key->sem));
11101116
key_put(auth_tok_key);
1117+
}
11111118
kfree(s);
11121119
return rc;
11131120
}
@@ -1638,9 +1645,10 @@ int ecryptfs_keyring_auth_tok_for_sig(struct key **auth_tok_key,
16381645
(*auth_tok_key) = NULL;
16391646
goto out;
16401647
}
1641-
1648+
down_write(&(*auth_tok_key)->sem);
16421649
rc = ecryptfs_verify_auth_tok_from_key(*auth_tok_key, auth_tok);
16431650
if (rc) {
1651+
up_write(&(*auth_tok_key)->sem);
16441652
key_put(*auth_tok_key);
16451653
(*auth_tok_key) = NULL;
16461654
goto out;
@@ -1865,6 +1873,7 @@ int ecryptfs_parse_packet_set(struct ecryptfs_crypt_stat *crypt_stat,
18651873
find_next_matching_auth_tok:
18661874
found_auth_tok = 0;
18671875
if (auth_tok_key) {
1876+
up_write(&(auth_tok_key->sem));
18681877
key_put(auth_tok_key);
18691878
auth_tok_key = NULL;
18701879
}
@@ -1951,8 +1960,10 @@ int ecryptfs_parse_packet_set(struct ecryptfs_crypt_stat *crypt_stat,
19511960
out_wipe_list:
19521961
wipe_auth_tok_list(&auth_tok_list);
19531962
out:
1954-
if (auth_tok_key)
1963+
if (auth_tok_key) {
1964+
up_write(&(auth_tok_key->sem));
19551965
key_put(auth_tok_key);
1966+
}
19561967
return rc;
19571968
}
19581969

@@ -2446,6 +2457,7 @@ ecryptfs_generate_key_packet_set(char *dest_base,
24462457
rc = -EINVAL;
24472458
goto out_free;
24482459
}
2460+
up_write(&(auth_tok_key->sem));
24492461
key_put(auth_tok_key);
24502462
auth_tok_key = NULL;
24512463
}
@@ -2460,8 +2472,10 @@ ecryptfs_generate_key_packet_set(char *dest_base,
24602472
out:
24612473
if (rc)
24622474
(*len) = 0;
2463-
if (auth_tok_key)
2475+
if (auth_tok_key) {
2476+
up_write(&(auth_tok_key->sem));
24642477
key_put(auth_tok_key);
2478+
}
24652479

24662480
mutex_unlock(&crypt_stat->keysig_list_mutex);
24672481
return rc;

‎fs/ecryptfs/main.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,10 @@ static int ecryptfs_init_global_auth_toks(
254254
"option: [%s]\n", global_auth_tok->sig);
255255
global_auth_tok->flags |= ECRYPTFS_AUTH_TOK_INVALID;
256256
goto out;
257-
} else
257+
} else {
258258
global_auth_tok->flags &= ~ECRYPTFS_AUTH_TOK_INVALID;
259+
up_write(&(global_auth_tok->global_auth_tok_key)->sem);
260+
}
259261
}
260262
out:
261263
return rc;

0 commit comments

Comments
 (0)