Skip to content

Commit c58b59e

Browse files
committed
Verify the rule is empty before adding a watch
Added a safety check in audit_setup_watch_name to verify that watch rules contain no fields or actions, ensuring the rule is empty before adding a watch and providing a clear error path when it isn’t.
1 parent 194b36c commit c58b59e

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/auditctl.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ static int audit_setup_watch_name(struct audit_rule_data **rulep, char *path)
278278
int type = AUDIT_WATCH;
279279
size_t len;
280280
struct stat buf;
281+
unsigned int i;
281282

282283
if (check_path(path))
283284
return -1;
@@ -294,13 +295,28 @@ static int audit_setup_watch_name(struct audit_rule_data **rulep, char *path)
294295
if (S_ISDIR(buf.st_mode))
295296
type = AUDIT_DIR;
296297
}
297-
/* FIXME: might want to check to see that rule is empty */
298-
if (audit_add_watch_dir(type, rulep, path))
298+
/* Ensure the rule is empty before adding a watch */
299+
if ((*rulep)->field_count || (*rulep)->action || (*rulep)->flags ||
300+
(*rulep)->buflen)
301+
goto err;
302+
for (i = 0; i < AUDIT_MAX_FIELDS; i++)
303+
if ((*rulep)->fields[i] || (*rulep)->values[i] ||
304+
(*rulep)->fieldflags[i])
305+
goto err;
306+
for (i = 0; i < AUDIT_BITMASK_SIZE; i++)
307+
if ((*rulep)->mask[i])
308+
goto err;
309+
if (audit_add_watch_dir(type, rulep, path))
299310
return -1;
300311

301312
if (add != AUDIT_FILTER_UNSET)
302313
audit_msg(LOG_INFO, "Old style watch rules are slower");
303314
return 1;
315+
err:
316+
audit_msg(LOG_ERR, "Watches may not include fields or actions");
317+
audit_rule_free_data(*rulep);
318+
*rulep = audit_rule_create_data();
319+
return -1;
304320
}
305321

306322
/*

0 commit comments

Comments
 (0)