From 0f6dee2a45470f5418138c17411939b36a64015d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Witold=20Kr=C4=99cicki?= Date: Fri, 7 Sep 2018 09:34:32 +0200 Subject: [PATCH] Align CMSG buffers to a void* boundary, fixes crash on architectures with strict alignment CHANGES entry (cherry picked from commit 17212cf9965a1a0ec8412b807fe08f74e059cc1c) --- CHANGES | 3 +++ lib/isc/include/isc/util.h | 5 +++++ lib/isc/unix/socket.c | 5 +++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index cb24cc40ad..96134f8c68 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +5030. [bug] Align CMSG buffers to a 64-bit boundary, fixes crash + on architectures with strict alignment. [GL #521] + 5028. [bug] Spread the initial RRSIG expiration times over the entire working sig-validity-interval when signing a zone in named to even out re-signing and transfer diff --git a/lib/isc/include/isc/util.h b/lib/isc/include/isc/util.h index 332dc0c2b9..2ed0a2a4a9 100644 --- a/lib/isc/include/isc/util.h +++ b/lib/isc/include/isc/util.h @@ -234,6 +234,11 @@ */ #define TIME_NOW(tp) RUNTIME_CHECK(isc_time_now((tp)) == ISC_R_SUCCESS) +/*% + * Alignment + */ +#define ALIGN(x, a) (((x) + (a) - 1) & ~((typeof(x))(a)-1)) + /*% * Misc */ diff --git a/lib/isc/unix/socket.c b/lib/isc/unix/socket.c index d2ee1b0dca..229711d238 100644 --- a/lib/isc/unix/socket.c +++ b/lib/isc/unix/socket.c @@ -346,8 +346,9 @@ typedef isc_event_t intev_t; #define CMSG_SP_INT 24 -#define RECVCMSGBUFLEN (2*(CMSG_SP_IN6PKT + CMSG_SP_TIMESTAMP + CMSG_SP_TCTOS)+1) -#define SENDCMSGBUFLEN (2*(CMSG_SP_IN6PKT + CMSG_SP_INT + CMSG_SP_TCTOS)+1) +/* Align cmsg buffers to be safe on SPARC etc. */ +#define RECVCMSGBUFLEN ALIGN(2*(CMSG_SP_IN6PKT + CMSG_SP_TIMESTAMP + CMSG_SP_TCTOS)+1, sizeof(void*)) +#define SENDCMSGBUFLEN ALIGN(2*(CMSG_SP_IN6PKT + CMSG_SP_INT + CMSG_SP_TCTOS)+1, sizeof(void*)) /*% * The number of times a send operation is repeated if the result is EINTR.