[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[hurd] 07/75: random: satisfy arbitrarily-sized reads
From: |
Samuel Thibault |
Subject: |
[hurd] 07/75: random: satisfy arbitrarily-sized reads |
Date: |
Thu, 14 Jan 2016 01:04:01 +0000 |
This is an automated email from the git hooks/post-receive script.
sthibault pushed a commit to branch dde
in repository hurd.
commit df778cd01505e3a8c11f5b13f5ee26a4be290f9a
Author: Justus Winter <address@hidden>
Date: Fri Nov 6 14:42:04 2015 +0100
random: satisfy arbitrarily-sized reads
* random/random.c (trivfs_S_io_read): Satisfy arbitrarily-sized reads.
---
random/random.c | 41 ++++++++++++++++++++++++++++++-----------
1 file changed, 30 insertions(+), 11 deletions(-)
diff --git a/random/random.c b/random/random.c
index f926b7f..8f76c5b 100644
--- a/random/random.c
+++ b/random/random.c
@@ -143,6 +143,11 @@ trivfs_S_io_read (struct trivfs_protid *cred,
data_t *data, mach_msg_type_number_t *data_len,
loff_t offs, mach_msg_type_number_t amount)
{
+ error_t err;
+ mach_msg_type_number_t read_amount = 0;
+ void *buf = NULL;
+ size_t length;
+
/* Deny access if they have bad credentials. */
if (! cred)
return EOPNOTSUPP;
@@ -151,21 +156,27 @@ trivfs_S_io_read (struct trivfs_protid *cred,
pthread_mutex_lock (&global_lock);
- if (amount > 0)
+ while (amount > 0)
{
mach_msg_type_number_t new_amount;
+ /* XXX: It would be nice to fix readable_pool to work for sizes
+ greater than the POOLSIZE. Otherwise we risk detecting too
+ late that we run out of entropy and all that entropy is
+ wasted. */
while (readable_pool (amount, level) == 0)
{
if (cred->po->openmodes & O_NONBLOCK)
{
pthread_mutex_unlock (&global_lock);
- return EWOULDBLOCK;
+ err = EWOULDBLOCK;
+ goto errout;
}
read_blocked = 1;
if (pthread_hurd_cond_wait_np (&wait, &global_lock))
{
pthread_mutex_unlock (&global_lock);
- return EINTR;
+ err = EINTR;
+ goto errout;
}
/* See term/users.c for possible race? */
}
@@ -175,27 +186,35 @@ trivfs_S_io_read (struct trivfs_protid *cred,
{
*data = mmap (0, amount, PROT_READ|PROT_WRITE,
MAP_ANON, 0, 0);
+
if (*data == MAP_FAILED)
{
pthread_mutex_unlock (&global_lock);
return errno;
}
- }
- new_amount = read_pool ((byte *) *data, amount, level);
+ /* Keep track of our map in case of errors. */
+ buf = *data, length = amount;
- if (new_amount < amount)
- munmap (*data + round_page (new_amount),
- round_page(amount) - round_page (new_amount));
- amount = new_amount;
+ /* Update DATA_LEN to reflect the new buffers size. */
+ *data_len = amount;
+ }
+
+ new_amount = read_pool (((byte *) *data) + read_amount, amount, level);
+ read_amount += new_amount;
+ amount -= new_amount;
}
- *data_len = amount;
/* Set atime, see term/users.c */
pthread_mutex_unlock (&global_lock);
-
+ *data_len = read_amount;
return 0;
+
+ errout:
+ if (buf)
+ munmap (buf, length);
+ return err;
}
/* Write data to an IO object. If offset is -1, write at the object
--
Alioth's /usr/local/bin/git-commit-notice on
/srv/git.debian.org/git/pkg-hurd/hurd.git
- [hurd] branch dde updated (c7fdc30 -> cb08549), Samuel Thibault, 2016/01/13
- [hurd] 04/75: random: fix odd formatting, Samuel Thibault, 2016/01/13
- [hurd] 06/75: random: use /servers/startup to register for shutdown notifications, Samuel Thibault, 2016/01/13
- [hurd] 07/75: random: satisfy arbitrarily-sized reads,
Samuel Thibault <=
- [hurd] 08/75: libihash: add hurd_ihash_value_valid, Samuel Thibault, 2016/01/13
- [hurd] 10/75: libihash: prefer performance degradation over failure, Samuel Thibault, 2016/01/13
- [hurd] 11/75: Make dde conditionally built under presence of libpciaccess, Samuel Thibault, 2016/01/13
- [hurd] 13/75: Clean debugging macro, Samuel Thibault, 2016/01/13
- [hurd] 09/75: libihash: optimize lookup-or-insert operations, Samuel Thibault, 2016/01/13
- [hurd] 03/75: Remove unused variables, Samuel Thibault, 2016/01/13
- [hurd] 17/75: Merge branch 'master' of git.savannah.gnu.org:/srv/git/hurd/hurd into dde, Samuel Thibault, 2016/01/13
- [hurd] 19/75: Add devnode documentation, Samuel Thibault, 2016/01/13
- [hurd] 23/75: Add missing menus, Samuel Thibault, 2016/01/13
- [hurd] 20/75: Merge branch 'master' of git.savannah.gnu.org:/srv/git/hurd/hurd into dde, Samuel Thibault, 2016/01/13