[Rpm-maint] [rpm-software-management/rpm] fix: chdir after chroot so cwd is valid inside --root transactions (PR #4305)

luxinyou notifications at github.com
Tue Aug 11 13:17:47 UTC 2026


## Problem

rpmChrootIn() ran chdir("/") BEFORE chroot(), so the cwd stayed on the old root's inode — unreachable from inside the new root. Every relative path resolution in rpm's own code then fails (realpath/getcwd in fprint.c canonDir), crashing with SIGSEGV 0xF069 during --root (installer) transactions once file fingerprinting kicks in.

## Fix (lib/rpmchroot.c, 4 changes)

1. rootState_s: add root_fd (pre-chroot root dir fd, opened in rpmChrootSet)
2. rpmChrootSet: save root_fd, close on reset
3. rpmChrootIn: chdir("/") AFTER chroot() so cwd is valid in the new root
4. rpmChrootOut: fchdir(root_fd) + chroot(".") + fchdir(saved cwd) to restore the original root (chroot(".") alone would re-chroot to the target root since cwd is no longer the old-root inode)

## Verification

Standalone chroot in/out harness on UOS Server 25 (root):
- old logic: getcwd/realpath fail inside chroot (crash precursor)
- new logic: getcwd/realpath OK inside chroot, full restore on exit

Matches the LD_PRELOAD shim workaround previously proven across 1252-package installer transactions.
You can view, comment on, or merge this pull request online at:

  https://github.com/rpm-software-management/rpm/pull/4305

-- Commit Summary --

  * fix: chdir after chroot so cwd is valid inside --root transactions

-- File Changes --

    M lib/rpmchroot.c (28)

-- Patch Links --

https://github.com/rpm-software-management/rpm/pull/4305.patch
https://github.com/rpm-software-management/rpm/pull/4305.diff

-- 
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/pull/4305
You are receiving this because you are subscribed to this thread.

Message ID: <rpm-software-management/rpm/pull/4305 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rpm.org/pipermail/rpm-maint/attachments/20260811/bc9fc52c/attachment.htm>


More information about the Rpm-maint mailing list