<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - -fsanitize=safe-stack can prevent -fstack-protector-strong from working sometimes"
   href="https://bugs.llvm.org/show_bug.cgi?id=43869">43869</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>-fsanitize=safe-stack can prevent -fstack-protector-strong from working sometimes
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>LLVM Codegen
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>leonardchan@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>