Skip to content

Commit 29750b8

Browse files
committed
Fix post integration invalid memory accesses
The crash comes from passing a minimal stub struct to interpretation routines that now expect the full parser state. To fix this, the stub now allocates a real parser with auparse_init(""), and each caller loads interpretations via that parser. This prevents invalid memory access when caches are cleaned up.
1 parent 2ca1ec0 commit 29750b8

File tree

7 files changed

+35
-56
lines changed

7 files changed

+35
-56
lines changed

src/auditctl-listing.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -469,9 +469,8 @@ static void print_rule(const struct audit_rule_data *r)
469469
type = auparse_interp_adjust_type(
470470
AUDIT_SYSCALL, name, val);
471471
out = auparse_do_interpretation(
472-
(auparse_state_t *)&interp_au,
473-
type, &id,
474-
AUPARSE_ESC_TTY);
472+
interp_au, type, &id,
473+
AUPARSE_ESC_TTY);
475474
printf(" -F %s%s%s", name,
476475
audit_operator_to_symbol(op),
477476
out);
@@ -569,8 +568,9 @@ int audit_print_reply(const struct audit_reply *rep, int fd)
569568
{
570569
static int init_done = 0;
571570
if (!init_done) {
572-
memset(&interp_au, 0, sizeof(interp_au));
573-
interp_au.interpretations.cnt = NEVER_LOADED;
571+
interp_au = auparse_init(AUSOURCE_BUFFER, "");
572+
if (interp_au == NULL)
573+
return 0;
574574
init_done = 1;
575575
}
576576
_audit_elf = 0;

src/auparse-stub.h

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,12 @@
11
#ifndef AUPARSE_STUB_H
22
#define AUPARSE_STUB_H
33

4+
#include "auparse.h"
45
#include "auparse-idata.h"
56

67
/*
7-
* Stub definitions for using interpretation helpers without auparse
8-
* initialization. Each translation unit that needs them gets its own
9-
* static copy.
8+
* Provide a shared parser instance for interpretation helpers.
109
*/
11-
12-
typedef struct interp_nvnode {
13-
char *name;
14-
char *val;
15-
char *interp_val;
16-
unsigned int item;
17-
} interp_nvnode;
18-
19-
typedef struct interp_nvlist {
20-
interp_nvnode *array;
21-
unsigned int cur;
22-
unsigned int cnt;
23-
unsigned int size;
24-
char *record;
25-
char *end;
26-
} interp_nvlist;
27-
28-
typedef struct {
29-
interp_nvlist interpretations;
30-
} interp_state_t;
31-
32-
static interp_state_t interp_au;
10+
static auparse_state_t *interp_au = NULL;
3311

3412
#endif /* AUPARSE_STUB_H */

src/aureport.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,11 @@ int main(int argc, char *argv[])
100100
set_aumessage_mode(MSG_STDERR, DBG_NO);
101101
(void) umask( umask( 077 ) | 027 );
102102
very_first_event.sec = 0;
103-
memset(&interp_au, 0, sizeof(interp_au));
104-
interp_au.interpretations.cnt = NEVER_LOADED;
103+
interp_au = auparse_init(AUSOURCE_BUFFER, "");
104+
if (interp_au == NULL) {
105+
fprintf(stderr, "cannot init parser\n");
106+
return 1;
107+
}
105108
reset_counters();
106109

107110
/* Load config so we know where logs are and eoe_timeout */
@@ -242,14 +245,13 @@ static void process_event(llist *entries)
242245
// If its a single event or SYSCALL load interpretations
243246
if ((entries->cnt == 1) ||
244247
(entries->head->type == AUDIT_SYSCALL)) {
245-
_auparse_load_interpretations(
246-
(auparse_state_t *)&interp_au,
248+
_auparse_load_interpretations(interp_au,
247249
entries->head->interp);
248250
}
249251
// This is the per entry action item
250252
if (per_event_processing(entries))
251253
found = 1;
252-
_auparse_free_interpretations((auparse_state_t *)&interp_au);
254+
_auparse_free_interpretations(interp_au);
253255
}
254256
}
255257

src/ausearch-lookup.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ const char *aulookup_syscall(llist *l, char *buf, size_t size)
7676
const char *sys;
7777

