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: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected]

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@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@cp-snakewater:~/llvm-monorepo/llvm-build-3-master-fuchsia-toolchain$
./install/bin/clang++ ~/misc/test.cpp -fstack-protector-strong -std=c++17
leonardchan@cp-snakewater:~/llvm-monorepo/llvm-build-3-master-fuchsia-toolchain$
./a.out  # Aborts as expected
*** stack smashing detected ***: <unknown> terminated
Aborted
leonardchan@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@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.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to