Skip to content

Commit

Permalink
Consider nosound and novideo when keeping groups
Browse files Browse the repository at this point in the history
Even when `nogroups` is not used, avoid keeping the audio and video
groups when `nosound` and `novideo` are used, respectively.

Based on @rusty-snake's suggestion:
netblue30#4603 (comment)

Relates to netblue30#4603.
  • Loading branch information
kmk3 committed Oct 22, 2021
1 parent 615ce15 commit ea564eb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
20 changes: 12 additions & 8 deletions src/firejail/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3144,17 +3144,21 @@ int main(int argc, char **argv, char **envp) {
}

// add audio group
g = get_group_id("audio");
if (g) {
sprintf(ptr, "%d %d 1\n", g, g);
ptr += strlen(ptr);
if (!arg_nosound) {
g = get_group_id("audio");
if (g) {
sprintf(ptr, "%d %d 1\n", g, g);
ptr += strlen(ptr);
}
}

// add video group
g = get_group_id("video");
if (g) {
sprintf(ptr, "%d %d 1\n", g, g);
ptr += strlen(ptr);
if (!arg_novideo) {
g = get_group_id("video");
if (g) {
sprintf(ptr, "%d %d 1\n", g, g);
ptr += strlen(ptr);
}
}

// add games group
Expand Down
13 changes: 10 additions & 3 deletions src/firejail/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,11 @@ static void clean_supplementary_groups(gid_t gid) {
goto clean_all;

// clean supplementary group list
// allow only firejail, tty, audio, video, games
gid_t new_groups[MAX_GROUPS];
int new_ngroups = 0;
char *allowed[] = {
"firejail",
"tty",
"audio",
"video",
"games",
NULL
};
Expand All @@ -161,6 +158,16 @@ static void clean_supplementary_groups(gid_t gid) {
i++;
}

if (!arg_nosound) {
copy_group_ifcont("audio", groups, ngroups,
new_groups, &new_ngroups, MAX_GROUPS);
}

if (!arg_novideo) {
copy_group_ifcont("video", groups, ngroups,
new_groups, &new_ngroups, MAX_GROUPS);
}

if (new_ngroups) {
rv = setgroups(new_ngroups, new_groups);
if (rv)
Expand Down

0 comments on commit ea564eb

Please sign in to comment.