Skip to content

Commit e2e091f

Browse files
committed
Merge tag 'ecryptfs-3.9-rc2-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tyhicks/ecryptfs
Pull ecryptfs fixes from Tyler Hicks: "Minor code cleanups and new Kconfig option to disable /dev/ecryptfs The code cleanups fix up W=1 compiler warnings and some unnecessary checks. The new Kconfig option, defaulting to N, allows the rarely used eCryptfs kernel to userspace communication channel to be compiled out. This may be the first step in it being eventually removed." Hmm. I'm not sure whether these should be called "fixes", and it probably should have gone in the merge window. But I'll let it slide. * tag 'ecryptfs-3.9-rc2-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tyhicks/ecryptfs: eCryptfs: allow userspace messaging to be disabled eCryptfs: Fix redundant error check on ecryptfs_find_daemon_by_euid() ecryptfs: ecryptfs_msg_ctx_alloc_to_free(): remove kfree() redundant null check eCryptfs: decrypt_pki_encrypted_session_key(): remove kfree() redundant null check eCryptfs: remove unneeded checks in virt_to_scatterlist() eCryptfs: Fix -Wmissing-prototypes warnings eCryptfs: Fix -Wunused-but-set-variable warnings eCryptfs: initialize payload_len in keystore.c
2 parents cd66acb + 290502b commit e2e091f

10 files changed

Lines changed: 66 additions & 36 deletions

File tree

‎fs/ecryptfs/Kconfig‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,11 @@ config ECRYPT_FS
1212

1313
To compile this file system support as a module, choose M here: the
1414
module will be called ecryptfs.
15+
16+
config ECRYPT_FS_MESSAGING
17+
bool "Enable notifications for userspace key wrap/unwrap"
18+
depends on ECRYPT_FS
19+
help
20+
Enables the /dev/ecryptfs entry for use by ecryptfsd. This allows
21+
for userspace to wrap/unwrap file encryption keys by other
22+
backends, like OpenSSL.

‎fs/ecryptfs/Makefile‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#
2-
# Makefile for the Linux 2.6 eCryptfs
2+
# Makefile for the Linux eCryptfs
33
#
44

55
obj-$(CONFIG_ECRYPT_FS) += ecryptfs.o
66

7-
ecryptfs-objs := dentry.o file.o inode.o main.o super.o mmap.o read_write.o crypto.o keystore.o messaging.o miscdev.o kthread.o debug.o
7+
ecryptfs-y := dentry.o file.o inode.o main.o super.o mmap.o read_write.o \
8+
crypto.o keystore.o kthread.o debug.o
9+
10+
ecryptfs-$(CONFIG_ECRYPT_FS_MESSAGING) += messaging.o miscdev.o

