Skip to content

Commit

Permalink
landlock: fix profile entries processed in reverse
Browse files Browse the repository at this point in the history
When a new landlock entry is parsed from a profile, the first entry in
the `cfg.lprofile` list is being set as the next/second entry and the
new entry is being set as the first entry in the list, so all entries
are being processed from last to first.

This commit makes the behavior of ll_add_profile() match the one from
profile_add() in src/firejail/profile.c so that the entries are
processed in the same order that they are parsed.

This amends commit b94cc75 ("landlock: apply rules in sandbox before
app start", 2023-10-26) / PR #6078.
  • Loading branch information
kmk3 committed Dec 5, 2023
1 parent 24b88ce commit aa87789
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/firejail/landlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,16 +345,24 @@ void ll_add_profile(int type, const char *data) {
while (*data == ' ' || *data == '\t')
data++;

LandlockEntry *ptr = malloc(sizeof(LandlockEntry));
if (!ptr)
LandlockEntry *entry = malloc(sizeof(LandlockEntry));
if (!entry)
errExit("malloc");
memset(ptr, 0, sizeof(LandlockEntry));
ptr->type = type;
ptr->data = strdup(data);
if (!ptr->data)
memset(entry, 0, sizeof(LandlockEntry));
entry->type = type;
entry->data = strdup(data);
if (!entry->data)
errExit("strdup");
ptr->next = cfg.lprofile;
cfg.lprofile = ptr;

// add entry to the list
if (cfg.lprofile == NULL) {
cfg.lprofile = entry;
return;
}
LandlockEntry *ptr = cfg.lprofile;
while (ptr->next != NULL)
ptr = ptr->next;
ptr->next = entry;
}

#endif /* HAVE_LANDLOCK */

0 comments on commit aa87789

Please sign in to comment.