Skip to content

ignore EINTR signals in case user database is slow - #18684

Merged
jeffvroom merged 1 commit into
mainfrom
bugfix-eintr-get-user
Aug 31, 2026
Merged

jeffvroom merged 1 commit into
mainfrom
bugfix-eintr-get-user

Conversation

@jeffvroom

Copy link
Copy Markdown
Contributor

Intent

Fixes: #18683

@github-actions

github-actions Bot commented Aug 29, 2026 •

Copy link
Copy Markdown

RStudio E2E - all platforms

All tests passed!

#################### 100% pass rate

Passed Failed Skipped Flaky
2532 0 184 3
Platform ✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
✅ auth-teardown 2 0 10 0
✅ desktop-linux 634 0 38 1
✅ desktop-macos 640 0 33 1
✅ desktop-windows 640 0 39 0
✅ server-linux 588 0 44 1
✅ setup 28 0 20 0
View / download the full report

View report online -- opens in the browser, no download needed. Available for 14 days.

Download playwright-report.zip -- extract and open index.html

Includes screenshots, traces, and step-by-step details for every test. Expires in 15 days.


All platforms - commit b4357a504a49b3cc0b7df673a78462355aa37d1d - Run #749

@gtritchie gtritchie added this to the 2026.09 (Autumn Hawkbit) milestone Aug 29, 2026
} while (result == ERANGE);
} while (result == ERANGE || result == EINTR);

if (temp == nullptr)

@gtritchie gtritchie Aug 29, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

@gtritchie gtritchie Aug 29, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@gtritchie gtritchie left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jeffvroom
jeffvroom merged commit 21981fc into main Aug 31, 2026
51 of 52 checks passed
@jeffvroom
jeffvroom deleted the bugfix-eintr-get-user branch August 31, 2026 19:41
@gtritchie gtritchie mentioned this pull request Aug 31, 2026
3 of 4 tasks
gtritchie added a commit that referenced this pull request Aug 31, 2026
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.

This branch was previously deployed

1 inactive deployment
e2e-playwright — b4357a50 Deployed Aug 29, 2026 by jeffvroom via macos / e2e-desktop-macos (1) #749
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ignore EINTR error returns in user lookups

2 participants