Skip to content

Commit 59b2f66

Browse files
authored
FIX: Improve PRNG seeding on Windows to ensure uniqueness of generated numbers (#5265)
Fix for the pseudo-random seed on Windows. The function `rand_r` isn't present on Windows and the global seed wasn't based on the current microseconds and thread id. Also it wasn't called on every thread as required on this platform but only once per process. The fix allows on this platform the uniqueness of client side member id generation in next-generation consumer group protocol. Happening since 1.x * Multiple platforms secure random generation * Run KIP-848 tests on MinGW-w64 * Changes to srand per thread on Windows. It's necessary on Windows to avoid using the same jitter values for all clients and avoid a stampede effect on brokers. * Run macOS local quick tests with KIP-848 as well * Run KIP-848 local quick tests on arm64 glibc and alpine * Increase 0153 with a different number of maximum open files
1 parent fdfc8d4 commit 59b2f66

26 files changed

+374
-114
lines changed

.semaphore/semaphore-integration.yml

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,7 @@ blocks:
4747
jobs:
4848
- name: 'Build'
4949
commands:
50-
- ./configure --install-deps --source-deps-only --enable-static --disable-lz4-ext --enable-strip
51-
- make -j all examples check
52-
- examples/rdkafka_example -X builtin.features
53-
- otool -L src/librdkafka.dylib
54-
- otool -L src-cpp/librdkafka++.dylib
55-
- make -j -C tests build
56-
- make -C tests run_local_quick
57-
- DESTDIR="$PWD/dest" make install
58-
- (cd dest && tar cvzf ../artifacts/librdkafka.tgz .)
50+
- packaging/macos/build-release-artifacts.sh
5951

6052

6153
- name: 'OSX x64'
@@ -73,15 +65,7 @@ blocks:
7365
jobs:
7466
- name: 'Build'
7567
commands:
76-
- ./configure --install-deps --source-deps-only --enable-static --disable-lz4-ext --enable-strip
77-
- make -j all examples check
78-
- examples/rdkafka_example -X builtin.features
79-
- otool -L src/librdkafka.dylib
80-
- otool -L src-cpp/librdkafka++.dylib
81-
- make -j -C tests build
82-
- make -C tests run_local_quick
83-
- DESTDIR="$PWD/dest" make install
84-
- (cd dest && tar cvzf ../artifacts/librdkafka.tgz .)
68+
- packaging/macos/build-release-artifacts.sh
8569

8670
- name: 'Linux Ubuntu amd64: integration tests'
8771
dependencies: []

CHANGELOG.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@
22

33
librdkafka v2.13.0 is a feature release:
44

5-
* Strip trailing dot of hostname to fix SSL certificate verification issue (#5253).
65
* [KIP-482](https://cwiki.apache.org/confluence/display/KAFKA/KIP-482%3A+The+Kafka+Protocol+should+Support+Optional+Tagged+Fields) Upgrade CreateAcls, DescribeAcls, DeleteAcls to the first version supporting this KIP (#5081).
76
* [KIP-482](https://cwiki.apache.org/confluence/display/KAFKA/KIP-482%3A+The+Kafka+Protocol+should+Support+Optional+Tagged+Fields) Upgrade DescribeGroups, DeleteTopics, DeleteRecords, CreatePartitions, DeleteGroups to the first version supporting this KIP (#5083).
7+
* Strip trailing dot of hostname to fix SSL certificate verification issue (#5253).
8+
* Fix memory management for interceptors in rd_kafka_conf to prevent
9+
double-free errors (#5240).
10+
* Fix for the pseudo-random generator seed on Windows involving as well
11+
the uniqueness of the new consumer group protocol member id (#5265).
12+
* Add secure random generation functionality used for UUID uniqueness
13+
and secure salt generation in `rd_kafka_UserScramCredentialUpsertion`
14+
using OpenSSL or the POSIX or WIN32 equivalent calls when it
15+
isn't available (#5265).
816

917

1018
## Fixes
@@ -14,6 +22,19 @@ librdkafka v2.13.0 is a feature release:
1422
* Issues: #4348.
1523
Strip trailing dot of hostname to fix SSL certificate verification issue.
1624
Happening since 1.x (#5253).
25+
* Issues: #4142.
26+
Fix memory management for interceptors in rd_kafka_conf to prevent double-free errors.
27+
In case the client instance fails the users needs to destroy the configuration
28+
data structure, it was causing a double-free because the interceptors were
29+
already freed in the constructor.
30+
Happening since 1.x (#5240).
31+
* Issues: #5263, #3929.
32+
Fix for the pseudo-random seed on Windows. The function `rand_r` isn't present
33+
on Windows and the global seed wasn't based on the current microseconds and thread
34+
id. Also it wasn't called on every thread as required on this platform but
35+
only once per process. The fix allows on this platform the uniqueness of client side
36+
member id generation in next-generation consumer group protocol.
37+
Happening since 1.x (#5265).
1738

1839

1940

configure.self

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,16 @@ void foo (void) {
216216
(void)rand_r(&seed);
217217
}"
218218

219+
# Check if getentropy() is available
220+
mkl_compile_check "getentropy" "HAVE_GETENTROPY" disable CC "" \
221+
"#define _DEFAULT_SOURCE
222+
#include <unistd.h>
223+
#include <sys/random.h>
224+
int foo (void) {
225+
char seed[16];
226+
return getentropy((void *)seed, sizeof(seed));
227+
}"
228+
219229
# Check if strndup() is available (isn't on Solaris 10)
220230
mkl_compile_check "strndup" "HAVE_STRNDUP" disable CC "" \
221231
"#include <string.h>

packaging/cmake/config.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#cmakedefine01 HAVE_REGEX
4444
#cmakedefine01 HAVE_STRNDUP
4545
#cmakedefine01 HAVE_RAND_R
46+
#cmakedefine01 HAVE_GETENTROPY
4647
#cmakedefine01 HAVE_PTHREAD_SETNAME_GNU
4748
#cmakedefine01 HAVE_PTHREAD_SETNAME_DARWIN
4849
#cmakedefine01 HAVE_PTHREAD_SETNAME_FREEBSD
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <unistd.h>
2+
#include <sys/random.h>
3+
4+
int main() {
5+
char seed[16];
6+
return getentropy(seed, sizeof(seed));
7+
}

packaging/cmake/try_compile/rdkafka_setup.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ try_compile(
1616
"${TRYCOMPILE_SRC_DIR}/rand_r_test.c"
1717
)
1818

19+
try_compile(
20+
HAVE_GETENTROPY
21+
"${CMAKE_CURRENT_BINARY_DIR}/try_compile"
22+
"${TRYCOMPILE_SRC_DIR}/getentropy_test.c"
23+
)
24+
1925
try_compile(
2026
HAVE_PTHREAD_SETNAME_GNU
2127
"${CMAKE_CURRENT_BINARY_DIR}/try_compile"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
./configure --install-deps --source-deps-only --enable-static --disable-lz4-ext --enable-strip
2+
make -j all examples check
3+
examples/rdkafka_example -X builtin.features
4+
otool -L src/librdkafka.dylib
5+
otool -L src-cpp/librdkafka++.dylib
6+
make -j -C tests build
7+
export TEST_CONSUMER_GROUP_PROTOCOL=classic
8+
make -C tests run_local_quick
9+
export TEST_CONSUMER_GROUP_PROTOCOL=consumer
10+
# Skip tests needing special limits
11+
TESTS_WITH_INCREASED_NLIMIT="0153"
12+
export TESTS_SKIP="$TESTS_WITH_INCREASED_NLIMIT"
13+
make -C tests run_local_quick
14+
# Now run only those tests with different limits
15+
16+
# Tests needing increased number of file descriptors
17+
PREV_N=$(ulimit -n)
18+
ulimit -n 2048
19+
export TESTS_SKIP=""
20+
export TESTS="$TESTS_WITH_INCREASED_NLIMIT"
21+
make -C tests run_local_quick
22+
ulimit -n $PREV_N
23+
24+
25+
DESTDIR="$PWD/dest" make install
26+
(cd dest && tar cvzf ../artifacts/librdkafka.tgz .)

packaging/mingw-w64/run-tests.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@
33
set -e
44

55
cd tests
6-
./test-runner.exe -l -Q -p1 0000
6+
export TEST_CONSUMER_GROUP_PROTOCOL=classic
7+
./test-runner.exe -l -Q -p1
8+
export TEST_CONSUMER_GROUP_PROTOCOL=consumer
9+
./test-runner.exe -l -Q -p1

packaging/tools/build-release-artifacts.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ fi
123123
# Run quick test suite, mark it as CI to avoid time/resource sensitive
124124
# tests to fail in case the worker is under-powered.
125125
CI=true make -C tests run_local_quick
126+
CI=true TEST_CONSUMER_GROUP_PROTOCOL=consumer make -C tests run_local_quick
126127

127128

128129
# Install librdkafka and then make a tar ball of the installed files.

src/rd.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@
4444
#ifndef _POSIX_C_SOURCE
4545
#define _POSIX_C_SOURCE 200809L /* for timespec on solaris */
4646
#endif
47+
#else
48+
#ifndef _CRT_RAND_S
49+
#define _CRT_RAND_S /* for rand_s() on MSVC. It needs to be defined before \
50+
* including <stdlib.h>. */
51+
#endif
4752
#endif
4853

4954
#include <stdio.h>

0 commit comments

Comments
 (0)