aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTyler Hicks <tyhicks@canonical.com>2012-01-14 09:51:37 -0500
committerTyler Hicks <tyhicks@canonical.com>2012-01-25 15:43:39 -0500
commit7f133504249afa48618becac546ce3c35c9f0185 (patch)
tree0aa0044c7074095e15ac86a6f1be00c5bc0df8f7
parentdb10e556518eb9d21ee92ff944530d84349684f4 (diff)
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: Tyler Hicks <tyhicks@canonical.com>
-rw-r--r--fs/ecryptfs/miscdev.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
index 0dc5a3d554a4..1145c58103e2 100644
--- a/fs/ecryptfs/miscdev.c
+++ b/fs/ecryptfs/miscdev.c
@@ -406,14 +406,13 @@ ecryptfs_miscdev_write(struct file *file, const char __user *buf,
406 __be32 counter_nbo; 406 __be32 counter_nbo;
407 u32 seq; 407 u32 seq;
408 size_t packet_size, packet_size_length, i; 408 size_t packet_size, packet_size_length, i;
409 ssize_t sz = 0;
410 char *data; 409 char *data;
411 uid_t euid = current_euid(); 410 uid_t euid = current_euid();
412 unsigned char packet_size_peek[3]; 411 unsigned char packet_size_peek[3];
413 int rc; 412 ssize_t rc;
414 413
415 if (count == 0) { 414 if (count == 0) {
416 goto out; 415 return 0;
417 } else if (count == (1 + 4)) { 416 } else if (count == (1 + 4)) {
418 /* Likely a harmless MSG_HELO or MSG_QUIT - no packet length */ 417 /* Likely a harmless MSG_HELO or MSG_QUIT - no packet length */
419 goto memdup; 418 goto memdup;
@@ -439,7 +438,7 @@ ecryptfs_miscdev_write(struct file *file, const char __user *buf,
439 &packet_size_length); 438 &packet_size_length);
440 if (rc) { 439 if (rc) {
441 printk(KERN_WARNING "%s: Error parsing packet length; " 440 printk(KERN_WARNING "%s: Error parsing packet length; "
442 "rc = [%d]\n", __func__, rc); 441 "rc = [%zd]\n", __func__, rc);
443 return rc; 442 return rc;
444 } 443 }
445 444
@@ -454,9 +453,8 @@ memdup:
454 if (IS_ERR(data)) { 453 if (IS_ERR(data)) {
455 printk(KERN_ERR "%s: memdup_user returned error [%ld]\n", 454 printk(KERN_ERR "%s: memdup_user returned error [%ld]\n",
456 __func__, PTR_ERR(data)); 455 __func__, PTR_ERR(data));
457 goto out; 456 return PTR_ERR(data);
458 } 457 }
459 sz = count;
460 i = 0; 458 i = 0;
461 switch (data[i++]) { 459 switch (data[i++]) {
462 case ECRYPTFS_MSG_RESPONSE: 460 case ECRYPTFS_MSG_RESPONSE:
@@ -467,6 +465,7 @@ memdup:
467 __func__, 465 __func__,
468 (1 + 4 + 1 + sizeof(struct ecryptfs_message)), 466 (1 + 4 + 1 + sizeof(struct ecryptfs_message)),
469 count); 467 count);
468 rc = -EINVAL;
470 goto out_free; 469 goto out_free;
471 } 470 }
472 memcpy(&counter_nbo, &data[i], 4); 471 memcpy(&counter_nbo, &data[i], 4);
@@ -475,10 +474,12 @@ memdup:
475 rc = ecryptfs_miscdev_response(&data[i], packet_size, 474 rc = ecryptfs_miscdev_response(&data[i], packet_size,
476 euid, current_user_ns(), 475 euid, current_user_ns(),
477 task_pid(current), seq); 476 task_pid(current), seq);
478 if (rc) 477 if (rc) {
479 printk(KERN_WARNING "%s: Failed to deliver miscdev " 478 printk(KERN_WARNING "%s: Failed to deliver miscdev "
480 "response to requesting operation; rc = [%d]\n", 479 "response to requesting operation; rc = [%zd]\n",
481 __func__, rc); 480 __func__, rc);
481 goto out_free;
482 }
482 break; 483 break;
483 case ECRYPTFS_MSG_HELO: 484 case ECRYPTFS_MSG_HELO:
484 case ECRYPTFS_MSG_QUIT: 485 case ECRYPTFS_MSG_QUIT:
@@ -487,12 +488,13 @@ memdup:
487 ecryptfs_printk(KERN_WARNING, "Dropping miscdev " 488 ecryptfs_printk(KERN_WARNING, "Dropping miscdev "
488 "message of unrecognized type [%d]\n", 489 "message of unrecognized type [%d]\n",
489 data[0]); 490 data[0]);
490 break; 491 rc = -EINVAL;
492 goto out_free;
491 } 493 }
494 rc = count;
492out_free: 495out_free:
493 kfree(data); 496 kfree(data);
494out: 497 return rc;
495 return sz;
496} 498}
497 499
498 500