Heap-buffer-overflow in flattenArgument for an empty stream-output element type

Đang mở Phù hợp với người mới
#9,173 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
cpp
Lĩnh vực
compilers

Hướng nghiên cứu

Bắt đầu với SROA_Parameter_HLSL::flattenArgument trong lib/Transforms/Scalar/ScalarReplAggregatesHLSL.cpp, đặc biệt là thao tác truy cập FlatAnnotationList[startArgIndex] và nhánh bỏ qua các tham số struct rỗng. Tái hiện bằng shader hình học GSOut rỗng được cung cấp, dùng dxc -T gs_6_0 -E main poc.hlsl -Fo poc.dxil, rồi so sánh với shader đối chứng không rỗng. Hoàn thành khi trường hợp phần tử rỗng biên dịch được hoặc đưa ra chẩn đoán mà không đọc vượt phạm vi.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug needs-triage

Description

A geometry shader whose stream-output element type is an empty struct makes DXC read past the end of a heap block in the SROA pass. The shader is valid HLSL. In the release build nothing is printed and the compiler exits with code 0; under AddressSanitizer it is a heap-buffer-overflow READ of size 8. In a build with hardened libc++ (the way Chromium builds DXC) the bounds check of std::vector::operator[] ends the process.

The read is in SROA_Parameter_HLSL::flattenArgument, lib/Transforms/Scalar/ScalarReplAggregatesHLSL.cpp, lines 5798–5801 at b43c5651:

  if (inputQual == DxilParamInputQual::OutStream0 || ... OutStream3)
    startArgIndex++;

  DxilParameterAnnotation &flatParamAnnotation =
      FlatAnnotationList[startArgIndex];

For a stream-output parameter the index is advanced past the stream object and then used without checking that flattening the element type produced an entry. With an empty struct it produces none (the "skip empty struct parameters" branch a little above, lines 5508–5513, continues without appending), so the list holds only the stream object and the access reads past its end.

Steps to Reproduce

A geometry shader with an empty stream-output element type:

poc.hlsl
struct GSOut { };
[maxvertexcount(1)]
void main(inout PointStream<GSOut> stream) { }
dxc -T gs_6_0 -E main poc.hlsl -Fo poc.dxil

Control, control.hlsl: the same shader with a non-empty element type. It compiles on every build listed under Environment.

control.hlsl
struct GSOut { float4 c : SV_Position; };
[maxvertexcount(1)]
void main(inout PointStream<GSOut> stream) { GSOut o = (GSOut)0; o.c = float4(0, 0, 0, 1); stream.Append(o); }

Actual Behavior

Release 1.9.2609.5: no output, exit code 0. The read happens and nothing observes it.

Build with AddressSanitizer, with or without assertions: exit code 1 and heap-buffer-overflow READ of size 8 in SROA_Parameter_HLSL::flattenArgument, on memory that flattenArgument itself allocated.

AddressSanitizer report (abbreviated)

The frames carry symbols but no line information, so they show the library offset instead.

==1821290==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x50f0000006b8 at pc 0x7fbba8f20fe5 bp 0x7fff87ead510 sp 0x7fff87ead500
READ of size 8 at 0x50f0000006b8 thread T0
    #0 in SROA_Parameter_HLSL::flattenArgument(...)                      libdxcompiler.so+0x1d20fe4
    #1 in SROA_Parameter_HLSL::createFlattenedFunction(llvm::Function*)  libdxcompiler.so+0x1d37679
    #2 in SROA_Parameter_HLSL::runOnModule(llvm::Module&)                libdxcompiler.so+0x1d463ce
    #3 in llvm::legacy::PassManagerImpl::run(llvm::Module&)              libdxcompiler.so+0x64ad66d
    ...
    #10 in DxcCompiler::Compile(...)                                     libdxcompiler.so+0x86769d

0x50f0000006b8 is located 40 bytes after 176-byte region [0x50f0000005e0,0x50f000000690)
allocated by thread T0 here:
    #0 in operator new(unsigned long)
    #1 in std::vector<hlsl::DxilParameterAnnotation>::_M_realloc_insert<hlsl::DxilParameterAnnotation>(...)
    #2 in SROA_Parameter_HLSL::flattenArgument(...)                      libdxcompiler.so+0x1d1d519
    #3 in SROA_Parameter_HLSL::createFlattenedFunction(llvm::Function*)  libdxcompiler.so+0x1d37679
    #4 in SROA_Parameter_HLSL::runOnModule(llvm::Module&)                libdxcompiler.so+0x1d463ce

SUMMARY: AddressSanitizer: heap-buffer-overflow (libdxcompiler.so+0x1d20fe4) in SROA_Parameter_HLSL::flattenArgument

The 176-byte region is the std::vector<DxilParameterAnnotation> that flattenArgument fills; with the empty element type it holds only the stream object.

Expected: the shader compiles to DXIL, or it is rejected with a diagnostic. Either way there should be no out-of-bounds read.

The same shader shape was also compiled with the DXC that Dawn builds (1.10.2609.0, 5de1dbca) with Chromium's hardened libc++, on Windows 11: the process ends with vector.h:414: libc++ Hardening assertion __n < size() failed: vector[] index out of bounds.

Environment

  • DXC version
    • Release 1.9.2609.5: libdxcompiler.so: 1.9(5512-01b62ad4)(1.9.2609.5)
    • Built from source at b43c5651d744e606552b3274668a160be21db0f8 (main, 2026-11-24): libdxcompiler.so: 1.11(1-b43c5651)(1.10.0.10001), with AddressSanitizer, once with assertions and once without.
    • The code quoted above is the same on current main (2600ae89a615); I have not compiled that revision.
  • Host Operating System
    • Ubuntu 24.04.4 LTS, x86_64, kernel 6.8.
    • The hardened-libc++ observation is from Windows 11 (10.0.26100).
Ngôn ngữ chính
C++
Star
3.7k
Fork
926
Merge trung bình
3 ngày 22 giờ
Pull request đã merge (30 ngày)
45

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của microsoft/DirectXShaderCompiler

Tất cả issue của microsoft/DirectXShaderCompiler

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.