Repository navigation
ignore EINTR signals in case user database is slow - #18684
Conversation
RStudio E2E - all platformsAll tests passed!
View / download the full reportView report online -- opens in the browser, no download needed. Available for 14 days. Download playwright-report.zip -- extract and open
All platforms - commit |
| } while (result == ERANGE); | ||
| } while (result == ERANGE || result == EINTR); | ||
|
|
||
| if (temp == nullptr) |
There was a problem hiding this comment.
temp is still uninitialized (line 71: struct group* temp;), even though this PR fixes the exact analogous problem in User.cpp by initializing tempPtrPwd = nullptr. This temp == nullptr test can therefore read indeterminate stack memory.
Scenario: a failing or slow SSSD/LDAP NSS backend makes ::getgrgid_r return a non-ERANGE, non-EINTR error (EIO, ENOMEM, ECONNREFUSED) on a path that does not write *result. The loop exits and temp holds stack garbage; if that garbage is non-null the else branch below reads grp.gr_gid, assigns grp.gr_name (an uninitialized char*) into a std::string, and walks grp.gr_mem — a garbage-pointer dereference, or at best a bogus Group returned as Success() and then cached in s_groupNameCache/s_groupIdCache for the next 5 minutes.
This is the same slow-directory scenario the PR targets, so the group path deserves the same one-word fix as the passwd path. The change belongs on line 71, which is outside this diff hunk:
struct group grp;
struct group* temp = nullptr; // <-- here| { | ||
| struct passwd pwd; | ||
| struct passwd* tempPtrPwd; | ||
| struct passwd* tempPtrPwd = nullptr; |
There was a problem hiding this comment.
This initializer only protects the first iteration. tempPtrPwd is declared outside the do loop, so on every retry it still holds the previous call's value — while the buffer it may point into is re-created (and the old one destroyed) each iteration.
The new EINTR branch makes retries much more common. If iteration N leaves tempPtrPwd non-null and iteration N+1 fails without writing *result (the very premise that motivated adding this initializer), the check below takes the success branch and reads pwd.pw_name / pwd.pw_dir / pwd.pw_shell — all pointers into the std::vector<char> buffer from the previous iteration, which has already been freed. That is a use-after-free yielding a garbage username/home directory instead of a clean error.
Moving the declaration inside the loop, next to buffer whose lifetime it shares, removes the whole class of bug and keeps the pointer and its backing storage in lockstep. It needs two edits, so it is not expressible as a single suggestion — drop the declaration here, and re-declare it inside the loop:
bool retry;
do
{
retry = false;
std::vector<char> buffer(buffSize);
struct passwd* tempPtrPwd = nullptr; // <-- scoped with the buffer it points into
int result = in_getPasswdFunc(in_value, &pwd, &(buffer[0]), buffSize, &tempPtrPwd);| buffSize *= 2; | ||
|
|
||
| } while (result == ERANGE); | ||
| } while (result == ERANGE || result == EINTR); |
There was a problem hiding this comment.
The EINTR retry is uncapped and makes no forward progress — unlike ERANGE it neither grows the buffer nor delays — so it turns what used to be a returned error into a tight, potentially unbounded busy loop. Same concern for retry = true at User.cpp:90, where the ERANGE sibling is capped by kGetPWMaxBufSize but EINTR is not.
Scenario: rserver/rsession fork child processes, so SIGCHLD (and other unblocked signals) arrive regularly. Against an unresponsive remote directory whose NSS socket read is interrupted on essentially every attempt, groupFrom never returns: the calling request/auth thread hangs, with no log line and no error — harder to diagnose than the intermittent failure this PR is fixing.
Suggest bounding the retries (a small counter, then return systemError(EINTR, ...)) and logging when a retry happens, so a genuinely wedged directory is still visible in the logs.
| @@ -87,7 +87,7 @@ Error groupFrom(const boost::function<int( | |||
| if (result == ERANGE) | |||
| buffSize *= 2; | |||
There was a problem hiding this comment.
Pre-existing, but it is on the loop this PR modifies and the passwd path already guards against it. buffSize is an int holding a long from sysconf, and this doubling has no cap — User.cpp:76 caps the equivalent growth with kGetPWMaxBufSize.
Scenario: a very large LDAP group (hundreds of thousands of members) returns ERANGE repeatedly. buffSize doubles 4096 → … → 1073741824 (a 1 GB allocation), then overflows signed int to -2147483648; buffer.resize(buffSize) converts that to a huge size_t and throws std::length_error/std::bad_alloc out of groupFrom. Callers like updateGroupCacheByName expect failure via an Error return, so the exception escapes into the auth path instead.
Mirroring the kGetPWMaxBufSize cap here would keep failure reporting consistent between the two lookups.
There was a problem hiding this comment.
Some claude findings, but none it considers blocking (I didn't review the review). Only question is if this needs a NEWS.md entry plus determining if the PR CI failures are related to the change or flakiness. I confirmed it is a flakey test, unrelated to this PR. I'm re-running that task.
Audited every commit merged to main since the 2026.08.0 branch point (8987547) against NEWS.md, excluding work that arrived from rel-yellow-yarrow. Two changes to released behavior merged without an entry: - #18441 (PR #18442): the sign-in page and logged-out dialog polled continuously, including while their tab was hidden. The PR body noted the NEWS entry was still to come. - #18683 (PR #18684): user and group lookups did not retry on EINTR, so a slow remote user directory produced intermittent failures. #18515 and #18512 were removed in 5aa0626 because they shipped in the 2026.08.1 patch notes, then resurrected by merge b92f45d, whose topic branch forked before that removal. Both are still present in version/news/os/NEWS-2026.08.1-yellow-yarrow.md, so they are dropped here again. Addresses #18441. Addresses #18683.
Intent
Fixes: #18683