🇰🇷 한글 설명
Linux 커널의 FunctionFS(f_fs) 구현에서 USB ep0 short read 발생 시 실제 수신된 바이트보다 더 많은 데이터를 사용자 공간으로 복사하는 취약점입니다. 이로 인해 kmalloc으로 할당된 버퍼 내의 초기화되지 않은 슬랩 잔여물(slab residue)이 FunctionFS 데몬으로 유출될 수 있습니다.
💡 쉬운 설명
USB 연결 과정에서 데이터가 예상보다 적게 들어왔을 때, 컴퓨터 메모리에 남아있던 이전 데이터의 흔적을 실수로 읽어가는 문제입니다. 이로 인해 권한이 높은 프로그램이 메모리에 숨겨진 민감한 정보를 알게 될 위험이 있습니다.
🇺🇸 원문 (English)
In the Linux kernel, the following vulnerability has been resolved:
usb: gadget: f_fs: copy only received bytes on short ep0 read
ffs_ep0_read() allocates its control-OUT data buffer with
kmalloc() (not kzalloc) at the Length value from the Setup
packet, then copies that full len to userspace regardless of
how many bytes were actually received:
data = kmalloc(len, GFP_KERNEL);
...
ret = __ffs_ep0_queue_wait(ffs, data, len);
if ((ret > 0) && (copy_to_user(buf, data, len)))
ret = -EFAULT;
__ffs_ep0_queue_wait() returns req->actual, which on a short
control OUT transfer is strictly less than len. The
copy_to_user() call still copies len bytes, so on a short OUT
the last (len - ret) bytes of the kmalloc() buffer --
uninitialised slab residue -- are delivered to the FunctionFS
daemon.
Short ep0 OUT completions are specified USB control-transfer
behavior and are produced by in-tree UDCs:
* dwc2 continues on req->actual < req->length for ep0 DATA OUT
(short-not-ok is the only ep0-OUT stall path).
* aspeed_udc ends ep0 OUT on rx_len < ep->ep.maxpacket.
* renesas_usbf logs "ep0 short packet" and completes the
request.
* dwc3 stalls on short IN but not on short OUT.
A short ep0 OUT is therefore not evidence of a broken UDC; it is
a normal condition f_fs has to cope with. The sibling gadgetfs
implementation in drivers/usb/gadget/legacy/inode.c already does
this correctly via min(len, dev->req->actual) before
copy_to_user(). This patch brings f_fs.c to the same safe
pattern rather than trimming at a defensive layer.
The bug is reached from the FunctionFS device node, which in
real deployments is owned by the privileged gadget daemon
(adbd, UMS, composite gadget services, etc.); it is not
reachable from unprivileged userspace. Linux host stacks
normally reject short-wLength control OUTs before they reach
the gadget, so reproducing this required a build that
bypasses that host-side check. With the bypass in place, a
1-byte payload on a 64-byte Setup produces 63 bytes of
non-canary slab residue in the daemon's read buffer.
Fix by copying only ret (actually received) bytes to
userspace.
📍 영향받는 시스템
Linux kernel (FunctionFS를 사용하는 시스템)
⚔️ 공격 벡터
호스트 측의 체크를 우회하여 조작된 짧은 USB control-OUT 패킷을 전송함으로써 발생
🛡️ 대응 방법
커널 패치를 통해 copy_to_user() 호출 시 실제 수신된 바이트(ret)만큼만 복사하도록 수정
🔧 검증 코드
출력된 커널 버전이 해당 취약점이 수정된 패치 버전 이후인지 확인하십시오.