Repository navigation
client: keep dentry alive while unlinking trimmed cache entries - #69021
Conversation
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
gregsfortytwo
left a comment
There was a problem hiding this comment.
I'll try to look at this some more to understand better, but I don't think this patch covers the full crash scope?
|
So with this patch as it stands, the next thing that will happen is that we run the dentry-handling code: This code assumes the dentry is still linked in to a directory and that I don't think I understand why we're seeing this crash now and not before. If the given explanation is accurate, isn't this whole workflow completely broken? That doesn't seem likely given the age and stability of this part of the code? We're talking about a "clone", but that's the dentry name itself and it doesn't immediately look like a snapshot dentry to me? |
That is my concern too. Did we just got lucky all these days that the client was able to survive using a deallocated object? I am going to run a wild grep in our teuthology fs suite history looking for the dentry ref counts during shutdown. Let me see what I get... |
From my past experience, with jemalloc/tcmalloc, freed memory often retains its old values (not zeroed). So I can suggest adding |
|
Another point is that The |
I scrapped through our teuthology tests that exercises this code path and here is what is happening. E.g.: /a/choffman-2026-04-22_16:26:51-fs:fscrypt-main-distro-default-trial/169501/remote/trial108/log/ceph-mgr.x.log.gz From above, when the last child under "clone" gets trimmed, the dout() for put_inode() has dentry list for clone with ref=1, followed by, trimming dentry(clone) itself: Pretty similar pattern, but no crash in this case. |
|
I suggest to go with the function scope fix, it will not make it worse, but the assert I suggested may give us good hint next time this crash will hit |
Do you have a change that I can put to test (without this change), so that when it hits a coredump is there for us to debug? |
|
I think diagnostics is the best we can do right now, so this seems like a good approach. |
Not sure about tcmalloc but IIRC then jemalloc provides a debugging tool call opt.junk (junk filling) that initialises freed/unused memory with a specific byte stream and on hitting a UAF it should segfault. Might help with debugging? |
Yeah, but Client::close_dir() is explicitly zeroing out the dn->dir pointer, so we won't be able to follow that and should bring segfaulting when we hit that dereference, if the crash is a result of running this unlink code after close_dir() runs. |
Yeh, I have been banging my head on this without being able to explain why there would be a premature deallocation of the dentry. The only explanation I have now is the absence of PR #60909 could be causing this issue. It seems related to some extent but I cannot yet say with 100% surety that it's caused by the missing PR in the branch where the crash was seen. @gregsfortytwo |
|
We confirmed that PR #60909 (pin inode/dentry for O_DIRECTORY) is not in the 19.2.1 build where the crash was observed. That PR was merged 11 days after the v19.2.1 tag. Without it, opening a directory does not call PR #60909 fixes the root cause — the pin was never taken. Our I suggest we land both: PR #60909 as the backport fix, and this DentryRef guard as defense-in-depth so that missing pins produce an |
|
jenkins retest this please |
|
This PR has been added to main integration testing by vshankar started 2026-06-01-06:34. |
|
jenkins retest this please |
gregsfortytwo
left a comment
There was a problem hiding this comment.
@salieri11's explanation seems good to me. But the code is still referring to close_dir() as a path to trouble. Let's update the code comment with our new understanding and then merge? :)
|
jenkins retest this please |
|
jenkins test docs |
1 similar comment
|
jenkins test docs |
Add ceph_assert(dn->ref > 0) after Dentry::unlink() in Client::unlink() to catch the case where internal put() calls drop the dentry reference to zero before we proceed to detach/lru_remove. This turns a silent use-after-free into a clean assertion failure with a full stack trace, making it possible to catch the exact conditions in a test environment. Signed-off-by: Igor Golikov <[email protected]> Fixes: https://tracker.ceph.com/issues/74625
Hold a function-scoped DentryRef in Client::unlink() to keep the dentry alive through the entire teardown sequence. Without the O_DIRECTORY dentry pin (PR ceph#60909, merged after v19.2.1), opening a directory does not call _ll_get(), so the dentry stays at ref=1 while inode->dir is still active. When trim_cache() evicts this dentry, Dentry::unlink() calls put() for the dir pin, ref drops to 0, and the dentry is freed while Client::unlink() still needs it for detach/lru_remove. A function-scoped DentryRef guarantees the dentry survives until after it has been properly removed from the dir and LRU, regardless of pin state. Signed-off-by: Igor Golikov <[email protected]> Fixes: https://tracker.ceph.com/issues/74625
|
Force pushed to get jenkins test passing (hopefully). |
Summary
DentryRefinClient::unlink()while tearing down a dentryclose_dir()and drop the extra pin on the parent dentry just before that parent is trimmedceph_shutdown()crash reported in tracker#74625Root cause
Client::unlink()was operating on a rawDentry*across ref-dropping work.In the shutdown path, trimming the last child of a cached directory can call
close_dir(), which removes the extra directory pin from the parent dentry.If that parent dentry is selected for trimming next,
Client::unlink()maystill use the same raw pointer after
dn->unlink()while detaching it fromthe dir and removing it from the LRU.
Keeping a local
DentryReffor the whole unlink teardown makes the dentrylifetime explicit and keeps it alive until the final
dn->put().Fixes: https://tracker.ceph.com/issues/74625
Contribution Guidelines
To sign and title your commits, please refer to Submitting Patches to Ceph.
If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.
When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an
xbetween the brackets:[x]. Spaces and capitalization matter when checking off items this way.Checklist
Show available Jenkins commands
jenkins test classic perfJenkins Job | Jenkins Job Definitionjenkins test crimson perfJenkins Job | Jenkins Job Definitionjenkins test signedJenkins Job | Jenkins Job Definitionjenkins test make checkJenkins Job | Jenkins Job Definitionjenkins test make check arm64Jenkins Job | Jenkins Job Definitionjenkins test submodulesJenkins Job | Jenkins Job Definitionjenkins test dashboardJenkins Job | Jenkins Job Definitionjenkins test dashboard cephadmJenkins Job | Jenkins Job Definitionjenkins test apiJenkins Job | Jenkins Job Definitionjenkins test docsReadTheDocs | Github Workflow Definitionjenkins test ceph-volume allJenkins Jobs | Jenkins Jobs Definitionjenkins test windowsJenkins Job | Jenkins Job Definitionjenkins test rook e2eJenkins Job | Jenkins Job DefinitionYou must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.