LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 24662 - stack-buffer-overflow in llvm::APInt::tcExtract
Summary: stack-buffer-overflow in llvm::APInt::tcExtract
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Common Code Generator Code (show other bugs)
Version: trunk
Hardware: PC Linux
: P normal
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks: 24639
  Show dependency tree
 
Reported: 2015-09-01 15:29 PDT by Kostya Serebryany
Modified: 2017-03-19 10:13 PDT (History)
3 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kostya Serebryany 2015-09-01 15:29:37 PDT
Found with libFuzzer

echo CgoKCmdsb2JhbCBpMzIgMzYKCgpkZWZpbmUgaTYwIEB0ZXN0MSgpIHsKICAgcmV0IGk2MCBmcHRvdWkoZmxvYXQgMHg0MDBEOTk5OUEwMDAwMDAwIHRvIGk2NzAwMTApCn0KCmRlZmluZSBmbG9hdCBAdGVzdDIoKSB7CiAgcmV0IGZsb2F0IHVpdG9mcChpNjAgMTcgdG8gZmw7YTYKdCkKfQoKZGVmaW5lIGk2NCBAdGVzdDMoKSB7CiAgcmV0IA==  | base64 --decode  |  ./bin/llvm-as - 


==24285==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffc33500d30 at pc 0x00000049db5c bp 0x7ffc335007f0 sp 0x7ffc334fffa8
WRITE of size 83744 at 0x7ffc33500d30 thread T0
    #0 0x49db5b in __asan_memset projects/compiler-rt/lib/asan/asan_interceptors.cc:404:3
    #1 0xcfd96a in llvm::APInt::tcExtract(unsigned long*, unsigned int, unsigned long const*, unsigned int, unsigned int) lib/Support/APInt.cpp:2468:21
    #2 0xcba4e7 in llvm::APFloat::convertToSignExtendedInteger(unsigned long*, unsigned int, bool, llvm::APFloat::roundingMode, bool*) const lib/Support/APFloat.cpp:2134:7
    #3 0xcb76ef in llvm::APFloat::convertToInteger(unsigned long*, unsigned int, bool, llvm::APFloat::roundingMode, bool*) const lib/Support/APFloat.cpp:2206:8
    #4 0xbe69ce in llvm::ConstantFoldCastInstruction(unsigned int, llvm::Constant*, llvm::Type*) lib/IR/ConstantFold.cpp:611:11
    #5 0x7f3b17 in getFoldedCast lib/IR/Constants.cpp:1580:22
    #6 0x7f3b17 in llvm::ConstantExpr::getFPToUI(llvm::Constant*, llvm::Type*, bool) lib/IR/Constants.cpp:1798
    #7 0x7e8034 in llvm::ConstantExpr::getCast(unsigned int, llvm::Constant*, llvm::Type*, bool) lib/IR/Constants.cpp:1619:12
    #8 0x531e50 in llvm::LLParser::ParseValID(llvm::ValID&, llvm::LLParser::PerFunctionState*) lib/AsmParser/LLParser.cpp:2785:22
    #9 0x59c4e3 in ParseValue lib/AsmParser/LLParser.cpp:4255:10
    #10 0x59c4e3 in ParseValue lib/AsmParser/LLParser.h:373
    #11 0x59c4e3 in llvm::LLParser::ParseRet(llvm::Instruction*&, llvm::BasicBlock*, llvm::LLParser::PerFunctionState&) lib/AsmParser/LLParser.cpp:4851
    #12 0x59a9ba in llvm::LLParser::ParseInstruction(llvm::Instruction*&, llvm::BasicBlock*, llvm::LLParser::PerFunctionState&) lib/AsmParser/LLParser.cpp:4678:38
    #13 0x59809d in llvm::LLParser::ParseBasicBlock(llvm::LLParser::PerFunctionState&) lib/AsmParser/LLParser.cpp:4630:13
    #14 0x5272e9 in llvm::LLParser::ParseFunctionBody(llvm::Function&) lib/AsmParser/LLParser.cpp:4578:9
    #15 0x50880d in llvm::LLParser::ParseDefine() lib/AsmParser/LLParser.cpp:411:10
    #16 0x5010f1 in llvm::LLParser::ParseTopLevelEntities() lib/AsmParser/LLParser.cpp:217:33
    #17 0x500b31 in llvm::LLParser::Run() lib/AsmParser/LLParser.cpp:48:10
    #18 0x4e0f91 in llvm::parseAssemblyInto(llvm::MemoryBufferRef, llvm::Module&, llvm::SMDiagnostic&, llvm::SlotMapping*) lib/AsmParser/Parser.cpp:31:10
    #19 0x4e204a in parseAssembly lib/AsmParser/Parser.cpp:41:7
    #20 0x4e204a in llvm::parseAssemblyFile(llvm::StringRef, llvm::SMDiagnostic&, llvm::LLVMContext&, llvm::SlotMapping*) lib/AsmParser/Parser.cpp:59
    #21 0x4dd7f0 in main tools/llvm-as/llvm-as.cpp:96:31
    #22 0x7fa9c4c2eec4 in __libc_start_main /build/buildd/eglibc-2.19/csu/libc-start.c:287
    #23 0x424d7b in _start (/usr/local/google/home/kcc/llvm-asan-cov-assertions/bin/llvm-as+0x424d7b)

Address 0x7ffc33500d30 is located in stack of thread T0 at offset 848 in frame
    #0 0xbe505f in llvm::ConstantFoldCastInstruction(unsigned int, llvm::Constant*, llvm::Type*) lib/IR/ConstantFold.cpp:525

  This frame has 17 object(s):
    [32, 184) 'Result.i.i'
    [256, 264) 'V.addr.i'
    [288, 376) 'IdxList.i'
    [416, 440) 'ref.tmp.i'
    [480, 496) 'ref.tmp125.i'
    [512, 664) 'res'
    [736, 737) 'ignored'
    [752, 776) 'Val'
    [816, 817) 'ignored137'
    [832, 848) 'x'
    [864, 880) 'Val146' <== Memory access at offset 848 partially underflows this variable
    [896, 912) 'api' <== Memory access at offset 848 partially underflows this variable
    [928, 952) 'apf' <== Memory access at offset 848 partially underflows this variable
    [992, 1008) 'ref.tmp272' <== Memory access at offset 848 partially underflows this variable
    [1024, 1040) 'ref.tmp298' <== Memory access at offset 848 partially underflows this variable
    [1056, 1072) 'ref.tmp315' <== Memory access at offset 848 partially underflows this variable
    [1088, 1104) 'ref.tmp336' <== Memory access at offset 848 partially underflows this variable
Comment 1 Nick Lewycky 2015-09-01 15:37:56 PDT
This testcase should be enough:

define i60 @test1() {
   ret i60 fptoui(float 0x400D9999A0000000 to i670010)
}
Comment 2 Simon Pilgrim 2017-03-17 05:03:26 PDT
https://reviews.llvm.org/D31074
Comment 3 Simon Pilgrim 2017-03-19 10:13:46 PDT
Fixed by rL298226