Skip to content

Commit 2e5b3dd

Browse files
committed
pam/go-exec/module: More consistent behavior for fatal signals
Sadly some signals such as SIGABRT or SIGSEGV are handled by go and in the wrong way because it never redirects them as expected, so in such cases we just fail with a normal exit error instead of because of a signal. Reported this upstream and adding comments about. See: golang/go#72084
1 parent b57d879 commit 2e5b3dd

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

pam/go-exec/module.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,17 @@ wait_child_thread (gpointer data)
436436

437437
if (ret == child_pid && WIFEXITED (status))
438438
{
439+
/* Sadly go childs that exits because of SIGABRT or SIGSEGV do not
440+
* have a WIFSIGNALED status, but instead exit with 2 exit status.
441+
* See: https://pkg.go.dev/runtime
442+
* So in such case we just return a generic system error, to be
443+
* consistent with signals (plus, we never return pam.ErrSymbol).
444+
* This is an upstream bug, but they refuse to fix or allow a
445+
* better handling: https://github.com/golang/go/issues/72084
446+
*/
447+
if (WEXITSTATUS (status) == 2)
448+
break;
449+
439450
exit_status = WEXITSTATUS (status);
440451
break;
441452
}

pam/integration-tests/exec_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ func TestExecModule(t *testing.T) {
226226
},
227227
"Error_when_client_fails_panicking": {
228228
methodCalls: []cliMethodCall{{m: "SimulateClientPanic", args: []any{"Client panicked! (As expected)"}}},
229-
wantError: pam.ErrSymbol,
229+
wantError: pam.ErrSystem,
230230
},
231231
"Error_when_client_fails_because_an_unhandled_error": {
232232
methodCalls: []cliMethodCall{{m: "SimulateClientError", args: []any{"Client error!"}}},
@@ -240,6 +240,14 @@ func TestExecModule(t *testing.T) {
240240
methodCalls: []cliMethodCall{{m: "SimulateClientSignal", args: []any{syscall.SIGKILL, true}}},
241241
wantError: pam.ErrSystem,
242242
},
243+
"Error_when_client_fails_because_a_client_SIGSEGV_signal": {
244+
methodCalls: []cliMethodCall{{m: "SimulateClientSignal", args: []any{syscall.SIGSEGV, true}}},
245+
wantError: pam.ErrSystem,
246+
},
247+
"Error_when_client_fails_because_a_client_SIGABRT_signal": {
248+
methodCalls: []cliMethodCall{{m: "SimulateClientSignal", args: []any{syscall.SIGABRT, true}}},
249+
wantError: pam.ErrSystem,
250+
},
243251
}
244252
for name, tc := range cliTests {
245253
t.Run("Client "+name, func(t *testing.T) {

0 commit comments

Comments
 (0)