Skip to content

Commit c2ae55c

Browse files
committed
1) Fixed a problem in AES-MT where it would crash if the stack size for the
threads isn't large enough. In Linux it's 8MB (which oveersized) and in things like Alpine its (128k). Set it to 1MB. 2) Added a routine that will fix issues when it's being built under Alpine. This allows for some stack metrics to be gathered. This changed metrics.h metrics.c and configure.ac. The change in configure.ac is to automatically check if the application is being built under Alpine. This reads /etc/os-release and parses out the OS ID. Right now the only test in the case statement is for Alpine but now we have a system if we need more stuff like this. 3) minor change to a typedef in the CC20 fastXOR. Should be a little more portable.
1 parent 58388ff commit c2ae55c

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
lines changed

cipher-chachapoly-libcrypto-mt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ fastXOR(u_char *dest, const u_char *src, const u_char *keystream, u_int len)
493493

494494
/* XXX: this was __uint128_t but that was causing unaligned load errors.
495495
* this works but we need to explore it more. */
496-
typedef __uint32_t chunk;
496+
typedef uint32_t chunk;
497497
size_t i;
498498
for (i=0; i < (len / sizeof(chunk)); i++)
499499
((chunk *)dest)[i]=((chunk *)src)[i]^((chunk *)keystream)[i];

cipher-ctr-mt-functions.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,10 +517,17 @@ int aes_mt_start_threads(void *vevp_ctx, const u_char *key,
517517
aes_mt_ctx->ridx = 0;
518518
aes_mt_ctx->struct_id = global_struct_id++;
519519

520-
/* Start threads */
520+
/* Start threads. Make sure we have enough stack space (under alpine)
521+
* and aren't using more than we need (linux). This can be as low as
522+
* 512KB but that's a minimum. 1024KB gives us a little headroom if we
523+
* need it */
524+
#define STACK_SIZE (1024 * 1024)
525+
pthread_attr_t attr;
526+
pthread_attr_init(&attr);
527+
pthread_attr_setstacksize(&attr, STACK_SIZE);
521528
for (int i = 0; i < cipher_threads; i++) {
522529
pthread_rwlock_wrlock(&aes_mt_ctx->tid_lock);
523-
if (pthread_create(&aes_mt_ctx->tid[i], NULL, thread_loop, aes_mt_ctx) != 0)
530+
if (pthread_create(&aes_mt_ctx->tid[i], &attr, thread_loop, aes_mt_ctx) != 0)
524531
fatal ("AES-CTR MT Could not create thread in %s", __func__);
525532
else {
526533
aes_mt_ctx->id[i] = i;

configure.ac

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2680,6 +2680,15 @@ AC_CHECK_FUNCS([getpgrp],[
26802680
)
26812681
])
26822682

2683+
# Look for OS Type (alpine, fedora, bsd, etc)
2684+
# Only need this for alpine at the moment it may be useful in the future
2685+
os_type=$(grep '^ID=' /etc/os-release | awk -F "=" '{print $2}')
2686+
AC_MSG_CHECKING([OS type: "$os_type"])
2687+
case "$os_type" in
2688+
alpine) AC_DEFINE([__alpine__], [1], [Alpine Linux])
2689+
;;
2690+
esac
2691+
26832692
# Search for OpenSSL
26842693
saved_CPPFLAGS="$CPPFLAGS"
26852694
saved_LDFLAGS="$LDFLAGS"

metrics.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
#include "metrics.h"
2020
#include "ssherr.h"
2121
#include <stdlib.h>
22-
#ifdef __linux__
22+
#include <stdio.h>
23+
#if defined(__linux__) && !defined(__alpine__)
2324
#include <linux/version.h>
2425
#endif
2526

@@ -45,7 +46,7 @@ metrics_write_binn_object(struct tcp_info *data, struct binn_struct *binnobj) {
4546
* on non linux systems we set the kernel version to 0
4647
* which will get us the base set of metrics from netinet/tcp.h
4748
*/
48-
#ifdef __linux__
49+
#if (defined __linux__) && !defined(__alpine__)
4950
binn_object_set_uint32(binnobj, "kernel_version", LINUX_VERSION_CODE);
5051
#else
5152
binn_object_set_uint32(binnobj, "kernel_version", 0);

metrics.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
/* linux, freebsd, and netbsd have tcp_info structs.
2424
* I don't know about other systems so we disable this
2525
* functionality for them */
26-
#if defined __linux__ || defined __FreeBSD__ || defined __NetBSD__
26+
#if defined __linux__ || defined __FreeBSD__ || defined __NetBSD__ && !defined(__alpine__)
2727
#define TCP_INFO 1
28-
#if defined __linux__
28+
#if defined __linux__ && !defined(__alpine__)
2929
#include <linux/tcp.h>
3030
#else
3131
#include <netinet/tcp.h>

0 commit comments

Comments
 (0)