From 494c6264145f989001e9cde0ad06e1f6d94f1a66 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Fri, 25 Oct 2013 12:21:59 +0000 Subject: [PATCH] * devices.in (dev_storage): Map /dev/random and /dev/urandom to \Device\Null. * devices.cc: Regenerate. * fhandler.h (fhandler_dev_random::open): Drop declaration. (fhandler_dev_random::close): Ditto. (fhandler_dev_random::crypt_gen_random): Convert to static method. * fhandler_random.cc (fhandler_dev_random::open): Remove so that default fhandler_base::open is used to open \Device\Null. (fhandler_dev_random::close): Ditto. * fhandler_socket.cc (entropy_source): Delete. (fhandler_socket::af_local_set_secret): Remove entropy_source code and call fhandler_dev_random::crypt_gen_random directly instead. --- winsup/cygwin/ChangeLog | 15 +++++++++++++++ winsup/cygwin/devices.cc | 4 ++-- winsup/cygwin/devices.in | 4 ++-- winsup/cygwin/fhandler.h | 5 ++--- winsup/cygwin/fhandler_random.cc | 15 --------------- winsup/cygwin/fhandler_socket.cc | 24 +++--------------------- winsup/cygwin/release/1.7.26 | 6 +++--- 7 files changed, 27 insertions(+), 46 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 8ae3e44c2..784013787 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,18 @@ +2013-10-25 Corinna Vinschen + + * devices.in (dev_storage): Map /dev/random and /dev/urandom to + \Device\Null. + * devices.cc: Regenerate. + * fhandler.h (fhandler_dev_random::open): Drop declaration. + (fhandler_dev_random::close): Ditto. + (fhandler_dev_random::crypt_gen_random): Convert to static method. + * fhandler_random.cc (fhandler_dev_random::open): Remove so that default + fhandler_base::open is used to open \Device\Null. + (fhandler_dev_random::close): Ditto. + * fhandler_socket.cc (entropy_source): Delete. + (fhandler_socket::af_local_set_secret): Remove entropy_source code and + call fhandler_dev_random::crypt_gen_random directly instead. + 2013-10-24 Corinna Vinschen * fhandler.h (fhandler_dev_zero::lseek): Convert to inline method. diff --git a/winsup/cygwin/devices.cc b/winsup/cygwin/devices.cc index fd2e7e16d..2e36dc85f 100644 --- a/winsup/cygwin/devices.cc +++ b/winsup/cygwin/devices.cc @@ -439,7 +439,7 @@ const _RDATA device dev_storage[] = {"/dev/pty61", BRACK(FHDEV(DEV_PTYS_MAJOR, 61)), "/dev/pty61", exists_pty, S_IFCHR, true}, {"/dev/pty62", BRACK(FHDEV(DEV_PTYS_MAJOR, 62)), "/dev/pty62", exists_pty, S_IFCHR, true}, {"/dev/pty63", BRACK(FHDEV(DEV_PTYS_MAJOR, 63)), "/dev/pty63", exists_pty, S_IFCHR, true}, - {"/dev/random", BRACK(FH_RANDOM), "/dev/random", exists, S_IFCHR, true}, + {"/dev/random", BRACK(FH_RANDOM), "\\Device\\Null", exists_ntdev, S_IFCHR, true}, {"/dev/scd0", BRACK(FHDEV(DEV_CDROM_MAJOR, 0)), "\\Device\\CdRom0", exists_ntdev, S_IFBLK, true}, {"/dev/scd1", BRACK(FHDEV(DEV_CDROM_MAJOR, 1)), "\\Device\\CdRom1", exists_ntdev, S_IFBLK, true}, {"/dev/scd2", BRACK(FHDEV(DEV_CDROM_MAJOR, 2)), "\\Device\\CdRom2", exists_ntdev, S_IFBLK, true}, @@ -2713,7 +2713,7 @@ const _RDATA device dev_storage[] = {"/dev/ttyS61", BRACK(FHDEV(DEV_SERIAL_MAJOR, 61)), "\\??\\COM62", exists_ntdev, S_IFCHR, true}, {"/dev/ttyS62", BRACK(FHDEV(DEV_SERIAL_MAJOR, 62)), "\\??\\COM63", exists_ntdev, S_IFCHR, true}, {"/dev/ttyS63", BRACK(FHDEV(DEV_SERIAL_MAJOR, 63)), "\\??\\COM64", exists_ntdev, S_IFCHR, true}, - {"/dev/urandom", BRACK(FH_URANDOM), "/dev/urandom", exists, S_IFCHR, true}, + {"/dev/urandom", BRACK(FH_URANDOM), "\\Device\\Null", exists_ntdev, S_IFCHR, true}, {"/dev/windows", BRACK(FH_WINDOWS), "/dev/windows", exists, S_IFCHR, true}, {"/dev/zero", BRACK(FH_ZERO), "\\Device\\Null", exists_ntdev, S_IFCHR, true}, {":fifo", BRACK(FH_FIFO), "/dev/fifo", exists_internal, S_IFCHR, false}, diff --git a/winsup/cygwin/devices.in b/winsup/cygwin/devices.in index ea26a5337..a297b31f6 100644 --- a/winsup/cygwin/devices.in +++ b/winsup/cygwin/devices.in @@ -154,8 +154,8 @@ const device dev_error_storage = "/dev/null", BRACK(FH_NULL), "\\Device\\Null", exists_ntdev, S_IFCHR "/dev/zero", BRACK(FH_ZERO), "\\Device\\Null", exists_ntdev, S_IFCHR "/dev/full", BRACK(FH_FULL), "\\Device\\Null", exists_ntdev, S_IFCHR -"/dev/random", BRACK(FH_RANDOM), "/dev/random", exists, S_IFCHR -"/dev/urandom", BRACK(FH_URANDOM), "/dev/urandom", exists, S_IFCHR, =urandom_dev +"/dev/random", BRACK(FH_RANDOM), "\\Device\\Null", exists_ntdev, S_IFCHR +"/dev/urandom", BRACK(FH_URANDOM), "\\Device\\Null", exists_ntdev, S_IFCHR, =urandom_dev "/dev/clipboard", BRACK(FH_CLIPBOARD), "/dev/clipboard", exists, S_IFCHR "/dev/com%(1-16)d", BRACK(FHDEV(DEV_SERIAL_MAJOR, {$1 - 1})), "\\??\\COM{$1}", exists_ntdev_silent, S_IFCHR "/dev/ttyS%(0-63)d", BRACK(FHDEV(DEV_SERIAL_MAJOR, {$1})), "\\??\\COM{$1 + 1}", exists_ntdev, S_IFCHR diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index 840a96125..bb10ea1bb 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -1654,16 +1654,15 @@ class fhandler_dev_random: public fhandler_base protected: uint32_t pseudo; - bool crypt_gen_random (void *ptr, size_t len); int pseudo_write (const void *ptr, size_t len); int pseudo_read (void *ptr, size_t len); public: - int open (int flags, mode_t mode = 0); ssize_t __stdcall write (const void *ptr, size_t len); void __reg3 read (void *ptr, size_t& len); off_t lseek (off_t, int) { return 0; } - int close (); + + static bool crypt_gen_random (void *ptr, size_t len); fhandler_dev_random () : fhandler_base () {} fhandler_dev_random (void *) {} diff --git a/winsup/cygwin/fhandler_random.cc b/winsup/cygwin/fhandler_random.cc index 85624c038..0d28738de 100644 --- a/winsup/cygwin/fhandler_random.cc +++ b/winsup/cygwin/fhandler_random.cc @@ -28,15 +28,6 @@ details. */ #define PSEUDO_MULTIPLIER (6364136223846793005LL) #define PSEUDO_SHIFTVAL (21) -int -fhandler_dev_random::open (int flags, mode_t) -{ - set_flags ((flags & ~O_TEXT) | O_BINARY); - nohandle (true); - set_open_status (); - return 1; -} - /* There's a bug in ntsecapi.h (Mingw as well as MSFT). SystemFunction036 is, in fact, a WINAPI function, but it's not defined as such. Therefore we have to do it correctly here. */ @@ -149,9 +140,3 @@ fhandler_dev_random::read (void *ptr, size_t& len) else if (!crypt_gen_random (ptr, len)) len = pseudo_read (ptr, len); } - -int -fhandler_dev_random::close () -{ - return 0; -} diff --git a/winsup/cygwin/fhandler_socket.cc b/winsup/cygwin/fhandler_socket.cc index b2a7f5c82..f79e89950 100644 --- a/winsup/cygwin/fhandler_socket.cc +++ b/winsup/cygwin/fhandler_socket.cc @@ -48,8 +48,6 @@ extern "C" { int sscanf (const char *, const char *, ...); } /* End of "C" section */ -fhandler_dev_random* entropy_source; - static inline mode_t adjust_socket_file_mode (mode_t mode) { @@ -445,25 +443,9 @@ fhandler_socket::af_local_copy (fhandler_socket *sock) void fhandler_socket::af_local_set_secret (char *buf) { - if (!entropy_source) - { - void *buf = malloc (sizeof (fhandler_dev_random)); - entropy_source = new (buf) fhandler_dev_random (); - entropy_source->dev () = *urandom_dev; - } - if (entropy_source && - !entropy_source->open (O_RDONLY)) - { - delete entropy_source; - entropy_source = NULL; - } - if (entropy_source) - { - size_t len = sizeof (connect_secret); - entropy_source->read (connect_secret, len); - if (len != sizeof (connect_secret)) - bzero ((char*) connect_secret, sizeof (connect_secret)); - } + if (!fhandler_dev_random::crypt_gen_random (connect_secret, + sizeof (connect_secret))) + bzero ((char*) connect_secret, sizeof (connect_secret)); __small_sprintf (buf, "%08x-%08x-%08x-%08x", connect_secret [0], connect_secret [1], connect_secret [2], connect_secret [3]); diff --git a/winsup/cygwin/release/1.7.26 b/winsup/cygwin/release/1.7.26 index 3656715fa..ca0170bbd 100644 --- a/winsup/cygwin/release/1.7.26 +++ b/winsup/cygwin/release/1.7.26 @@ -7,9 +7,9 @@ What changed: - Slightly improve randomness of /dev/random emulation. -- Allow to use advisory locking on any device which is backed by an OS handle. - Right now this excludes /dev/clipboard, /dev/dsp, /dev/random, /dev/urandom, - as well as almost all virtual files under /proc. +- Allow to use advisory locking on any device which is backed by an OS + handle. Right now this excludes /dev/clipboard, /dev/dsp, as well as + almost all virtual files under /proc. Bug fixes: