[GH-ISSUE #1039] ASSERT_PERMS_FD should use fstat() rather than stat() #705

Closed
opened 2026-05-05 06:28:53 -06:00 by gitea-mirror · 1 comment
Owner

Originally created by @setharnold on GitHub (Jan 11, 2017).
Original GitHub issue: https://github.com/netblue30/firejail/issues/1039

Hello, please note that ASSERT_PERMS_FD() (and thus also ASSERT_PERMS_STREAM()) have a mistake that would lead to a segmentation violation, if they were actually used in the code:

#define ASSERT_PERMS_FD(fd, uid, gid, mode)
do {
struct stat s;
if (stat(fd, &s) == -1) errExit("stat");\ ### should use fstat() instead of stat()
assert(s.st_uid == uid);
assert(s.st_gid == gid);
assert((s.st_mode & 07777) == (mode));
} while (0)

https://github.com/netblue30/firejail/blob/master/src/firejail/firejail.h#L108

Thanks

Originally created by @setharnold on GitHub (Jan 11, 2017). Original GitHub issue: https://github.com/netblue30/firejail/issues/1039 Hello, please note that ASSERT_PERMS_FD() (and thus also ASSERT_PERMS_STREAM()) have a mistake that would lead to a segmentation violation, if they were actually used in the code: #define ASSERT_PERMS_FD(fd, uid, gid, mode) \ do { \ struct stat s;\ if (stat(fd, &s) == -1) errExit("stat");\ ### should use fstat() instead of stat() assert(s.st_uid == uid);\ assert(s.st_gid == gid);\ assert((s.st_mode & 07777) == (mode));\ } while (0) https://github.com/netblue30/firejail/blob/master/src/firejail/firejail.h#L108 Thanks
gitea-mirror 2026-05-05 06:28:53 -06:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@netblue30 commented on GitHub (Jan 14, 2017):

I've pushd the fix on all 3 branches, thanks.

<!-- gh-comment-id:272628033 --> @netblue30 commented on GitHub (Jan 14, 2017): I've pushd the fix on all 3 branches, thanks.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/firejail#705
No description provided.