Commit 7f133504 authored by Tyler Hicks's avatar Tyler Hicks

eCryptfs: Report errors in writes to /dev/ecryptfs

Errors in writes to /dev/ecryptfs were being incorrectly reported by
returning 0 or the value of the original write count.

This patch clears up the return code assignment in error paths.
Signed-off-by: default avatarTyler Hicks <tyhicks@canonical.com>
parent db10e556
...@@ -406,14 +406,13 @@ ecryptfs_miscdev_write(struct file *file, const char __user *buf, ...@@ -406,14 +406,13 @@ ecryptfs_miscdev_write(struct file *file, const char __user *buf,
__be32 counter_nbo; __be32 counter_nbo;
u32 seq; u32 seq;
size_t packet_size, packet_size_length, i; size_t packet_size, packet_size_length, i;
ssize_t sz = 0;
char *data; char *data;
uid_t euid = current_euid(); uid_t euid = current_euid();
unsigned char packet_size_peek[3]; unsigned char packet_size_peek[3];
int rc; ssize_t rc;
if (count == 0) { if (count == 0) {
goto out; return 0;
} else if (count == (1 + 4)) { } else if (count == (1 + 4)) {
/* Likely a harmless MSG_HELO or MSG_QUIT - no packet length */ /* Likely a harmless MSG_HELO or MSG_QUIT - no packet length */
goto memdup; goto memdup;
...@@ -439,7 +438,7 @@ ecryptfs_miscdev_write(struct file *file, const char __user *buf, ...@@ -439,7 +438,7 @@ ecryptfs_miscdev_write(struct file *file, const char __user *buf,
&packet_size_length); &packet_size_length);
if (rc) { if (rc) {
printk(KERN_WARNING "%s: Error parsing packet length; " printk(KERN_WARNING "%s: Error parsing packet length; "
"rc = [%d]\n", __func__, rc); "rc = [%zd]\n", __func__, rc);
return rc; return rc;
} }
...@@ -454,9 +453,8 @@ ecryptfs_miscdev_write(struct file *file, const char __user *buf, ...@@ -454,9 +453,8 @@ ecryptfs_miscdev_write(struct file *file, const char __user *buf,
if (IS_ERR(data)) { if (IS_ERR(data)) {
printk(KERN_ERR "%s: memdup_user returned error [%ld]\n", printk(KERN_ERR "%s: memdup_user returned error [%ld]\n",
__func__, PTR_ERR(data)); __func__, PTR_ERR(data));
goto out; return PTR_ERR(data);
} }
sz = count;
i = 0; i = 0;
switch (data[i++]) { switch (data[i++]) {
case ECRYPTFS_MSG_RESPONSE: case ECRYPTFS_MSG_RESPONSE:
...@@ -467,6 +465,7 @@ ecryptfs_miscdev_write(struct file *file, const char __user *buf, ...@@ -467,6 +465,7 @@ ecryptfs_miscdev_write(struct file *file, const char __user *buf,
__func__, __func__,
(1 + 4 + 1 + sizeof(struct ecryptfs_message)), (1 + 4 + 1 + sizeof(struct ecryptfs_message)),
count); count);
rc = -EINVAL;
goto out_free; goto out_free;
} }
memcpy(&counter_nbo, &data[i], 4); memcpy(&counter_nbo, &data[i], 4);
...@@ -475,10 +474,12 @@ ecryptfs_miscdev_write(struct file *file, const char __user *buf, ...@@ -475,10 +474,12 @@ ecryptfs_miscdev_write(struct file *file, const char __user *buf,
rc = ecryptfs_miscdev_response(&data[i], packet_size, rc = ecryptfs_miscdev_response(&data[i], packet_size,
euid, current_user_ns(), euid, current_user_ns(),
task_pid(current), seq); task_pid(current), seq);
if (rc) if (rc) {
printk(KERN_WARNING "%s: Failed to deliver miscdev " printk(KERN_WARNING "%s: Failed to deliver miscdev "
"response to requesting operation; rc = [%d]\n", "response to requesting operation; rc = [%zd]\n",
__func__, rc); __func__, rc);
goto out_free;
}
break; break;
case ECRYPTFS_MSG_HELO: case ECRYPTFS_MSG_HELO:
case ECRYPTFS_MSG_QUIT: case ECRYPTFS_MSG_QUIT:
...@@ -487,12 +488,13 @@ ecryptfs_miscdev_write(struct file *file, const char __user *buf, ...@@ -487,12 +488,13 @@ ecryptfs_miscdev_write(struct file *file, const char __user *buf,
ecryptfs_printk(KERN_WARNING, "Dropping miscdev " ecryptfs_printk(KERN_WARNING, "Dropping miscdev "
"message of unrecognized type [%d]\n", "message of unrecognized type [%d]\n",
data[0]); data[0]);
break; rc = -EINVAL;
goto out_free;
} }
rc = count;
out_free: out_free:
kfree(data); kfree(data);
out: return rc;
return sz;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment