Skip to content

Commit 290502b

Browse files
keestyhicks
authored andcommitted
eCryptfs: allow userspace messaging to be disabled
When the userspace messaging (for the less common case of userspace key wrap/unwrap via ecryptfsd) is not needed, allow eCryptfs to build with it removed. This saves on kernel code size and reduces potential attack surface by removing the /dev/ecryptfs node. Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
1 parent 1111eae commit 290502b

5 files changed

Lines changed: 55 additions & 16 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/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)
@@ -604,6 +619,7 @@ int
604619
ecryptfs_setxattr(struct dentry *dentry, const char *name, const void *value,
605620
size_t size, int flags);
606621
int ecryptfs_read_xattr_region(char *page_virt, struct inode *ecryptfs_inode);
622+
#ifdef CONFIG_ECRYPT_FS_MESSAGING
607623
int ecryptfs_process_response(struct ecryptfs_daemon *daemon,
608624
struct ecryptfs_message *msg, u32 seq);
609625
int ecryptfs_send_message(char *data, int data_len,
@@ -612,6 +628,24 @@ int ecryptfs_wait_for_response(struct ecryptfs_msg_ctx *msg_ctx,
612628
struct ecryptfs_message **emsg);
613629
int ecryptfs_init_messaging(void);
614630
void ecryptfs_release_messaging(void);
631+
#else
632+
static inline int ecryptfs_init_messaging(void)
633+
{
634+
return 0;
635+
}
636+
static inline void ecryptfs_release_messaging(void)
637+
{ }
638+
static inline int ecryptfs_send_message(char *data, int data_len,
639+
struct ecryptfs_msg_ctx **msg_ctx)
640+
{
641+
return -ENOTCONN;
642+
}
643+
static inline int ecryptfs_wait_for_response(struct ecryptfs_msg_ctx *msg_ctx,
644+
struct ecryptfs_message **emsg)
645+
{
646+
return -ENOMSG;
647+
}
648+
#endif
615649

616650
void
617651
ecryptfs_write_header_metadata(char *virt,
@@ -649,12 +683,11 @@ int ecryptfs_read_lower_page_segment(struct page *page_for_ecryptfs,
649683
size_t offset_in_page, size_t size,
650684
struct inode *ecryptfs_inode);
651685
struct page *ecryptfs_get_locked_page(struct inode *inode, loff_t index);
652-
int ecryptfs_exorcise_daemon(struct ecryptfs_daemon *daemon);
653-
int ecryptfs_find_daemon_by_euid(struct ecryptfs_daemon **daemon);
654686
int ecryptfs_parse_packet_length(unsigned char *data, size_t *size,
655687
size_t *length_size);
656688
int ecryptfs_write_packet_length(char *dest, size_t size,
657689
size_t *packet_size_length);
690+
#ifdef CONFIG_ECRYPT_FS_MESSAGING
658691
int ecryptfs_init_ecryptfs_miscdev(void);
659692
void ecryptfs_destroy_ecryptfs_miscdev(void);
660693
int ecryptfs_send_miscdev(char *data, size_t data_size,
@@ -663,6 +696,9 @@ int ecryptfs_send_miscdev(char *data, size_t data_size,
663696
void ecryptfs_msg_ctx_alloc_to_free(struct ecryptfs_msg_ctx *msg_ctx);
664697
int
665698
ecryptfs_spawn_daemon(struct ecryptfs_daemon **daemon, struct file *file);
699+
int ecryptfs_exorcise_daemon(struct ecryptfs_daemon *daemon);
700+
int ecryptfs_find_daemon_by_euid(struct ecryptfs_daemon **daemon);
701+
#endif
666702
int ecryptfs_init_kthread(void);
667703
void ecryptfs_destroy_kthread(void);
668704
int ecryptfs_privileged_open(struct file **lower_file,

‎fs/ecryptfs/keystore.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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);
@@ -1988,7 +1988,7 @@ pki_encrypt_session_key(struct key *auth_tok_key,
19881988
rc = ecryptfs_send_message(payload, payload_len, &msg_ctx);
19891989
if (rc) {
19901990
ecryptfs_printk(KERN_ERR, "Error sending message to "
1991-
"ecryptfsd\n");
1991+
"ecryptfsd: %d\n", rc);
19921992
goto out;
19931993
}
19941994
rc = ecryptfs_wait_for_response(msg_ctx, &msg);

‎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)