Skip to content

Commit

Permalink
Set file metadata via fd-based ops for everything but symlinks
Browse files Browse the repository at this point in the history
Regular file ops are fd-based already, for the rest we need to open them
manually. Files with temporary suffix must never be followed, for
directories (and pre-existing FA_TOUCHed files) use the rpm symlink
"root or target owner allowed" rule wrt following.

This mostly fixes CVE-2021-35938, but as we're not yet using dirfd-based
operatiosn for everything there are corner cases left undone. And then
there's the plugin API which needs updating for all this.
  • Loading branch information
pmatilai committed Feb 16, 2022
1 parent 9f5b228 commit 25a435e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,14 @@ int rpmPackageFilesInstall(rpmts ts, rpmte te, rpmfiles files,
rc = RPMERR_UNKNOWN_FILETYPE;
}

if (!rc && fd == -1 && !S_ISLNK(fp->sb.st_mode)) {
/* Only follow safe symlinks, and never on temporary files */
fd = fsmOpenat(di.dirfd, fp->fpath,
fp->suffix ? AT_SYMLINK_NOFOLLOW : 0);
if (fd < 0)
rc = RPMERR_OPEN_FAILED;
}

setmeta:
if (!rc && fp->setmeta) {
rc = fsmSetmeta(fd, di.dirfd, fp->fpath,
Expand Down

0 comments on commit 25a435e

Please # to comment.