Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * eCryptfs: Linux filesystem encryption layer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 1997-2003 Erez Zadok
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (C) 2001-2003 Stony Brook University
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright (C) 2004-2007 International Business Machines Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *   Author(s): Michael A. Halcrow <mahalcro@us.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *              Michael C. Thompson <mcthomps@us.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *              Tyler Hicks <code@tyhicks.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/dcache.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/namei.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/mount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/key.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/parser.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/fs_stack.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/magic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include "ecryptfs_kernel.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * Module parameter that defines the ecryptfs_verbosity level.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) int ecryptfs_verbosity = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) module_param(ecryptfs_verbosity, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) MODULE_PARM_DESC(ecryptfs_verbosity,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 		 "Initial verbosity level (0 or 1; defaults to "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 		 "0, which is Quiet)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  * Module parameter that defines the number of message buffer elements
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) unsigned int ecryptfs_message_buf_len = ECRYPTFS_DEFAULT_MSG_CTX_ELEMS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) module_param(ecryptfs_message_buf_len, uint, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) MODULE_PARM_DESC(ecryptfs_message_buf_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		 "Number of message buffer elements");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * Module parameter that defines the maximum guaranteed amount of time to wait
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * for a response from ecryptfsd.  The actual sleep time will be, more than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * likely, a small amount greater than this specified value, but only less if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  * the message successfully arrives.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) signed long ecryptfs_message_wait_timeout = ECRYPTFS_MAX_MSG_CTX_TTL / HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) module_param(ecryptfs_message_wait_timeout, long, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) MODULE_PARM_DESC(ecryptfs_message_wait_timeout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		 "Maximum number of seconds that an operation will "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		 "sleep while waiting for a message response from "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		 "userspace");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  * Module parameter that is an estimate of the maximum number of users
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  * that will be concurrently using eCryptfs. Set this to the right
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  * value to balance performance and memory use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) unsigned int ecryptfs_number_of_users = ECRYPTFS_DEFAULT_NUM_USERS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) module_param(ecryptfs_number_of_users, uint, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) MODULE_PARM_DESC(ecryptfs_number_of_users, "An estimate of the number of "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		 "concurrent users of eCryptfs");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) void __ecryptfs_printk(const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	va_start(args, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	if (fmt[1] == '7') { /* KERN_DEBUG */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		if (ecryptfs_verbosity >= 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 			vprintk(fmt, args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		vprintk(fmt, args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)  * ecryptfs_init_lower_file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  * @ecryptfs_dentry: Fully initialized eCryptfs dentry object, with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)  *                   the lower dentry and the lower mount set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)  * eCryptfs only ever keeps a single open file for every lower
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89)  * inode. All I/O operations to the lower inode occur through that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90)  * file. When the first eCryptfs dentry that interposes with the first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91)  * lower dentry for that inode is created, this function creates the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92)  * lower file struct and associates it with the eCryptfs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)  * inode. When all eCryptfs files associated with the inode are released, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)  * file is closed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)  * The lower file will be opened with read/write permissions, if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  * possible. Otherwise, it is opened read-only.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99)  * This function does nothing if a lower file is already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  * associated with the eCryptfs inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)  * Returns zero on success; non-zero otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static int ecryptfs_init_lower_file(struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 				    struct file **lower_file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	const struct cred *cred = current_cred();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	struct path *path = ecryptfs_dentry_to_lower_path(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	rc = ecryptfs_privileged_open(lower_file, path->dentry, path->mnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 				      cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		printk(KERN_ERR "Error opening lower file "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		       "for lower_dentry [0x%p] and lower_mnt [0x%p]; "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		       "rc = [%d]\n", path->dentry, path->mnt, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		(*lower_file) = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) int ecryptfs_get_lower_file(struct dentry *dentry, struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	struct ecryptfs_inode_info *inode_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	int count, rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	inode_info = ecryptfs_inode_to_private(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	mutex_lock(&inode_info->lower_file_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	count = atomic_inc_return(&inode_info->lower_file_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	if (WARN_ON_ONCE(count < 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	else if (count == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		rc = ecryptfs_init_lower_file(dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 					      &inode_info->lower_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			atomic_set(&inode_info->lower_file_count, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	mutex_unlock(&inode_info->lower_file_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) void ecryptfs_put_lower_file(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	struct ecryptfs_inode_info *inode_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	inode_info = ecryptfs_inode_to_private(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	if (atomic_dec_and_mutex_lock(&inode_info->lower_file_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 				      &inode_info->lower_file_mutex)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		filemap_write_and_wait(inode->i_mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		fput(inode_info->lower_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		inode_info->lower_file = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		mutex_unlock(&inode_info->lower_file_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) enum { ecryptfs_opt_sig, ecryptfs_opt_ecryptfs_sig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)        ecryptfs_opt_cipher, ecryptfs_opt_ecryptfs_cipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)        ecryptfs_opt_ecryptfs_key_bytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)        ecryptfs_opt_passthrough, ecryptfs_opt_xattr_metadata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)        ecryptfs_opt_encrypted_view, ecryptfs_opt_fnek_sig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)        ecryptfs_opt_fn_cipher, ecryptfs_opt_fn_cipher_key_bytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)        ecryptfs_opt_unlink_sigs, ecryptfs_opt_mount_auth_tok_only,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)        ecryptfs_opt_check_dev_ruid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)        ecryptfs_opt_err };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static const match_table_t tokens = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	{ecryptfs_opt_sig, "sig=%s"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	{ecryptfs_opt_ecryptfs_sig, "ecryptfs_sig=%s"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	{ecryptfs_opt_cipher, "cipher=%s"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	{ecryptfs_opt_ecryptfs_cipher, "ecryptfs_cipher=%s"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	{ecryptfs_opt_ecryptfs_key_bytes, "ecryptfs_key_bytes=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	{ecryptfs_opt_passthrough, "ecryptfs_passthrough"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	{ecryptfs_opt_xattr_metadata, "ecryptfs_xattr_metadata"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	{ecryptfs_opt_encrypted_view, "ecryptfs_encrypted_view"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	{ecryptfs_opt_fnek_sig, "ecryptfs_fnek_sig=%s"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	{ecryptfs_opt_fn_cipher, "ecryptfs_fn_cipher=%s"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	{ecryptfs_opt_fn_cipher_key_bytes, "ecryptfs_fn_key_bytes=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	{ecryptfs_opt_unlink_sigs, "ecryptfs_unlink_sigs"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	{ecryptfs_opt_mount_auth_tok_only, "ecryptfs_mount_auth_tok_only"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	{ecryptfs_opt_check_dev_ruid, "ecryptfs_check_dev_ruid"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	{ecryptfs_opt_err, NULL}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) static int ecryptfs_init_global_auth_toks(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	struct ecryptfs_mount_crypt_stat *mount_crypt_stat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	struct ecryptfs_global_auth_tok *global_auth_tok;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	struct ecryptfs_auth_tok *auth_tok;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	list_for_each_entry(global_auth_tok,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 			    &mount_crypt_stat->global_auth_tok_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			    mount_crypt_stat_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		rc = ecryptfs_keyring_auth_tok_for_sig(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			&global_auth_tok->global_auth_tok_key, &auth_tok,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 			global_auth_tok->sig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 			printk(KERN_ERR "Could not find valid key in user "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 			       "session keyring for sig specified in mount "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 			       "option: [%s]\n", global_auth_tok->sig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 			global_auth_tok->flags |= ECRYPTFS_AUTH_TOK_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 			global_auth_tok->flags &= ~ECRYPTFS_AUTH_TOK_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			up_write(&(global_auth_tok->global_auth_tok_key)->sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) static void ecryptfs_init_mount_crypt_stat(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	struct ecryptfs_mount_crypt_stat *mount_crypt_stat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	memset((void *)mount_crypt_stat, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	       sizeof(struct ecryptfs_mount_crypt_stat));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	INIT_LIST_HEAD(&mount_crypt_stat->global_auth_tok_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	mutex_init(&mount_crypt_stat->global_auth_tok_list_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	mount_crypt_stat->flags |= ECRYPTFS_MOUNT_CRYPT_STAT_INITIALIZED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)  * ecryptfs_parse_options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)  * @sb: The ecryptfs super block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)  * @options: The options passed to the kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)  * @check_ruid: set to 1 if device uid should be checked against the ruid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)  * Parse mount options:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)  * debug=N 	   - ecryptfs_verbosity level for debug output
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)  * sig=XXX	   - description(signature) of the key to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)  * Returns the dentry object of the lower-level (lower/interposed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)  * directory; We want to mount our stackable file system on top of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)  * that lower directory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)  * The signature of the key to use must be the description of a key
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)  * already in the keyring. Mounting will fail if the key can not be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)  * found.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)  * Returns zero on success; non-zero on error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static int ecryptfs_parse_options(struct ecryptfs_sb_info *sbi, char *options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 				  uid_t *check_ruid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	char *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	int sig_set = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	int cipher_name_set = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	int fn_cipher_name_set = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	int cipher_key_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	int cipher_key_bytes_set = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	int fn_cipher_key_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	int fn_cipher_key_bytes_set = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	struct ecryptfs_mount_crypt_stat *mount_crypt_stat =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		&sbi->mount_crypt_stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	substring_t args[MAX_OPT_ARGS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	int token;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	char *sig_src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	char *cipher_name_dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	char *cipher_name_src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	char *fn_cipher_name_dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	char *fn_cipher_name_src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	char *fnek_dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	char *fnek_src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	char *cipher_key_bytes_src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	char *fn_cipher_key_bytes_src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	u8 cipher_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	*check_ruid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	if (!options) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	ecryptfs_init_mount_crypt_stat(mount_crypt_stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	while ((p = strsep(&options, ",")) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		if (!*p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		token = match_token(p, tokens, args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		switch (token) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		case ecryptfs_opt_sig:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		case ecryptfs_opt_ecryptfs_sig:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			sig_src = args[0].from;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 			rc = ecryptfs_add_global_auth_tok(mount_crypt_stat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 							  sig_src, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 			if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 				printk(KERN_ERR "Error attempting to register "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 				       "global sig; rc = [%d]\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 			sig_set = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		case ecryptfs_opt_cipher:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		case ecryptfs_opt_ecryptfs_cipher:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 			cipher_name_src = args[0].from;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 			cipher_name_dst =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 				mount_crypt_stat->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 				global_default_cipher_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 			strncpy(cipher_name_dst, cipher_name_src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 				ECRYPTFS_MAX_CIPHER_NAME_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 			cipher_name_dst[ECRYPTFS_MAX_CIPHER_NAME_SIZE] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 			cipher_name_set = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		case ecryptfs_opt_ecryptfs_key_bytes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 			cipher_key_bytes_src = args[0].from;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 			cipher_key_bytes =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 				(int)simple_strtol(cipher_key_bytes_src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 						   &cipher_key_bytes_src, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 			mount_crypt_stat->global_default_cipher_key_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 				cipher_key_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 			cipher_key_bytes_set = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		case ecryptfs_opt_passthrough:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 			mount_crypt_stat->flags |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 				ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		case ecryptfs_opt_xattr_metadata:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 			mount_crypt_stat->flags |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 				ECRYPTFS_XATTR_METADATA_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		case ecryptfs_opt_encrypted_view:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 			mount_crypt_stat->flags |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 				ECRYPTFS_XATTR_METADATA_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 			mount_crypt_stat->flags |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 				ECRYPTFS_ENCRYPTED_VIEW_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		case ecryptfs_opt_fnek_sig:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 			fnek_src = args[0].from;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 			fnek_dst =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 				mount_crypt_stat->global_default_fnek_sig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 			strncpy(fnek_dst, fnek_src, ECRYPTFS_SIG_SIZE_HEX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 			mount_crypt_stat->global_default_fnek_sig[
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 				ECRYPTFS_SIG_SIZE_HEX] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 			rc = ecryptfs_add_global_auth_tok(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 				mount_crypt_stat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 				mount_crypt_stat->global_default_fnek_sig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 				ECRYPTFS_AUTH_TOK_FNEK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 			if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 				printk(KERN_ERR "Error attempting to register "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 				       "global fnek sig [%s]; rc = [%d]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 				       mount_crypt_stat->global_default_fnek_sig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 				       rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 			mount_crypt_stat->flags |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 				(ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 				 | ECRYPTFS_GLOBAL_ENCFN_USE_MOUNT_FNEK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		case ecryptfs_opt_fn_cipher:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 			fn_cipher_name_src = args[0].from;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 			fn_cipher_name_dst =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 				mount_crypt_stat->global_default_fn_cipher_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 			strncpy(fn_cipher_name_dst, fn_cipher_name_src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 				ECRYPTFS_MAX_CIPHER_NAME_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 			mount_crypt_stat->global_default_fn_cipher_name[
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 				ECRYPTFS_MAX_CIPHER_NAME_SIZE] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 			fn_cipher_name_set = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		case ecryptfs_opt_fn_cipher_key_bytes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 			fn_cipher_key_bytes_src = args[0].from;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 			fn_cipher_key_bytes =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 				(int)simple_strtol(fn_cipher_key_bytes_src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 						   &fn_cipher_key_bytes_src, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 			mount_crypt_stat->global_default_fn_cipher_key_bytes =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 				fn_cipher_key_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 			fn_cipher_key_bytes_set = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		case ecryptfs_opt_unlink_sigs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 			mount_crypt_stat->flags |= ECRYPTFS_UNLINK_SIGS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		case ecryptfs_opt_mount_auth_tok_only:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 			mount_crypt_stat->flags |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 				ECRYPTFS_GLOBAL_MOUNT_AUTH_TOK_ONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		case ecryptfs_opt_check_dev_ruid:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 			*check_ruid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		case ecryptfs_opt_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 			printk(KERN_WARNING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 			       "%s: eCryptfs: unrecognized option [%s]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 			       __func__, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	if (!sig_set) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 		rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 		ecryptfs_printk(KERN_ERR, "You must supply at least one valid "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 				"auth tok signature as a mount "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 				"parameter; see the eCryptfs README\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	if (!cipher_name_set) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		int cipher_name_len = strlen(ECRYPTFS_DEFAULT_CIPHER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		BUG_ON(cipher_name_len > ECRYPTFS_MAX_CIPHER_NAME_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		strcpy(mount_crypt_stat->global_default_cipher_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 		       ECRYPTFS_DEFAULT_CIPHER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	if ((mount_crypt_stat->flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	    && !fn_cipher_name_set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		strcpy(mount_crypt_stat->global_default_fn_cipher_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		       mount_crypt_stat->global_default_cipher_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	if (!cipher_key_bytes_set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 		mount_crypt_stat->global_default_cipher_key_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	if ((mount_crypt_stat->flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	    && !fn_cipher_key_bytes_set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 		mount_crypt_stat->global_default_fn_cipher_key_bytes =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 			mount_crypt_stat->global_default_cipher_key_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	cipher_code = ecryptfs_code_for_cipher_string(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		mount_crypt_stat->global_default_cipher_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 		mount_crypt_stat->global_default_cipher_key_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	if (!cipher_code) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		ecryptfs_printk(KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 				"eCryptfs doesn't support cipher: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 				mount_crypt_stat->global_default_cipher_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	mutex_lock(&key_tfm_list_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	if (!ecryptfs_tfm_exists(mount_crypt_stat->global_default_cipher_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 				 NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		rc = ecryptfs_add_new_key_tfm(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 			NULL, mount_crypt_stat->global_default_cipher_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 			mount_crypt_stat->global_default_cipher_key_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 		if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 			printk(KERN_ERR "Error attempting to initialize "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 			       "cipher with name = [%s] and key size = [%td]; "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 			       "rc = [%d]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 			       mount_crypt_stat->global_default_cipher_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 			       mount_crypt_stat->global_default_cipher_key_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 			       rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 			rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 			mutex_unlock(&key_tfm_list_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	if ((mount_crypt_stat->flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	    && !ecryptfs_tfm_exists(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 		    mount_crypt_stat->global_default_fn_cipher_name, NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		rc = ecryptfs_add_new_key_tfm(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 			NULL, mount_crypt_stat->global_default_fn_cipher_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 			mount_crypt_stat->global_default_fn_cipher_key_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 		if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 			printk(KERN_ERR "Error attempting to initialize "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 			       "cipher with name = [%s] and key size = [%td]; "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 			       "rc = [%d]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 			       mount_crypt_stat->global_default_fn_cipher_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 			       mount_crypt_stat->global_default_fn_cipher_key_bytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 			       rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 			rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 			mutex_unlock(&key_tfm_list_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	mutex_unlock(&key_tfm_list_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	rc = ecryptfs_init_global_auth_toks(mount_crypt_stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		printk(KERN_WARNING "One or more global auth toks could not "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 		       "properly register; rc = [%d]\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) struct kmem_cache *ecryptfs_sb_info_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) static struct file_system_type ecryptfs_fs_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)  * ecryptfs_get_sb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)  * @fs_type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)  * @flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)  * @dev_name: The path to mount over
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)  * @raw_data: The options passed into the kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) static struct dentry *ecryptfs_mount(struct file_system_type *fs_type, int flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 			const char *dev_name, void *raw_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	struct super_block *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	struct ecryptfs_sb_info *sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	struct ecryptfs_mount_crypt_stat *mount_crypt_stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	struct ecryptfs_dentry_info *root_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	const char *err = "Getting sb failed";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	struct path path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	uid_t check_ruid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	sbi = kmem_cache_zalloc(ecryptfs_sb_info_cache, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	if (!sbi) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 		rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	if (!dev_name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 		rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 		err = "Device name cannot be null";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	rc = ecryptfs_parse_options(sbi, raw_data, &check_ruid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 		err = "Error parsing options";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	mount_crypt_stat = &sbi->mount_crypt_stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	s = sget(fs_type, NULL, set_anon_super, flags, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	if (IS_ERR(s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 		rc = PTR_ERR(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	rc = super_setup_bdi(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 		goto out1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	ecryptfs_set_superblock_private(s, sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	/* ->kill_sb() will take care of sbi after that point */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	sbi = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	s->s_op = &ecryptfs_sops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	s->s_xattr = ecryptfs_xattr_handlers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	s->s_d_op = &ecryptfs_dops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	err = "Reading sb failed";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 	rc = kern_path(dev_name, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 		ecryptfs_printk(KERN_WARNING, "kern_path() failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 		goto out1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	if (path.dentry->d_sb->s_type == &ecryptfs_fs_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 		rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 		printk(KERN_ERR "Mount on filesystem of type "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 			"eCryptfs explicitly disallowed due to "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 			"known incompatibilities\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 		goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	if (check_ruid && !uid_eq(d_inode(path.dentry)->i_uid, current_uid())) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 		rc = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 		printk(KERN_ERR "Mount of device (uid: %d) not owned by "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 		       "requested user (uid: %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 			i_uid_read(d_inode(path.dentry)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 			from_kuid(&init_user_ns, current_uid()));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 		goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	ecryptfs_set_superblock_lower(s, path.dentry->d_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	 * Set the POSIX ACL flag based on whether they're enabled in the lower
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	 * mount.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	s->s_flags = flags & ~SB_POSIXACL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	s->s_flags |= path.dentry->d_sb->s_flags & SB_POSIXACL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	 * Force a read-only eCryptfs mount when:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	 *   1) The lower mount is ro
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	 *   2) The ecryptfs_encrypted_view mount option is specified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	if (sb_rdonly(path.dentry->d_sb) || mount_crypt_stat->flags & ECRYPTFS_ENCRYPTED_VIEW_ENABLED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 		s->s_flags |= SB_RDONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	s->s_maxbytes = path.dentry->d_sb->s_maxbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	s->s_blocksize = path.dentry->d_sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	s->s_magic = ECRYPTFS_SUPER_MAGIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 	s->s_stack_depth = path.dentry->d_sb->s_stack_depth + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 	rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	if (s->s_stack_depth > FILESYSTEM_MAX_STACK_DEPTH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 		pr_err("eCryptfs: maximum fs stacking depth exceeded\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 		goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	inode = ecryptfs_get_inode(d_inode(path.dentry), s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	rc = PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 	if (IS_ERR(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 		goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	s->s_root = d_make_root(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	if (!s->s_root) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 		rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 		goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 	root_info = kmem_cache_zalloc(ecryptfs_dentry_info_cache, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	if (!root_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 		goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 	/* ->kill_sb() will take care of root_info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	ecryptfs_set_dentry_private(s->s_root, root_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 	root_info->lower_path = path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 	s->s_flags |= SB_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 	return dget(s->s_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 	path_put(&path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) out1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	deactivate_locked_super(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 	if (sbi) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 		ecryptfs_destroy_mount_crypt_stat(&sbi->mount_crypt_stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 		kmem_cache_free(ecryptfs_sb_info_cache, sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 	printk(KERN_ERR "%s; rc = [%d]\n", err, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 	return ERR_PTR(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614)  * ecryptfs_kill_block_super
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)  * @sb: The ecryptfs super block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617)  * Used to bring the superblock down and free the private data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) static void ecryptfs_kill_block_super(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 	struct ecryptfs_sb_info *sb_info = ecryptfs_superblock_to_private(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 	kill_anon_super(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 	if (!sb_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 	ecryptfs_destroy_mount_crypt_stat(&sb_info->mount_crypt_stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 	kmem_cache_free(ecryptfs_sb_info_cache, sb_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) static struct file_system_type ecryptfs_fs_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 	.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 	.name = "ecryptfs",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 	.mount = ecryptfs_mount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 	.kill_sb = ecryptfs_kill_block_super,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 	.fs_flags = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) MODULE_ALIAS_FS("ecryptfs");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639)  * inode_info_init_once
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641)  * Initializes the ecryptfs_inode_info_cache when it is created
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) inode_info_init_once(void *vptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	struct ecryptfs_inode_info *ei = (struct ecryptfs_inode_info *)vptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 	inode_init_once(&ei->vfs_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) static struct ecryptfs_cache_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 	struct kmem_cache **cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 	const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	size_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 	slab_flags_t flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	void (*ctor)(void *obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) } ecryptfs_cache_infos[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 		.cache = &ecryptfs_auth_tok_list_item_cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 		.name = "ecryptfs_auth_tok_list_item",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 		.size = sizeof(struct ecryptfs_auth_tok_list_item),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 		.cache = &ecryptfs_file_info_cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 		.name = "ecryptfs_file_cache",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 		.size = sizeof(struct ecryptfs_file_info),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 		.cache = &ecryptfs_dentry_info_cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 		.name = "ecryptfs_dentry_info_cache",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 		.size = sizeof(struct ecryptfs_dentry_info),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 		.cache = &ecryptfs_inode_info_cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 		.name = "ecryptfs_inode_cache",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 		.size = sizeof(struct ecryptfs_inode_info),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 		.flags = SLAB_ACCOUNT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 		.ctor = inode_info_init_once,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 		.cache = &ecryptfs_sb_info_cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 		.name = "ecryptfs_sb_cache",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 		.size = sizeof(struct ecryptfs_sb_info),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 		.cache = &ecryptfs_header_cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 		.name = "ecryptfs_headers",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 		.size = PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 		.cache = &ecryptfs_xattr_cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 		.name = "ecryptfs_xattr_cache",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 		.size = PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 		.cache = &ecryptfs_key_record_cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 		.name = "ecryptfs_key_record_cache",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 		.size = sizeof(struct ecryptfs_key_record),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 		.cache = &ecryptfs_key_sig_cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 		.name = "ecryptfs_key_sig_cache",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 		.size = sizeof(struct ecryptfs_key_sig),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 		.cache = &ecryptfs_global_auth_tok_cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 		.name = "ecryptfs_global_auth_tok_cache",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 		.size = sizeof(struct ecryptfs_global_auth_tok),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 		.cache = &ecryptfs_key_tfm_cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 		.name = "ecryptfs_key_tfm_cache",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 		.size = sizeof(struct ecryptfs_key_tfm),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) static void ecryptfs_free_kmem_caches(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 	 * Make sure all delayed rcu free inodes are flushed before we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 	 * destroy cache.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 	rcu_barrier();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 	for (i = 0; i < ARRAY_SIZE(ecryptfs_cache_infos); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 		struct ecryptfs_cache_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 		info = &ecryptfs_cache_infos[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 		kmem_cache_destroy(*(info->cache));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736)  * ecryptfs_init_kmem_caches
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738)  * Returns zero on success; non-zero otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) static int ecryptfs_init_kmem_caches(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 	for (i = 0; i < ARRAY_SIZE(ecryptfs_cache_infos); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 		struct ecryptfs_cache_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 		info = &ecryptfs_cache_infos[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) 		*(info->cache) = kmem_cache_create(info->name, info->size, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 				SLAB_HWCACHE_ALIGN | info->flags, info->ctor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) 		if (!*(info->cache)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 			ecryptfs_free_kmem_caches();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) 			ecryptfs_printk(KERN_WARNING, "%s: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 					"kmem_cache_create failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) 					info->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) static struct kobject *ecryptfs_kobj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) static ssize_t version_show(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) 			    struct kobj_attribute *attr, char *buff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) 	return snprintf(buff, PAGE_SIZE, "%d\n", ECRYPTFS_VERSIONING_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) static struct kobj_attribute version_attr = __ATTR_RO(version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) static struct attribute *attributes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) 	&version_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) static const struct attribute_group attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) 	.attrs = attributes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) static int do_sysfs_registration(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) 	ecryptfs_kobj = kobject_create_and_add("ecryptfs", fs_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) 	if (!ecryptfs_kobj) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) 		printk(KERN_ERR "Unable to create ecryptfs kset\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) 		rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) 	rc = sysfs_create_group(ecryptfs_kobj, &attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) 		printk(KERN_ERR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) 		       "Unable to create ecryptfs version attributes\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) 		kobject_put(ecryptfs_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) static void do_sysfs_unregistration(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) 	sysfs_remove_group(ecryptfs_kobj, &attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) 	kobject_put(ecryptfs_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) static int __init ecryptfs_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) 	if (ECRYPTFS_DEFAULT_EXTENT_SIZE > PAGE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) 		rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) 		ecryptfs_printk(KERN_ERR, "The eCryptfs extent size is "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) 				"larger than the host's page size, and so "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) 				"eCryptfs cannot run on this system. The "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) 				"default eCryptfs extent size is [%u] bytes; "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) 				"the page size is [%lu] bytes.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) 				ECRYPTFS_DEFAULT_EXTENT_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) 				(unsigned long)PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) 	rc = ecryptfs_init_kmem_caches();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) 		printk(KERN_ERR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) 		       "Failed to allocate one or more kmem_cache objects\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) 	rc = do_sysfs_registration();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) 		printk(KERN_ERR "sysfs registration failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) 		goto out_free_kmem_caches;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) 	rc = ecryptfs_init_kthread();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) 		printk(KERN_ERR "%s: kthread initialization failed; "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) 		       "rc = [%d]\n", __func__, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) 		goto out_do_sysfs_unregistration;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) 	rc = ecryptfs_init_messaging();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) 		printk(KERN_ERR "Failure occurred while attempting to "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) 				"initialize the communications channel to "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) 				"ecryptfsd\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) 		goto out_destroy_kthread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) 	rc = ecryptfs_init_crypto();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) 		printk(KERN_ERR "Failure whilst attempting to init crypto; "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) 		       "rc = [%d]\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) 		goto out_release_messaging;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) 	rc = register_filesystem(&ecryptfs_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) 		printk(KERN_ERR "Failed to register filesystem\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) 		goto out_destroy_crypto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) 	if (ecryptfs_verbosity > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) 		printk(KERN_CRIT "eCryptfs verbosity set to %d. Secret values "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) 			"will be written to the syslog!\n", ecryptfs_verbosity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) 	goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) out_destroy_crypto:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) 	ecryptfs_destroy_crypto();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) out_release_messaging:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) 	ecryptfs_release_messaging();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) out_destroy_kthread:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) 	ecryptfs_destroy_kthread();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) out_do_sysfs_unregistration:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) 	do_sysfs_unregistration();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) out_free_kmem_caches:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) 	ecryptfs_free_kmem_caches();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) static void __exit ecryptfs_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) 	rc = ecryptfs_destroy_crypto();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) 		printk(KERN_ERR "Failure whilst attempting to destroy crypto; "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) 		       "rc = [%d]\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) 	ecryptfs_release_messaging();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) 	ecryptfs_destroy_kthread();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) 	do_sysfs_unregistration();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) 	unregister_filesystem(&ecryptfs_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) 	ecryptfs_free_kmem_caches();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) MODULE_AUTHOR("Michael A. Halcrow <mhalcrow@us.ibm.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) MODULE_DESCRIPTION("eCryptfs");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) MODULE_IMPORT_NS(ANDROID_GKI_VFS_EXPORT_ONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) module_init(ecryptfs_init)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) module_exit(ecryptfs_exit)