[Bug 4062] New: ssh-agent: stale socket cleanup reads a freed path on platforms without fstatat(2)

bugzilla-daemon at mindrot.org bugzilla-daemon at mindrot.org
Sun Nov 22 12:59:30 AEDT 2026


https://bugzilla.mindrot.org/show_bug.cgi?id=4062

            Bug ID: 4062
           Summary: ssh-agent: stale socket cleanup reads a freed path on
                    platforms without fstatat(2)
           Product: Portable OpenSSH
           Version: 10.6p1
          Hardware: All
               URL: https://github.com/openssh/openssh-portable/pull/725
                OS: All
            Status: NEW
          Severity: normal
          Priority: P5
         Component: ssh-agent
          Assignee: unassigned-bugs at mindrot.org
          Reporter: anabobillo3 at gmail.com

Created attachment 4031
  --> https://bugzilla.mindrot.org/attachment.cgi?id=4031&action=edit
ssh-agent: set path before fstatat/unlinkat shims

On platforms without fstatat(2) or unlinkat(2), misc-agent.c replaces
them with macros that call lstat(path, ...) and unlink(path), so
agent_cleanup_stale() has to set "path" for each directory entry before
the first of them (as de25e7397 arranged).

The agent socket directory sync in 10.6 (cee6aedb1) moved the
construction of "path" after the fstatat() call and dropped its reset
after the hostname hash is freed. On those platforms the lstat() then
reads a freed pointer (the hostname hash or the previous entry's path),
or an uninitialised one with ssh-agent -uu, so the socket type and age
checks are made on the wrong file.

The attached patch builds "path" at the top of each iteration again and
frees it on exit. It is also GitHub PR #725
(https://github.com/openssh/openssh-portable/pull/725), open since
October 22, and applies cleanly to current master and to V_10_6.

Could it be applied as written (git am), so it keeps its authorship?

Thanks,
Ana Bobillo

-- 
You are receiving this mail because:
You are watching the assignee of the bug.


More information about the openssh-bugs mailing list