7878
if (!interp_init) {
79-
memset(&interp_au, 0, sizeof(interp_au));
80-
interp_au.interpretations.cnt = NEVER_LOADED;
79+
interp_au = auparse_init(AUSOURCE_BUFFER, "");
80+
if (interp_au == NULL)
81+
return NULL;
8182
interp_init = 1;
8283
}
8384

@@ -86,8 +87,8 @@ const char *aulookup_syscall(llist *l, char *buf, size_t size)
8687
return buf;
8788
}
8889

89-
sys = _auparse_lookup_interpretation((auparse_state_t *)&interp_au,
90-
"syscall");
90+
sys = _auparse_lookup_interpretation(interp_au,
91+
"syscall");
9192
if (sys) {
9293
snprintf(buf, size, "%s", sys);
9394
free((void *)sys);
@@ -207,8 +208,9 @@ const char *aulookup_uid(uid_t uid, char *buf, size_t size)
207208
int rc;
208209

209210
if (!interp_init) {
210-
memset(&interp_au, 0, sizeof(interp_au));
211-
interp_au.interpretations.cnt = NEVER_LOADED;
211+
interp_au = auparse_init(AUSOURCE_BUFFER, "");
212+
if (interp_au == NULL)
213+
return NULL;
212214
interp_init = 1;
213215
}
214216

@@ -221,8 +223,7 @@ const char *aulookup_uid(uid_t uid, char *buf, size_t size)
221223
return buf;
222224
}
223225

224-
name = _auparse_lookup_interpretation((auparse_state_t *)&interp_au,
225-
"auid");
226+
name = _auparse_lookup_interpretation(interp_au, "auid");
226227
if (name) {
227228
snprintf(buf, size, "%s", name);
228229
free((void *)name);

src/ausearch-parse.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,13 @@ static const char *lookup_uid(const char *field, uid_t uid)
217217
const char *value;
218218

219219
if (!interp_init) {
220-
memset(&interp_au, 0, sizeof(interp_au));
221-
interp_au.interpretations.cnt = NEVER_LOADED;
220+
interp_au = auparse_init(AUSOURCE_BUFFER, "");
221+
if (interp_au == NULL)
222+
return NULL;
222223
interp_init = 1;
223224
}
224225

225-
value = _auparse_lookup_interpretation((auparse_state_t *)&interp_au,
226-
field);
226+
value = _auparse_lookup_interpretation(interp_au, field);
227227
if (value)
228228
return value;
229229
if (uid == 0)

src/ausearch-report.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,20 @@ void ausearch_load_interpretations(const lnode *n)
6969
{
7070
if (loaded == 0) {
7171
if (!interp_init) {
72-
memset(&interp_au, 0, sizeof(interp_au));
73-
interp_au.interpretations.cnt = NEVER_LOADED;
72+
interp_au = auparse_init(AUSOURCE_BUFFER, "");
73+
if (interp_au == NULL)
74+
return;
7475
interp_init = 1;
7576
}
76-
_auparse_load_interpretations((auparse_state_t *)&interp_au,
77-
n->interp);
77+
_auparse_load_interpretations(interp_au, n->interp);
7878
loaded = 1;
7979
}
8080
}
8181

8282
void ausearch_free_interpretations(void)
8383
{
84-
if (loaded) {
85-
_auparse_free_interpretations((auparse_state_t *)&interp_au);
84+
if (loaded && interp_au) {
85+
_auparse_free_interpretations(interp_au);
8686
loaded = 0;
8787
}
8888
}
@@ -394,8 +394,7 @@ static void report_interpret(char *name, char *val, int comma, int rtype)
394394
id.val = val;
395395
id.cwd = NULL;
396396

397-
char *out = auparse_do_interpretation((auparse_state_t *)&interp_au,
398-
type, &id, escape_mode);
397+
char *out = auparse_do_interpretation(interp_au,type,&id,escape_mode);
399398
if (type == AUPARSE_TYPE_UNCLASSIFIED)
400399
printf("%s%c", val, comma ? ',' : ' ');
401400
else if (name[0] == 'k' && strcmp(name, "key") == 0) {

src/ausearch.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ int main(int argc, char *argv[])
220220
free((char *)event_tuid);
221221
free((char *)event_teuid);
222222
free((char *)event_tauid);
223-
auparse_destroy(NULL);
224223
output_auparse_finish();
225224
if (rc)
226225
return rc;

0 commit comments

Comments
 (0)