|
19 | 19 | #ifdef WITH_THREAD |
20 | 20 | #include "pythread.h" |
21 | 21 |
|
22 | | -#ifdef HAVE_PTHREAD_ATFORK |
23 | | -# include <pthread.h> |
24 | | -#endif |
25 | 22 |
|
26 | 23 | #define PySSL_BEGIN_ALLOW_THREADS_S(save) \ |
27 | 24 | do { if (_ssl_locks_count>0) { (save) = PyEval_SaveThread(); } } while (0) |
@@ -2950,65 +2947,6 @@ Queries the entropy gather daemon (EGD) on the socket named by 'path'.\n\ |
2950 | 2947 | Returns number of bytes read. Raises SSLError if connection to EGD\n\ |
2951 | 2948 | fails or if it does not provide enough data to seed PRNG."); |
2952 | 2949 |
|
2953 | | -/* Seed OpenSSL's PRNG at fork(), http://bugs.python.org/issue18747 |
2954 | | - * |
2955 | | - * The prepare handler seeds the PRNG from pseudo-random data like pid, the |
2956 | | - * current time (miliseconds or seconds) and an uninitialized array. |
2957 | | - * The array contains stack variables that are impossible to predict |
2958 | | - * on most systems, e.g. function return address (subject to ASLR), the |
2959 | | - * stack protection canary and automatic variables. |
2960 | | - * The code is inspired by Apache's ssl_rand_seed() function. |
2961 | | - * |
2962 | | - * Note: |
2963 | | - * The code uses pthread_atfork() until Python has a proper atfork API. The |
2964 | | - * handlers are not removed from the child process. A prepare handler is used |
2965 | | - * instead of a child handler because fork() is supposed to be async-signal |
2966 | | - * safe but the handler calls unsafe functions. A parent handler has caused |
2967 | | - * other problems, see issue #19227. |
2968 | | - */ |
2969 | | - |
2970 | | -#if defined(HAVE_PTHREAD_ATFORK) && defined(WITH_THREAD) |
2971 | | -#define PYSSL_RAND_ATFORK 1 |
2972 | | - |
2973 | | -static void |
2974 | | -PySSL_RAND_atfork_prepare(void) |
2975 | | -{ |
2976 | | - struct { |
2977 | | - char stack[128]; /* uninitialized (!) stack data, 128 is an |
2978 | | - arbitrary number. */ |
2979 | | - pid_t pid; /* current pid */ |
2980 | | - _PyTime_timeval tp; /* current time */ |
2981 | | - } seed; |
2982 | | - |
2983 | | -#ifdef WITH_VALGRIND |
2984 | | - VALGRIND_MAKE_MEM_DEFINED(seed.stack, sizeof(seed.stack)); |
2985 | | -#endif |
2986 | | - seed.pid = getpid(); |
2987 | | - _PyTime_gettimeofday(&(seed.tp)); |
2988 | | - RAND_add((unsigned char *)&seed, sizeof(seed), 0.0); |
2989 | | -} |
2990 | | - |
2991 | | -static int |
2992 | | -PySSL_RAND_atfork(void) |
2993 | | -{ |
2994 | | - static int registered = 0; |
2995 | | - int retval; |
2996 | | - |
2997 | | - if (registered) |
2998 | | - return 0; |
2999 | | - |
3000 | | - retval = pthread_atfork(PySSL_RAND_atfork_prepare, /* prepare */ |
3001 | | - NULL, /* parent */ |
3002 | | - NULL); /* child */ |
3003 | | - if (retval != 0) { |
3004 | | - PyErr_SetFromErrno(PyExc_OSError); |
3005 | | - return -1; |
3006 | | - } |
3007 | | - registered = 1; |
3008 | | - return 0; |
3009 | | -} |
3010 | | -#endif /* HAVE_PTHREAD_ATFORK */ |
3011 | | - |
3012 | 2950 | #endif /* HAVE_OPENSSL_RAND */ |
3013 | 2951 |
|
3014 | 2952 |
|
@@ -3623,10 +3561,5 @@ PyInit__ssl(void) |
3623 | 3561 | if (r == NULL || PyModule_AddObject(m, "_OPENSSL_API_VERSION", r)) |
3624 | 3562 | return NULL; |
3625 | 3563 |
|
3626 | | -#ifdef PYSSL_RAND_ATFORK |
3627 | | - if (PySSL_RAND_atfork() == -1) |
3628 | | - return NULL; |
3629 | | -#endif |
3630 | | - |
3631 | 3564 | return m; |
3632 | 3565 | } |
0 commit comments