diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2019-07-14 22:29:04 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2019-07-14 22:29:04 -0400 |
commit | fa6e951a2a440babd7a7310d0f4713e618061767 (patch) | |
tree | 07adc018be439e33a0353169b93a7399dfad94cd | |
parent | a318423b61e8c67aa5c0a428540c58439a20baac (diff) | |
parent | 7451c54abc9139585492605d9e91dec2d26c6457 (diff) |
Merge tag 'ecryptfs-5.3-rc1-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tyhicks/ecryptfs
Pull eCryptfs updates from Tyler Hicks:
- Fix error handling when ecryptfs_read_lower() encounters an error
- Fix read-only file creation when the eCryptfs mount is configured to
store metadata in xattrs
- Minor code cleanups
* tag 'ecryptfs-5.3-rc1-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tyhicks/ecryptfs:
ecryptfs: Change return type of ecryptfs_process_flags
ecryptfs: Make ecryptfs_xattr_handler static
ecryptfs: remove unnessesary null check in ecryptfs_keyring_auth_tok_for_sig
ecryptfs: use print_hex_dump_bytes for hexdump
eCryptfs: fix permission denied with ecryptfs_xattr mount option when create readonly file
ecryptfs: re-order a condition for static checkers
eCryptfs: fix a couple type promotion bugs
-rw-r--r-- | fs/ecryptfs/crypto.c | 42 | ||||
-rw-r--r-- | fs/ecryptfs/debug.c | 22 | ||||
-rw-r--r-- | fs/ecryptfs/inode.c | 2 | ||||
-rw-r--r-- | fs/ecryptfs/keystore.c | 9 |
4 files changed, 34 insertions, 41 deletions
diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c index 91d65f337d87..f91db24bbf3b 100644 --- a/fs/ecryptfs/crypto.c +++ b/fs/ecryptfs/crypto.c | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <linux/slab.h> | 23 | #include <linux/slab.h> |
24 | #include <asm/unaligned.h> | 24 | #include <asm/unaligned.h> |
25 | #include <linux/kernel.h> | 25 | #include <linux/kernel.h> |
26 | #include <linux/xattr.h> | ||
26 | #include "ecryptfs_kernel.h" | 27 | #include "ecryptfs_kernel.h" |
27 | 28 | ||
28 | #define DECRYPT 0 | 29 | #define DECRYPT 0 |
@@ -860,13 +861,10 @@ static struct ecryptfs_flag_map_elem ecryptfs_flag_map[] = { | |||
860 | * @crypt_stat: The cryptographic context | 861 | * @crypt_stat: The cryptographic context |
861 | * @page_virt: Source data to be parsed | 862 | * @page_virt: Source data to be parsed |
862 | * @bytes_read: Updated with the number of bytes read | 863 | * @bytes_read: Updated with the number of bytes read |
863 | * | ||
864 | * Returns zero on success; non-zero if the flag set is invalid | ||
865 | */ | 864 | */ |
866 | static int ecryptfs_process_flags(struct ecryptfs_crypt_stat *crypt_stat, | 865 | static void ecryptfs_process_flags(struct ecryptfs_crypt_stat *crypt_stat, |
867 | char *page_virt, int *bytes_read) | 866 | char *page_virt, int *bytes_read) |
868 | { | 867 | { |
869 | int rc = 0; | ||
870 | int i; | 868 | int i; |
871 | u32 flags; | 869 | u32 flags; |
872 | 870 | ||
@@ -879,7 +877,6 @@ static int ecryptfs_process_flags(struct ecryptfs_crypt_stat *crypt_stat, | |||
879 | /* Version is in top 8 bits of the 32-bit flag vector */ | 877 | /* Version is in top 8 bits of the 32-bit flag vector */ |
880 | crypt_stat->file_version = ((flags >> 24) & 0xFF); | 878 | crypt_stat->file_version = ((flags >> 24) & 0xFF); |
881 | (*bytes_read) = 4; | 879 | (*bytes_read) = 4; |
882 | return rc; | ||
883 | } | 880 | } |
884 | 881 | ||
885 | /** | 882 | /** |
@@ -1004,8 +1001,10 @@ int ecryptfs_read_and_validate_header_region(struct inode *inode) | |||
1004 | 1001 | ||
1005 | rc = ecryptfs_read_lower(file_size, 0, ECRYPTFS_SIZE_AND_MARKER_BYTES, | 1002 | rc = ecryptfs_read_lower(file_size, 0, ECRYPTFS_SIZE_AND_MARKER_BYTES, |
1006 | inode); | 1003 | inode); |
1007 | if (rc < ECRYPTFS_SIZE_AND_MARKER_BYTES) | 1004 | if (rc < 0) |
1008 | return rc >= 0 ? -EINVAL : rc; | 1005 | return rc; |
1006 | else if (rc < ECRYPTFS_SIZE_AND_MARKER_BYTES) | ||
1007 | return -EINVAL; | ||
1009 | rc = ecryptfs_validate_marker(marker); | 1008 | rc = ecryptfs_validate_marker(marker); |
1010 | if (!rc) | 1009 | if (!rc) |
1011 | ecryptfs_i_size_init(file_size, inode); | 1010 | ecryptfs_i_size_init(file_size, inode); |
@@ -1115,9 +1114,21 @@ ecryptfs_write_metadata_to_xattr(struct dentry *ecryptfs_dentry, | |||
1115 | char *page_virt, size_t size) | 1114 | char *page_virt, size_t size) |
1116 | { | 1115 | { |
1117 | int rc; | 1116 | int rc; |
1117 | struct dentry *lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry); | ||
1118 | struct inode *lower_inode = d_inode(lower_dentry); | ||
1118 | 1119 | ||
1119 | rc = ecryptfs_setxattr(ecryptfs_dentry, ecryptfs_inode, | 1120 | if (!(lower_inode->i_opflags & IOP_XATTR)) { |
1120 | ECRYPTFS_XATTR_NAME, page_virt, size, 0); | 1121 | rc = -EOPNOTSUPP; |
1122 | goto out; | ||
1123 | } | ||
1124 | |||
1125 | inode_lock(lower_inode); | ||
1126 | rc = __vfs_setxattr(lower_dentry, lower_inode, ECRYPTFS_XATTR_NAME, | ||
1127 | page_virt, size, 0); | ||
1128 | if (!rc && ecryptfs_inode) | ||
1129 | fsstack_copy_attr_all(ecryptfs_inode, lower_inode); | ||
1130 | inode_unlock(lower_inode); | ||
1131 | out: | ||
1121 | return rc; | 1132 | return rc; |
1122 | } | 1133 | } |
1123 | 1134 | ||
@@ -1291,12 +1302,7 @@ static int ecryptfs_read_headers_virt(char *page_virt, | |||
1291 | if (!(crypt_stat->flags & ECRYPTFS_I_SIZE_INITIALIZED)) | 1302 | if (!(crypt_stat->flags & ECRYPTFS_I_SIZE_INITIALIZED)) |
1292 | ecryptfs_i_size_init(page_virt, d_inode(ecryptfs_dentry)); | 1303 | ecryptfs_i_size_init(page_virt, d_inode(ecryptfs_dentry)); |
1293 | offset += MAGIC_ECRYPTFS_MARKER_SIZE_BYTES; | 1304 | offset += MAGIC_ECRYPTFS_MARKER_SIZE_BYTES; |
1294 | rc = ecryptfs_process_flags(crypt_stat, (page_virt + offset), | 1305 | ecryptfs_process_flags(crypt_stat, (page_virt + offset), &bytes_read); |
1295 | &bytes_read); | ||
1296 | if (rc) { | ||
1297 | ecryptfs_printk(KERN_WARNING, "Error processing flags\n"); | ||
1298 | goto out; | ||
1299 | } | ||
1300 | if (crypt_stat->file_version > ECRYPTFS_SUPPORTED_FILE_VERSION) { | 1306 | if (crypt_stat->file_version > ECRYPTFS_SUPPORTED_FILE_VERSION) { |
1301 | ecryptfs_printk(KERN_WARNING, "File version is [%d]; only " | 1307 | ecryptfs_printk(KERN_WARNING, "File version is [%d]; only " |
1302 | "file version [%d] is supported by this " | 1308 | "file version [%d] is supported by this " |
@@ -1367,8 +1373,10 @@ int ecryptfs_read_and_validate_xattr_region(struct dentry *dentry, | |||
1367 | ecryptfs_inode_to_lower(inode), | 1373 | ecryptfs_inode_to_lower(inode), |
1368 | ECRYPTFS_XATTR_NAME, file_size, | 1374 | ECRYPTFS_XATTR_NAME, file_size, |
1369 | ECRYPTFS_SIZE_AND_MARKER_BYTES); | 1375 | ECRYPTFS_SIZE_AND_MARKER_BYTES); |
1370 | if (rc < ECRYPTFS_SIZE_AND_MARKER_BYTES) | 1376 | if (rc < 0) |
1371 | return rc >= 0 ? -EINVAL : rc; | 1377 | return rc; |
1378 | else if (rc < ECRYPTFS_SIZE_AND_MARKER_BYTES) | ||
1379 | return -EINVAL; | ||
1372 | rc = ecryptfs_validate_marker(marker); | 1380 | rc = ecryptfs_validate_marker(marker); |
1373 | if (!rc) | 1381 | if (!rc) |
1374 | ecryptfs_i_size_init(file_size, inode); | 1382 | ecryptfs_i_size_init(file_size, inode); |
diff --git a/fs/ecryptfs/debug.c b/fs/ecryptfs/debug.c index d131d070826f..1f65e99f9a41 100644 --- a/fs/ecryptfs/debug.c +++ b/fs/ecryptfs/debug.c | |||
@@ -83,25 +83,9 @@ void ecryptfs_dump_auth_tok(struct ecryptfs_auth_tok *auth_tok) | |||
83 | */ | 83 | */ |
84 | void ecryptfs_dump_hex(char *data, int bytes) | 84 | void ecryptfs_dump_hex(char *data, int bytes) |
85 | { | 85 | { |
86 | int i = 0; | ||
87 | int add_newline = 1; | ||
88 | |||
89 | if (ecryptfs_verbosity < 1) | 86 | if (ecryptfs_verbosity < 1) |
90 | return; | 87 | return; |
91 | if (bytes != 0) { | ||
92 | printk(KERN_DEBUG "0x%.2x.", (unsigned char)data[i]); | ||
93 | i++; | ||
94 | } | ||
95 | while (i < bytes) { | ||
96 | printk("0x%.2x.", (unsigned char)data[i]); | ||
97 | i++; | ||
98 | if (i % 16 == 0) { | ||
99 | printk("\n"); | ||
100 | add_newline = 0; | ||
101 | } else | ||
102 | add_newline = 1; | ||
103 | } | ||
104 | if (add_newline) | ||
105 | printk("\n"); | ||
106 | } | ||
107 | 88 | ||
89 | print_hex_dump(KERN_DEBUG, "ecryptfs: ", DUMP_PREFIX_OFFSET, 16, 1, | ||
90 | data, bytes, false); | ||
91 | } | ||
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c index 1e994d780f37..18426f4855f1 100644 --- a/fs/ecryptfs/inode.c +++ b/fs/ecryptfs/inode.c | |||
@@ -1121,7 +1121,7 @@ static int ecryptfs_xattr_set(const struct xattr_handler *handler, | |||
1121 | } | 1121 | } |
1122 | } | 1122 | } |
1123 | 1123 | ||
1124 | const struct xattr_handler ecryptfs_xattr_handler = { | 1124 | static const struct xattr_handler ecryptfs_xattr_handler = { |
1125 | .prefix = "", /* match anything */ | 1125 | .prefix = "", /* match anything */ |
1126 | .get = ecryptfs_xattr_get, | 1126 | .get = ecryptfs_xattr_get, |
1127 | .set = ecryptfs_xattr_set, | 1127 | .set = ecryptfs_xattr_set, |
diff --git a/fs/ecryptfs/keystore.c b/fs/ecryptfs/keystore.c index 9536e592e25a..216fbe6a4837 100644 --- a/fs/ecryptfs/keystore.c +++ b/fs/ecryptfs/keystore.c | |||
@@ -1048,8 +1048,9 @@ ecryptfs_parse_tag_70_packet(char **filename, size_t *filename_size, | |||
1048 | "rc = [%d]\n", __func__, rc); | 1048 | "rc = [%d]\n", __func__, rc); |
1049 | goto out_free_unlock; | 1049 | goto out_free_unlock; |
1050 | } | 1050 | } |
1051 | while (s->decrypted_filename[s->i] != '\0' | 1051 | |
1052 | && s->i < s->block_aligned_filename_size) | 1052 | while (s->i < s->block_aligned_filename_size && |
1053 | s->decrypted_filename[s->i] != '\0') | ||
1053 | s->i++; | 1054 | s->i++; |
1054 | if (s->i == s->block_aligned_filename_size) { | 1055 | if (s->i == s->block_aligned_filename_size) { |
1055 | printk(KERN_WARNING "%s: Invalid tag 70 packet; could not " | 1056 | printk(KERN_WARNING "%s: Invalid tag 70 packet; could not " |
@@ -1611,9 +1612,9 @@ int ecryptfs_keyring_auth_tok_for_sig(struct key **auth_tok_key, | |||
1611 | int rc = 0; | 1612 | int rc = 0; |
1612 | 1613 | ||
1613 | (*auth_tok_key) = request_key(&key_type_user, sig, NULL); | 1614 | (*auth_tok_key) = request_key(&key_type_user, sig, NULL); |
1614 | if (!(*auth_tok_key) || IS_ERR(*auth_tok_key)) { | 1615 | if (IS_ERR(*auth_tok_key)) { |
1615 | (*auth_tok_key) = ecryptfs_get_encrypted_key(sig); | 1616 | (*auth_tok_key) = ecryptfs_get_encrypted_key(sig); |
1616 | if (!(*auth_tok_key) || IS_ERR(*auth_tok_key)) { | 1617 | if (IS_ERR(*auth_tok_key)) { |
1617 | printk(KERN_ERR "Could not find key with description: [%s]\n", | 1618 | printk(KERN_ERR "Could not find key with description: [%s]\n", |
1618 | sig); | 1619 | sig); |
1619 | rc = process_request_key_err(PTR_ERR(*auth_tok_key)); | 1620 | rc = process_request_key_err(PTR_ERR(*auth_tok_key)); |