Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
354e57ac
Commit
354e57ac
authored
Aug 21, 2013
by
Christian Heimes
Browse files
Options
Browse Files
Download
Plain Diff
merge
parents
a2697728
30212195
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
91 additions
and
0 deletions
+91
-0
Misc/NEWS
Misc/NEWS
+4
-0
Modules/_ssl.c
Modules/_ssl.c
+72
-0
configure
configure
+11
-0
configure.ac
configure.ac
+1
-0
pyconfig.h.in
pyconfig.h.in
+3
-0
No files found.
Misc/NEWS
View file @
354e57ac
...
...
@@ -32,6 +32,10 @@ Core and Builtins
Library
-------
- Issue #18747: Re-seed OpenSSL'
s
pseudo
-
random
number
generator
after
fork
.
A
pthread_atfork
()
child
handler
is
used
to
seeded
the
PRNG
with
pid
,
time
and
some
stack
data
.
-
Issue
#
8865
:
Concurrent
invocation
of
select
.
poll
.
poll
()
now
raises
a
RuntimeError
exception
.
Patch
by
Christian
Schubert
.
...
...
Modules/_ssl.c
View file @
354e57ac
...
...
@@ -18,6 +18,11 @@
#ifdef WITH_THREAD
#include "pythread.h"
#ifdef HAVE_PTHREAD_ATFORK
# include <pthread.h>
#endif
#define PySSL_BEGIN_ALLOW_THREADS { \
PyThreadState *_save = NULL; \
if (_ssl_locks_count>0) {_save = PyEval_SaveThread();}
...
...
@@ -1621,7 +1626,69 @@ Queries the entropy gather daemon (EGD) on the socket named by 'path'.\n\
Returns number of bytes read. Raises SSLError if connection to EGD
\n
\
fails or if it does not provide enough data to seed PRNG."
);
/* Seed OpenSSL's PRNG at fork(), http://bugs.python.org/issue18747
*
* The child handler seeds the PRNG from pseudo-random data like pid, the
* current time (nanoseconds, miliseconds or seconds) and an uninitialized
* array. The array contains stack variables that are impossible to predict
* on most systems, e.g. function return address (subject to ASLR), the
* stack protection canary and automatic variables.
* The code is inspired by Apache's ssl_rand_seed() function.
*
* Note:
* The code uses pthread_atfork() until Python has a proper atfork API. The
* handlers are not removed from the child process.
*/
#if defined(HAVE_PTHREAD_ATFORK) && defined(WITH_THREAD)
#define PYSSL_RAND_ATFORK 1
static
void
PySSL_RAND_atfork_child
(
void
)
{
struct
{
char
stack
[
128
];
/* uninitialized (!) stack data, 128 is an
arbitrary number. */
pid_t
pid
;
/* current pid */
time_t
time
;
/* current time */
}
seed
;
#ifdef WITH_VALGRIND
VALGRIND_MAKE_MEM_DEFINED
(
seed
.
stack
,
sizeof
(
seed
.
stack
));
#endif
seed
.
pid
=
getpid
();
seed
.
time
=
time
(
NULL
);
#if 0
fprintf(stderr, "PySSL_RAND_atfork_child() seeds %i bytes in pid %i\n",
(int)sizeof(seed), seed.pid);
#endif
RAND_add
((
unsigned
char
*
)
&
seed
,
sizeof
(
seed
),
0
.
0
);
}
static
int
PySSL_RAND_atfork
(
void
)
{
static
int
registered
=
0
;
int
retval
;
if
(
registered
)
return
0
;
retval
=
pthread_atfork
(
NULL
,
/* prepare */
NULL
,
/* parent */
PySSL_RAND_atfork_child
);
/* child */
if
(
retval
!=
0
)
{
PyErr_SetFromErrno
(
PyExc_OSError
);
return
-
1
;
}
registered
=
1
;
return
0
;
}
#endif
/* HAVE_PTHREAD_ATFORK */
#endif
/* HAVE_OPENSSL_RAND */
/* List of functions exported by this module. */
...
...
@@ -1833,4 +1900,9 @@ init_ssl(void)
r
=
PyString_FromString
(
SSLeay_version
(
SSLEAY_VERSION
));
if
(
r
==
NULL
||
PyModule_AddObject
(
m
,
"OPENSSL_VERSION"
,
r
))
return
;
#ifdef PYSSL_RAND_ATFORK
if
(
PySSL_RAND_atfork
()
==
-
1
)
return
;
#endif
}
configure
View file @
354e57ac
...
...
@@ -9627,6 +9627,17 @@ $as_echo "#define HAVE_BROKEN_PTHREAD_SIGMASK 1" >>confdefs.h
;;
esac
fi
done
for
ac_func
in
pthread_atfork
do
:
ac_fn_c_check_func
"
$LINENO
"
"pthread_atfork"
"ac_cv_func_pthread_atfork"
if
test
"x
$ac_cv_func_pthread_atfork
"
=
xyes
;
then
:
cat
>>
confdefs.h
<<
_ACEOF
#define HAVE_PTHREAD_ATFORK 1
_ACEOF
fi
done
...
...
configure.ac
View file @
354e57ac
...
...
@@ -2569,6 +2569,7 @@ if test "$posix_threads" = "yes"; then
[Define if pthread_sigmask() does not work on your system.])
;;
esac])
AC_CHECK_FUNCS(pthread_atfork)
fi
...
...
pyconfig.h.in
View file @
354e57ac
...
...
@@ -520,6 +520,9 @@
/* Define if you have GNU PTH threads. */
#undef HAVE_PTH
/* Define to 1 if you have the `pthread_atfork' function. */
#undef HAVE_PTHREAD_ATFORK
/* Defined for Solaris 2.6 bug in pthread header. */
#undef HAVE_PTHREAD_DESTRUCTOR
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment