audit: fix static linking

+156 -1
+9 -1
pkgs/os-specific/linux/audit/default.nix
··· 36 36 # TODO: Remove the musl patches when 37 37 # https://github.com/linux-audit/audit-userspace/pull/25 38 38 # is available with the next release. 39 - patches = stdenv.lib.optional stdenv.hostPlatform.isMusl [ 39 + patches = [ ./patches/weak-symbols.patch ] ++ 40 + stdenv.lib.optional stdenv.hostPlatform.isMusl [ 40 41 ( 41 42 let patch = fetchpatch { 42 43 url = "https://github.com/linux-audit/audit-userspace/commit/d579a08bb1cde71f939c13ac6b2261052ae9f77e.patch"; ··· 55 56 56 57 prePatch = '' 57 58 sed -i 's,#include <sys/poll.h>,#include <poll.h>\n#include <limits.h>,' audisp/audispd.c 59 + '' 60 + # According to https://stackoverflow.com/questions/13089166 61 + # --whole-archive linker flag is required to be sure that linker 62 + # correctly chooses strong version of symbol regardless of order of 63 + # object files at command line. 64 + + stdenv.lib.optionalString stdenv.targetPlatform.isStatic '' 65 + export LDFLAGS=-Wl,--whole-archive 58 66 ''; 59 67 meta = { 60 68 description = "Audit Library";
+147
pkgs/os-specific/linux/audit/patches/weak-symbols.patch
··· 1 + Executables in src/ directory are built from source files in src/ 2 + and are linked to libauparse, with both src/auditd-config.c and 3 + auparse/auditd-config.c defining "free_config" function. 4 + 5 + It is known (although obscure) behaviour of shared libraries that 6 + symbol defined in binary itself overrides symbol in shared library; 7 + with static linkage it expectedly results in multiple definition 8 + error. 9 + 10 + This set of fixes explicitly marks libauparse versions of 11 + conflicting functions as weak to have behaviour coherent with 12 + dynamic linkage version -- definitions in src/ overriding definition 13 + in auparse/. 14 + 15 + Still, this architecture is very strange and confusing. 16 + 17 + diff -r -U5 audit-2.8.5-orig/auparse/auditd-config.c audit-2.8.5/auparse/auditd-config.c 18 + --- audit-2.8.5-orig/auparse/auditd-config.c 2019-03-01 20:19:13.000000000 +0000 19 + +++ audit-2.8.5/auparse/auditd-config.c 2021-01-13 11:36:12.716226498 +0000 20 + @@ -68,10 +68,11 @@ 21 + }; 22 + 23 + /* 24 + * Set everything to its default value 25 + */ 26 + +#pragma weak clear_config 27 + void clear_config(struct daemon_conf *config) 28 + { 29 + config->local_events = 1; 30 + config->qos = QOS_NON_BLOCKING; 31 + config->sender_uid = 0; 32 + @@ -322,10 +323,11 @@ 33 + if (config->log_file == NULL) 34 + return 1; 35 + return 0; 36 + } 37 + 38 + +#pragma weak free_config 39 + void free_config(struct daemon_conf *config) 40 + { 41 + free((void*)config->log_file); 42 + } 43 + 44 + diff -r -U5 audit-2.8.5-orig/auparse/interpret.c audit-2.8.5/auparse/interpret.c 45 + --- audit-2.8.5-orig/auparse/interpret.c 2019-03-01 20:19:13.000000000 +0000 46 + +++ audit-2.8.5/auparse/interpret.c 2021-01-13 11:39:42.107217224 +0000 47 + @@ -545,10 +545,11 @@ 48 + else 49 + snprintf(buf, size, "unknown(%d)", uid); 50 + return buf; 51 + } 52 + 53 + +#pragma weak aulookup_destroy_uid_list 54 + void aulookup_destroy_uid_list(void) 55 + { 56 + if (uid_cache_created == 0) 57 + return; 58 + 59 + @@ -2810,10 +2811,11 @@ 60 + 61 + /* 62 + * This is the main entry point for the auparse library. Call chain is: 63 + * auparse_interpret_field -> nvlist_interp_cur_val -> interpret 64 + */ 65 + +#pragma weak interpret 66 + const char *interpret(const rnode *r, auparse_esc_t escape_mode) 67 + { 68 + const nvlist *nv = &r->nv; 69 + int type; 70 + idata id; 71 + diff -r -U5 audit-2.8.5-orig/auparse/nvlist.c audit-2.8.5/auparse/nvlist.c 72 + --- audit-2.8.5-orig/auparse/nvlist.c 2019-02-04 14:26:52.000000000 +0000 73 + +++ audit-2.8.5/auparse/nvlist.c 2021-01-13 11:37:37.190222757 +0000 74 + @@ -27,10 +27,11 @@ 75 + #include "nvlist.h" 76 + #include "interpret.h" 77 + #include "auparse-idata.h" 78 + 79 + 80 + +#pragma weak nvlist_create 81 + void nvlist_create(nvlist *l) 82 + { 83 + l->head = NULL; 84 + l->cur = NULL; 85 + l->cnt = 0; 86 + @@ -47,17 +48,19 @@ 87 + while (node->next) 88 + node = node->next; 89 + l->cur = node; 90 + } 91 + 92 + +#pragma weak nvlist_next 93 + nvnode *nvlist_next(nvlist *l) 94 + { 95 + if (l->cur) 96 + l->cur = l->cur->next; 97 + return l->cur; 98 + } 99 + 100 + +#pragma weak nvlist_append 101 + void nvlist_append(nvlist *l, nvnode *node) 102 + { 103 + nvnode* newnode = malloc(sizeof(nvnode)); 104 + 105 + newnode->name = node->name; 106 + @@ -141,10 +144,11 @@ 107 + if (l->cur->interp_val) 108 + return l->cur->interp_val; 109 + return interpret(r, escape_mode); 110 + } 111 + 112 + +#pragma weak nvlist_clear 113 + void nvlist_clear(nvlist* l) 114 + { 115 + nvnode* nextnode; 116 + register nvnode* current; 117 + 118 + diff -r -U5 audit-2.8.5-orig/auparse/strsplit.c audit-2.8.5/auparse/strsplit.c 119 + --- audit-2.8.5-orig/auparse/strsplit.c 2019-03-01 21:15:30.000000000 +0000 120 + +++ audit-2.8.5/auparse/strsplit.c 2021-01-13 11:38:04.306221556 +0000 121 + @@ -54,10 +54,11 @@ 122 + return NULL; 123 + return s; 124 + } 125 + } 126 + 127 + +#pragma weak audit_strsplit 128 + char *audit_strsplit(char *s) 129 + { 130 + static char *str = NULL; 131 + char *ptr; 132 + 133 + diff -r -U5 audit-2.8.5-orig/lib/strsplit.c audit-2.8.5/lib/strsplit.c 134 + --- audit-2.8.5-orig/lib/strsplit.c 2019-03-01 20:19:13.000000000 +0000 135 + +++ audit-2.8.5/lib/strsplit.c 2021-01-13 11:38:29.444220443 +0000 136 + @@ -23,10 +23,11 @@ 137 + 138 + #include <string.h> 139 + #include "libaudit.h" 140 + #include "private.h" 141 + 142 + +#pragma weak audit_strsplit_r 143 + char *audit_strsplit_r(char *s, char **savedpp) 144 + { 145 + char *ptr; 146 + 147 + if (s)