23 #include <linux/hash.h>
24 #include <linux/random.h>
26 #include <linux/poll.h>
27 #include <linux/slab.h>
28 #include <linux/wait.h>
29 #include <linux/module.h>
32 static atomic_t ecryptfs_num_miscdev_opens;
45 unsigned int mask = 0;
50 "daemon\n", __func__);
51 goto out_unlock_daemon;
54 goto out_unlock_daemon;
56 goto out_unlock_daemon;
59 poll_wait(file, &daemon->
wait, pt);
77 ecryptfs_miscdev_open(
struct inode *
inode,
struct file *file)
87 "count; rc = [%d]\n", __func__, rc);
88 goto out_unlock_daemon_list;
93 goto out_unlock_daemon_list;
98 "rc = [%d]\n", __func__, rc);
99 goto out_module_put_unlock_daemon_list;
104 goto out_unlock_daemon;
111 out_module_put_unlock_daemon_list:
114 out_unlock_daemon_list:
130 ecryptfs_miscdev_release(
struct inode *inode,
struct file *file)
146 "shut down daemon; rc = [%d]. Please report this "
147 "bug.\n", __func__, rc);
179 "to kmalloc(%zd, GFP_KERNEL)\n", __func__,
180 (
sizeof(*msg) + data_size));
186 msg_ctx->
msg->index = msg_ctx->
index;
189 memcpy(msg_ctx->
msg->data, data, data_size);
190 msg_ctx->
msg_size = (
sizeof(*msg_ctx->
msg) + data_size);
211 #define PKT_TYPE_SIZE 1
212 #define PKT_CTR_SIZE 4
213 #define MIN_NON_MSG_PKT_SIZE (PKT_TYPE_SIZE + PKT_CTR_SIZE)
214 #define MIN_MSG_PKT_SIZE (PKT_TYPE_SIZE + PKT_CTR_SIZE \
215 + ECRYPTFS_MIN_PKT_LEN_SIZE)
217 #define MAX_MSG_PKT_SIZE (PKT_TYPE_SIZE + PKT_CTR_SIZE \
218 + ECRYPTFS_MAX_PKT_LEN_SIZE \
219 + sizeof(struct ecryptfs_message) \
220 + 4 + ECRYPTFS_MAX_ENCRYPTED_KEY_BYTES)
221 #define PKT_TYPE_OFFSET 0
222 #define PKT_CTR_OFFSET PKT_TYPE_SIZE
223 #define PKT_LEN_OFFSET (PKT_TYPE_SIZE + PKT_CTR_SIZE)
238 ecryptfs_miscdev_read(
struct file *file,
char __user *
buf,
size_t count,
243 size_t packet_length_size;
253 "daemon\n", __func__);
254 goto out_unlock_daemon;
258 goto out_unlock_daemon;
270 goto out_unlock_daemon;
275 goto out_unlock_daemon;
290 &packet_length_size);
294 "rc = [%d]\n", __func__, rc);
295 goto out_unlock_msg_ctx;
298 packet_length_size = 0;
303 if (count < total_length) {
306 "size [%zd], but we need [%zd] to read the "
307 "pending message\n", __func__, count, total_length);
308 goto out_unlock_msg_ctx;
312 goto out_unlock_msg_ctx;
315 goto out_unlock_msg_ctx;
318 if (
copy_to_user(&buf[i], packet_length, packet_length_size))
319 goto out_unlock_msg_ctx;
320 i += packet_length_size;
322 goto out_unlock_msg_ctx;
357 "[%zd]; data_size = [%zd]. Invalid packet.\n", __func__,
358 (
sizeof(*msg) + msg->
data_len), data_size);
365 "Error processing response message; rc = [%d]\n", rc);
380 ecryptfs_miscdev_write(
struct file *file,
const char __user *
buf,
381 size_t count, loff_t *ppos)
385 size_t packet_size, packet_size_length;
397 "[%d-%zu], but amount of data written is [%zu].",
403 sizeof(packet_size_peek))) {
410 &packet_size_length);
413 "rc = [%zd]\n", __func__, rc);
428 __func__, PTR_ERR(data));
429 return PTR_ERR(data);
436 "size is [%zd], but amount of data written is "
437 "only [%zd]. Discarding response packet.\n",
447 &data[PKT_LEN_OFFSET + packet_size_length],
451 "response to requesting operation; rc = [%zd]\n",
461 "message of unrecognized type [%d]\n",
474 .open = ecryptfs_miscdev_open,
475 .poll = ecryptfs_miscdev_poll,
476 .read = ecryptfs_miscdev_read,
477 .write = ecryptfs_miscdev_write,
478 .release = ecryptfs_miscdev_release,
485 .fops = &ecryptfs_miscdev_fops
506 "for communications with userspace daemons; rc = [%d]\n",