Skip to content

fchmodat

Intro

fchmodat - change permissions of a file relative to a directory file descriptor.

Description

The fchmodat() system call allows changing the permissions of a specified file or directory, similar to chmod().

However, fchmodat() offers additional flexibility by operating relative to a directory identified by a file descriptor. This feature proves useful, especially when working with directory contexts where the absolute path to a target file or directory isn't directly known or accessible.

Arguments

  • dirfd: int[K] - File descriptor pointing to the directory relative to which the pathname is interpreted.
  • pathname: const char *[U] - The path of the file or directory whose permissions are to be changed.
  • mode: mode_t[K] - A bitmask specifying the new permissions to be set for the file or directory.
  • flags: int[K] - Flags that modify function behavior (e.g., AT_SYMLINK_NOFOLLOW ensures symbolic links aren't followed).

Permission Bits

  • S_ISUID (04000): Set-user-ID
  • S_ISGID (02000): Set-group-ID
  • S_ISVTX (01000): Sticky bit
  • S_IRUSR (00400): Read by owner
  • S_IWUSR (00200): Write by owner
  • S_IXUSR (00100): Execute/search by owner
  • S_IRGRP (00040): Read by group
  • S_IWGRP (00020): Write by group
  • S_IXGRP (00010): Execute/search by group
  • S_IROTH (00004): Read by others
  • S_IWOTH (00002): Write by others
  • S_IXOTH (00001): Execute/search by others

Available Tags

  • K - Originated from kernel-space.
  • U - Originated from user space.
  • TOCTOU - Vulnerable to TOCTOU (time of check, time of use).
  • OPT - Optional argument - might not always be available (passed with null value).

Hooks

sys_fchmodat

Type

Tracepoint (through sys_enter).

Purpose

To observe and capture instances of the fchmodat() system call invocation, detailing the file or directory targeted, and the new permissions being set.

Example Use Case

In security-centric environments, tracking permissions alterations of files and directories is pivotal to ensure consistent access controls and prevent unauthorized access.

Issues

Misuse of the fchmodat() system call can unintentionally expose sensitive files or directories, making them susceptible to unauthorized access or tampering.

  • chmod() - Change permissions of a file.
  • fchmod() - Change permissions of a file through its file descriptor.

This document was automatically generated by OpenAI and reviewed by a Human.