[llvm-bugs] [Bug 43869] New: -fsanitize=safe-stack can prevent -fstack-protector-strong from working sometimes

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Oct 31 16:46:00 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=43869

            Bug ID: 43869
           Summary: -fsanitize=safe-stack can prevent
                    -fstack-protector-strong from working sometimes
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: leonardchan at google.com
                CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
                    richard-llvm at metafoo.co.uk

We ran into an instance where using `-fsanitize=safe-stack
-fstack-protector-strong` does not abort properly as opposed to just using
`-fstack-protector-strong`.

Example:
```
leonardchan at cp-snakewater:~/llvm-monorepo/llvm-build-3-master-fuchsia-toolchain$
cat ~/misc/test.cpp
#include <cstdlib>
#include <cstdio>
#include <cstdint>
#include <string>
#include <string_view>

void write(void *src, size_t len) {
  memset(src, rand(), len);
}

std::string change_str(std::string_view str) {
  std::string s("__");
  return s + str.data();
}

std::string func() {
  uint32_t x;
  write(&x, 5);  // This should be caught since we are writing outside of x
  return change_str(std::to_string(x));
}

int main() {
  srand(0);
  printf("%s\n", func().c_str());
}
leonardchan at cp-snakewater:~/llvm-monorepo/llvm-build-3-master-fuchsia-toolchain$
./install/bin/clang++ ~/misc/test.cpp -fstack-protector-strong -std=c++17
leonardchan at cp-snakewater:~/llvm-monorepo/llvm-build-3-master-fuchsia-toolchain$
./a.out  # Aborts as expected
*** stack smashing detected ***: <unknown> terminated
Aborted
leonardchan at cp-snakewater:~/llvm-monorepo/llvm-build-3-master-fuchsia-toolchain$
./install/bin/clang++ ~/misc/test.cpp -fsanitize=safe-stack
-fstack-protector-strong -std=c++17
leonardchan at cp-snakewater:~/llvm-monorepo/llvm-build-3-master-fuchsia-toolchain$
./a.out  # No error
__1734829927
```

We abort normally with just `-fstack-protector-strong`, but also adding
`-fsanitize=safe-stack` avoids the abort. I would expect SafeStack and stack
protectors to complement each other rather than one replacing the other.

Not sure if this is related also, but using `-fsanitize=safe-stack` on it's own
still doesn't abort or indicate error.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20191031/9341d819/attachment.html>


More information about the llvm-bugs mailing list