‎fs/ecryptfs/crypto.c‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -301,17 +301,14 @@ int virt_to_scatterlist(const void *addr, int size, struct scatterlist *sg,
301301
while (size > 0 && i < sg_size) {
302302
pg = virt_to_page(addr);
303303
offset = offset_in_page(addr);
304-
if (sg)
305-
sg_set_page(&sg[i], pg, 0, offset);
304+
sg_set_page(&sg[i], pg, 0, offset);
306305
remainder_of_page = PAGE_CACHE_SIZE - offset;
307306
if (size >= remainder_of_page) {
308-
if (sg)
309-
sg[i].length = remainder_of_page;
307+
sg[i].length = remainder_of_page;
310308
addr += remainder_of_page;
311309
size -= remainder_of_page;
312310
} else {
313-
if (sg)
314-
sg[i].length = size;
311+
sg[i].length = size;
315312
addr += size;
316313
size = 0;
317314
}

‎fs/ecryptfs/dentry.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,12 @@
4545
static int ecryptfs_d_revalidate(struct dentry *dentry, unsigned int flags)
4646
{
4747
struct dentry *lower_dentry;
48-
struct vfsmount *lower_mnt;
4948
int rc = 1;
5049

5150
if (flags & LOOKUP_RCU)
5251
return -ECHILD;
5352

5453
lower_dentry = ecryptfs_dentry_to_lower(dentry);
55-
lower_mnt = ecryptfs_dentry_to_lower_mnt(dentry);
5654
if (!lower_dentry->d_op || !lower_dentry->d_op->d_revalidate)
5755
goto out;
5856
rc = lower_dentry->d_op->d_revalidate(lower_dentry, flags);

‎fs/ecryptfs/ecryptfs_kernel.h‎

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,19 @@ ecryptfs_get_key_payload_data(struct key *key)
172172
#define ECRYPTFS_FNEK_ENCRYPTED_FILENAME_PREFIX_SIZE 24
173173
#define ECRYPTFS_ENCRYPTED_DENTRY_NAME_LEN (18 + 1 + 4 + 1 + 32)
174174

175+
#ifdef CONFIG_ECRYPT_FS_MESSAGING
176+
# define ECRYPTFS_VERSIONING_MASK_MESSAGING (ECRYPTFS_VERSIONING_DEVMISC \
177+
| ECRYPTFS_VERSIONING_PUBKEY)
178+
#else
179+
# define ECRYPTFS_VERSIONING_MASK_MESSAGING 0
180+
#endif
181+
182+
#define ECRYPTFS_VERSIONING_MASK (ECRYPTFS_VERSIONING_PASSPHRASE \
183+
| ECRYPTFS_VERSIONING_PLAINTEXT_PASSTHROUGH \
184+
| ECRYPTFS_VERSIONING_XATTR \
185+
| ECRYPTFS_VERSIONING_MULTKEY \
186+
| ECRYPTFS_VERSIONING_MASK_MESSAGING \
187+
| ECRYPTFS_VERSIONING_FILENAME_ENCRYPTION)
175188
struct ecryptfs_key_sig {
176189
struct list_head crypt_stat_list;
177190
char keysig[ECRYPTFS_SIG_SIZE_HEX + 1];
@@ -399,7 +412,9 @@ struct ecryptfs_daemon {
399412
struct hlist_node euid_chain;
400413
};
401414

415+
#ifdef CONFIG_ECRYPT_FS_MESSAGING
402416
extern struct mutex ecryptfs_daemon_hash_mux;
417+
#endif
403418

404419
static inline size_t
405420
ecryptfs_lower_header_size(struct ecryptfs_crypt_stat *crypt_stat)
@@ -610,6 +625,7 @@ int
610625
ecryptfs_setxattr(struct dentry *dentry, const char *name, const void *value,
611626
size_t size, int flags);
612627
int ecryptfs_read_xattr_region(char *page_virt, struct inode *ecryptfs_inode);
628+
#ifdef CONFIG_ECRYPT_FS_MESSAGING
613629
int ecryptfs_process_response(struct ecryptfs_daemon *daemon,
614630
struct ecryptfs_message *msg, u32 seq);
615631
int ecryptfs_send_message(char *data, int data_len,
@@ -618,6 +634,24 @@ int ecryptfs_wait_for_response(struct ecryptfs_msg_ctx *msg_ctx,
618634
struct ecryptfs_message **emsg);
619635
int ecryptfs_init_messaging(void);
620636
void ecryptfs_release_messaging(void);
637+
#else
638+
static inline int ecryptfs_init_messaging(void)
639+
{
640+
return 0;
641+
}
642+
static inline void ecryptfs_release_messaging(void)
643+
{ }
644+
static inline int ecryptfs_send_message(char *data, int data_len,
645+
struct ecryptfs_msg_ctx **msg_ctx)
646+
{
647+
return -ENOTCONN;
648+
}
649+
static inline int ecryptfs_wait_for_response(struct ecryptfs_msg_ctx *msg_ctx,
650+
struct ecryptfs_message **emsg)
651+
{
652+
return -ENOMSG;
653+
}
654+
#endif
621655

622656
void
623657
ecryptfs_write_header_metadata(char *virt,
@@ -655,12 +689,11 @@ int ecryptfs_read_lower_page_segment(struct page *page_for_ecryptfs,
655689
size_t offset_in_page, size_t size,
656690
struct inode *ecryptfs_inode);
657691
struct page *ecryptfs_get_locked_page(struct inode *inode, loff_t index);
658-
int ecryptfs_exorcise_daemon(struct ecryptfs_daemon *daemon);
659-
int ecryptfs_find_daemon_by_euid(struct ecryptfs_daemon **daemon);
660692
int ecryptfs_parse_packet_length(unsigned char *data, size_t *size,
661693
size_t *length_size);
662694
int ecryptfs_write_packet_length(char *dest, size_t size,
663695
size_t *packet_size_length);
696+
#ifdef CONFIG_ECRYPT_FS_MESSAGING
664697
int ecryptfs_init_ecryptfs_miscdev(void);
665698
void ecryptfs_destroy_ecryptfs_miscdev(void);
666699
int ecryptfs_send_miscdev(char *data, size_t data_size,
@@ -669,6 +702,9 @@ int ecryptfs_send_miscdev(char *data, size_t data_size,
669702
void ecryptfs_msg_ctx_alloc_to_free(struct ecryptfs_msg_ctx *msg_ctx);
670703
int
671704
ecryptfs_spawn_daemon(struct ecryptfs_daemon **daemon, struct file *file);
705+
int ecryptfs_exorcise_daemon(struct ecryptfs_daemon *daemon);
706+
int ecryptfs_find_daemon_by_euid(struct ecryptfs_daemon **daemon);
707+
#endif
672708
int ecryptfs_init_kthread(void);
673709
void ecryptfs_destroy_kthread(void);
674710
int ecryptfs_privileged_open(struct file **lower_file,

‎fs/ecryptfs/file.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ static int ecryptfs_open(struct inode *inode, struct file *file)
199199
struct dentry *ecryptfs_dentry = file->f_path.dentry;
200200
/* Private value of ecryptfs_dentry allocated in
201201
* ecryptfs_lookup() */
202-
struct dentry *lower_dentry;
203202
struct ecryptfs_file_info *file_info;
204203

205204
mount_crypt_stat = &ecryptfs_superblock_to_private(
@@ -222,7 +221,6 @@ static int ecryptfs_open(struct inode *inode, struct file *file)
222221
rc = -ENOMEM;
223222
goto out;
224223
}
225-
lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry);
226224
crypt_stat = &ecryptfs_inode_to_private(inode)->crypt_stat;
227225
mutex_lock(&crypt_stat->cs_mutex);
228226
if (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED)) {

‎fs/ecryptfs/inode.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -999,8 +999,8 @@ static int ecryptfs_setattr(struct dentry *dentry, struct iattr *ia)
999999
return rc;
10001000
}
10011001

1002-
int ecryptfs_getattr_link(struct vfsmount *mnt, struct dentry *dentry,
1003-
struct kstat *stat)
1002+
static int ecryptfs_getattr_link(struct vfsmount *mnt, struct dentry *dentry,
1003+
struct kstat *stat)
10041004
{
10051005
struct ecryptfs_mount_crypt_stat *mount_crypt_stat;
10061006
int rc = 0;
@@ -1021,8 +1021,8 @@ int ecryptfs_getattr_link(struct vfsmount *mnt, struct dentry *dentry,
10211021
return rc;
10221022
}
10231023

1024-
int ecryptfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
1025-
struct kstat *stat)
1024+
static int ecryptfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
1025+
struct kstat *stat)
10261026
{
10271027
struct kstat lower_stat;
10281028
int rc;

‎fs/ecryptfs/keystore.c‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,7 @@ decrypt_pki_encrypted_session_key(struct ecryptfs_auth_tok *auth_tok,
11501150
struct ecryptfs_message *msg = NULL;
11511151
char *auth_tok_sig;
11521152
char *payload;
1153-
size_t payload_len;
1153+
size_t payload_len = 0;
11541154
int rc;
11551155

11561156
rc = ecryptfs_get_auth_tok_sig(&auth_tok_sig, auth_tok);
@@ -1168,7 +1168,7 @@ decrypt_pki_encrypted_session_key(struct ecryptfs_auth_tok *auth_tok,
11681168
rc = ecryptfs_send_message(payload, payload_len, &msg_ctx);
11691169
if (rc) {
11701170
ecryptfs_printk(KERN_ERR, "Error sending message to "
1171-
"ecryptfsd\n");
1171+
"ecryptfsd: %d\n", rc);
11721172
goto out;
11731173
}
11741174
rc = ecryptfs_wait_for_response(msg_ctx, &msg);
@@ -1202,8 +1202,7 @@ decrypt_pki_encrypted_session_key(struct ecryptfs_auth_tok *auth_tok,
12021202
crypt_stat->key_size);
12031203
}
12041204
out:
1205-
if (msg)
1206-
kfree(msg);
1205+
kfree(msg);
12071206
return rc;
12081207
}
12091208

@@ -1989,7 +1988,7 @@ pki_encrypt_session_key(struct key *auth_tok_key,
19891988
rc = ecryptfs_send_message(payload, payload_len, &msg_ctx);
19901989
if (rc) {
19911990
ecryptfs_printk(KERN_ERR, "Error sending message to "
1992-
"ecryptfsd\n");
1991+
"ecryptfsd: %d\n", rc);
19931992
goto out;
19941993
}
19951994
rc = ecryptfs_wait_for_response(msg_ctx, &msg);

‎fs/ecryptfs/messaging.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ static void ecryptfs_msg_ctx_free_to_alloc(struct ecryptfs_msg_ctx *msg_ctx)
9797
void ecryptfs_msg_ctx_alloc_to_free(struct ecryptfs_msg_ctx *msg_ctx)
9898
{
9999
list_move(&(msg_ctx->node), &ecryptfs_msg_ctx_free_list);
100-
if (msg_ctx->msg)
101-
kfree(msg_ctx->msg);
100+
kfree(msg_ctx->msg);
102101
msg_ctx->msg = NULL;
103102
msg_ctx->state = ECRYPTFS_MSG_CTX_STATE_FREE;
104103
}
@@ -283,7 +282,7 @@ ecryptfs_send_message_locked(char *data, int data_len, u8 msg_type,
283282
int rc;
284283

285284
rc = ecryptfs_find_daemon_by_euid(&daemon);
286-
if (rc || !daemon) {
285+
if (rc) {
287286
rc = -ENOTCONN;
288287
goto out;
289288
}

‎include/linux/ecryptfs.h‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
#define ECRYPTFS_VERSION_MINOR 0x04
77
#define ECRYPTFS_SUPPORTED_FILE_VERSION 0x03
88
/* These flags indicate which features are supported by the kernel
9-
* module; userspace tools such as the mount helper read
10-
* ECRYPTFS_VERSIONING_MASK from a sysfs handle in order to determine
11-
* how to behave. */
9+
* module; userspace tools such as the mount helper read the feature
10+
* bits from a sysfs handle in order to determine how to behave. */
1211
#define ECRYPTFS_VERSIONING_PASSPHRASE 0x00000001
1312
#define ECRYPTFS_VERSIONING_PUBKEY 0x00000002
1413
#define ECRYPTFS_VERSIONING_PLAINTEXT_PASSTHROUGH 0x00000004
@@ -19,13 +18,6 @@
1918
#define ECRYPTFS_VERSIONING_HMAC 0x00000080
2019
#define ECRYPTFS_VERSIONING_FILENAME_ENCRYPTION 0x00000100
2120
#define ECRYPTFS_VERSIONING_GCM 0x00000200
22-
#define ECRYPTFS_VERSIONING_MASK (ECRYPTFS_VERSIONING_PASSPHRASE \
23-
| ECRYPTFS_VERSIONING_PLAINTEXT_PASSTHROUGH \
24-
| ECRYPTFS_VERSIONING_PUBKEY \
25-
| ECRYPTFS_VERSIONING_XATTR \
26-
| ECRYPTFS_VERSIONING_MULTKEY \
27-
| ECRYPTFS_VERSIONING_DEVMISC \
28-
| ECRYPTFS_VERSIONING_FILENAME_ENCRYPTION)
2921
#define ECRYPTFS_MAX_PASSWORD_LENGTH 64
3022
#define ECRYPTFS_MAX_PASSPHRASE_BYTES ECRYPTFS_MAX_PASSWORD_LENGTH
3123
#define ECRYPTFS_SALT_SIZE 8

0 commit comments

Comments
 (0)