Bug 914 - (Patch included) Segfault when pressing Ctrl+Z during PAM conversation input
(Patch included) Segfault when pressing Ctrl+Z during PAM conversation input
Status: RESOLVED FIXED
Product: Sudo
Classification: Unclassified
Component: Sudoers
1.8.30
PC Linux
: low normal
Assigned To: Todd C. Miller
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2020-01-24 09:29 MST by Michael Norton
Modified: 2020-06-19 06:13 MDT (History)
0 users

See Also:


Attachments
Patch to fix bug (456 bytes, text/plain)
2020-01-24 09:29 MST, Michael Norton
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Norton 2020-01-24 09:29:28 MST
Created attachment 539 [details]
Patch to fix bug

I thought this was a bug in the PAM I'm coding, but after debugging, I found that it's actually a bug in sudo itself.

To reproduce:

1) Configure sudo to use any PAM that requests user input via the conversation API.
2) Invoke sudo so it calls this PAM for authentication.
3) Press Ctrl+Z at the input prompt.

Expected results: sudo should suspend and resume cleanly.

Actual results: sudo crashes with a segmentation fault.

Cause of issue + fix:

The sudo_conv_callback structure's closure field should contain a pointer to a getpass_closure structure. The code populates this with "&closure", but this is incorrect as the "closure" argument referenced is already a pointer. As a result, when a pointer is later read from that structure, it's read from the wrong location, causing a segmentation fault.

I tried replacing "cb.closure = &closure;" with "cb.closure = closure;" in plugins/sudoers/check.c, and it resolved the issue I was experiencing. I have attached a patch for this change.
Comment 1 Todd C. Miller 2020-01-24 11:19:05 MST
Thanks, the closure used to be a struct, not a pointer.  It looks like this got broken in 9b2022e6f11d as part of the fix for bug #910.

I've committed this as https://www.sudo.ws/repos/sudo/rev/011b6a7663ef
Comment 2 Michael Norton 2020-01-24 22:50:42 MST
Oh wow you're right, it does it even on the regular password prompt. Didn't think to try that. :P

Glad I could help!
Comment 3 Todd C. Miller 2020-06-19 06:13:18 MDT
This was fixed in Sudo 1.8.31