[clang] [BoundsSafety] Allow 'counted_by' attribute on pointers in structs in C (PR #90786)

2024-05-11 Thread Kees Cook via cfe-commits
@@ -0,0 +1,187 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +#define __counted_by(f) __attribute__((counted_by(f))) + +struct bar; + +struct not_found { + int count; + struct bar *fam[] __counted_by(bork); // expected-error {{use of undeclared identifier 'bork'}} +}; + +s

[clang] [BoundsSafety] Allow 'counted_by' attribute on pointers in structs in C (PR #90786)

2024-05-14 Thread Kees Cook via cfe-commits
https://github.com/kees approved this pull request. Thanks for the updates! Let's get this in and continue with the rest of the support. :) https://github.com/llvm/llvm-project/pull/90786 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https:/

[clang] [Clang] Fix __builtin_dynamic_object_size off by 4 (PR #111015)

2024-10-04 Thread Kees Cook via cfe-commits
kees wrote: > This is why I believe the gcc behavior is correct. When it knows the size > given to `malloc` it uses that. When it doesn't know that it simply returns > INT_MAX. When you ask gcc for the `__bdos` of the FAM it will use the `count` > to calculate the size. (nit: `SIZE_MAX`, not

[clang] [llvm] [PowerPC][ISelLowering] Support -mstack-protector-guard=tls (PR #110928)

2024-10-17 Thread Kees Cook via cfe-commits
https://github.com/kees closed https://github.com/llvm/llvm-project/pull/110928 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Clang] Implement labelled type filtering for overflow/truncation sanitizers w/ SSCLs (PR #107332)

2024-11-01 Thread Kees Cook via cfe-commits
kees wrote: > Thankfully, this PR and my other PR (WIP) leave the door open. You can ignore > all types and then mark a few as `no_wraps` or you can sanitize all types > (the default) and mark a few as `wraps`. Right, while I want to go full instrumentation, it's just not going to happen in t

[clang] [Clang] Introduce __builtin_is_modifiable_lvalue() (PR #132524)

2025-03-22 Thread Kees Cook via cfe-commits
kees wrote: > It looks like this is similar to `__builtin_constant_p` - what is the > proposed behavior wrt. side effects in the evaluated expression? gcc and > clang disagree about this a lot currently: https://godbolt.org/z/rbneznT9z It is intended to have no side-effects. I followed the sam

[clang] [Clang] Introduce __builtin_is_modifiable_lvalue() (PR #132524)

2025-03-21 Thread Kees Cook via cfe-commits
https://github.com/kees created https://github.com/llvm/llvm-project/pull/132524 Provide a way to introspect expressions to see if they are assignable, which becomes very useful in macros that want to perform additional work on arguments that are lvalues. GCC is adding this builtin as well: ht

[clang] [Clang] Introduce __builtin_is_modifiable_lvalue() (PR #132524)

2025-03-25 Thread Kees Cook via cfe-commits
kees wrote: Thanks for all the feedback! I'll continue working on this next week (I'm OoO this week). https://github.com/llvm/llvm-project/pull/132524 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listi

[clang] [Clang][counted_by] Add support for 'counted_by' on struct pointers (PR #137250)

2025-04-30 Thread Kees Cook via cfe-commits
kees wrote: This is looking good, but needs to support `void *` struct members (they are treated as byte-sized for pointer arithmetic and `memcpy`). GCC has added support for this. Otherwise, yes, this is building for Linux with some (non-`void *`) annotations added and is operating correctly.

[clang] [llvm] [sancov] Introduce optional callback for stack-depth tracking (PR #138323)

2025-05-04 Thread Kees Cook via cfe-commits
https://github.com/kees updated https://github.com/llvm/llvm-project/pull/138323 >From 729d249d3848c2e417174ed935bfefde5c048dc7 Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Fri, 2 May 2025 10:51:02 -0700 Subject: [PATCH] [sancov] Introduce optional callback for stack-depth tracking Normally -

[clang] [llvm] [sancov] Introduce optional callback for stack-depth tracking (PR #138323)

2025-05-04 Thread Kees Cook via cfe-commits
https://github.com/kees updated https://github.com/llvm/llvm-project/pull/138323 >From 027ff82e738f6bdf82f958a4774eb05d321b23ef Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Fri, 2 May 2025 10:51:02 -0700 Subject: [PATCH] [sancov] Introduce optional callback for stack-depth tracking Normally -

[clang] [llvm] [sancov] Introduce optional callback for stack-depth tracking (PR #138323)

2025-05-04 Thread Kees Cook via cfe-commits
@@ -34,6 +34,7 @@ class SanitizerArgs { std::vector CoverageIgnorelistFiles; std::vector BinaryMetadataIgnorelistFiles; int CoverageFeatures = 0; + int StackDepthCallbackMin = 0; kees wrote: Fixed. https://github.com/llvm/llvm-project/pull/138323 _

[clang] [llvm] [sancov] Introduce optional callback for stack-depth tracking (PR #138323)

2025-05-05 Thread Kees Cook via cfe-commits
kees wrote: Okay, a couple small clean-ups, and I've also solved the lack of dynamic stack size tracking. https://github.com/llvm/llvm-project/pull/138323 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/l

[clang] [llvm] [sancov] Introduce optional callback for stack-depth tracking (PR #138323)

2025-05-05 Thread Kees Cook via cfe-commits
@@ -1078,22 +1091,61 @@ void ModuleSanitizerCoverage::InjectCoverageAtBlock(Function &F, BasicBlock &BB, Store->setNoSanitizeMetadata(); } if (Options.StackDepth && IsEntryBB && !IsLeafFunc) { -// Check stack depth. If it's the deepest so far, record it. Modu

[clang] [llvm] [sancov] Introduce optional callback for stack-depth tracking (PR #138323)

2025-05-05 Thread Kees Cook via cfe-commits
https://github.com/kees updated https://github.com/llvm/llvm-project/pull/138323 >From a481c0b96417c63786811e5bf118f3eb2e7dabb1 Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Fri, 2 May 2025 10:51:02 -0700 Subject: [PATCH 1/2] [sancov] Introduce optional callback for stack-depth tracking Norma

[clang] [llvm] [sancov] Introduce optional callback for stack-depth tracking (PR #138323)

2025-05-05 Thread Kees Cook via cfe-commits
https://github.com/kees updated https://github.com/llvm/llvm-project/pull/138323 >From a481c0b96417c63786811e5bf118f3eb2e7dabb1 Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Fri, 2 May 2025 10:51:02 -0700 Subject: [PATCH] [sancov] Introduce optional callback for stack-depth tracking Normally -

[clang] [llvm] [sancov] Introduce optional callback for stack-depth tracking (PR #138323)

2025-05-05 Thread Kees Cook via cfe-commits
https://github.com/kees updated https://github.com/llvm/llvm-project/pull/138323 >From 549d71572f086a3ecab9d8cd4e546a55b078bf11 Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Fri, 2 May 2025 10:51:02 -0700 Subject: [PATCH 1/3] [sancov] Introduce optional callback for stack-depth tracking Norma

[clang] [llvm] [sancov] Introduce optional callback for stack-depth tracking (PR #138323)

2025-05-05 Thread Kees Cook via cfe-commits
@@ -2361,6 +2361,13 @@ def fsanitize_coverage_ignorelist : Joined<["-"], "fsanitize-coverage-ignorelist HelpText<"Disable sanitizer coverage instrumentation for modules and functions " "that match the provided special case list, even the allowed ones">,

[clang] [llvm] [sancov] Introduce optional callback for stack-depth tracking (PR #138323)

2025-05-05 Thread Kees Cook via cfe-commits
https://github.com/kees updated https://github.com/llvm/llvm-project/pull/138323 >From 03e2eead7c4034c81c79619c1507dd27145aaa43 Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Fri, 2 May 2025 10:51:02 -0700 Subject: [PATCH 1/2] [sancov] Introduce optional callback for stack-depth tracking Norma

[clang] [llvm] [sancov] Introduce optional callback for stack-depth tracking (PR #138323)

2025-05-05 Thread Kees Cook via cfe-commits
@@ -1078,22 +1091,61 @@ void ModuleSanitizerCoverage::InjectCoverageAtBlock(Function &F, BasicBlock &BB, Store->setNoSanitizeMetadata(); } if (Options.StackDepth && IsEntryBB && !IsLeafFunc) { -// Check stack depth. If it's the deepest so far, record it. Modu

[clang] [llvm] [sancov] Introduce optional callback for stack-depth tracking (PR #138323)

2025-05-02 Thread Kees Cook via cfe-commits
https://github.com/kees created https://github.com/llvm/llvm-project/pull/138323 Normally -fsanitize-coverage=stack-depth inserts inline arithmetic to update thread_local __sancov_lowest_stack. To support stack depth tracking in the Linux kernel, which does not implement traditional thread_loca

[clang] [llvm] [sancov] Introduce optional callback for stack-depth tracking (PR #138323)

2025-05-02 Thread Kees Cook via cfe-commits
https://github.com/kees updated https://github.com/llvm/llvm-project/pull/138323 >From 4c9e223b8f0457b3f3f66bbb3fa2688b49204cc9 Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Fri, 2 May 2025 10:51:02 -0700 Subject: [PATCH] [sancov] Introduce optional callback for stack-depth tracking Normally -

[clang] [llvm] [sancov] Introduce optional callback for stack-depth tracking (PR #138323)

2025-05-02 Thread Kees Cook via cfe-commits
kees wrote: > ⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️ > > You can test this locally with the following command: > View the diff from clang-format here. Whoops, yes, I've fixed these now. https://github.com/llvm/llvm-project/pull/138323 __

[clang] [llvm] [sancov] Introduce optional callback for stack-depth tracking (PR #138323)

2025-05-04 Thread Kees Cook via cfe-commits
@@ -1078,22 +1092,44 @@ void ModuleSanitizerCoverage::InjectCoverageAtBlock(Function &F, BasicBlock &BB, Store->setNoSanitizeMetadata(); } if (Options.StackDepth && IsEntryBB && !IsLeafFunc) { -// Check stack depth. If it's the deepest so far, record it. Modu

[clang] [llvm] [sancov] Introduce optional callback for stack-depth tracking (PR #138323)

2025-05-04 Thread Kees Cook via cfe-commits
kees wrote: > This is also missing flag and IR tests. Oh, yes, I will add those. Thanks! https://github.com/llvm/llvm-project/pull/138323 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commi

[clang] [randstruct] Also randomize composite function pointer structs (PR #138385)

2025-05-05 Thread Kees Cook via cfe-commits
https://github.com/kees closed https://github.com/llvm/llvm-project/pull/138385 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [llvm] [sancov] Introduce optional callback for stack-depth tracking (PR #138323)

2025-05-05 Thread Kees Cook via cfe-commits
@@ -2361,6 +2361,13 @@ def fsanitize_coverage_ignorelist : Joined<["-"], "fsanitize-coverage-ignorelist HelpText<"Disable sanitizer coverage instrumentation for modules and functions " "that match the provided special case list, even the allowed ones">,

[clang] [randstruct] Also randomize composite function pointer structs (PR #138385)

2025-05-02 Thread Kees Cook via cfe-commits
https://github.com/kees created https://github.com/llvm/llvm-project/pull/138385 Check for struct members that are structs filled only with function pointers by recursively examining it. Since the lamba IsFunctionPointerOrForwardDecl cannot call itself directly, move it into a helper function,

[clang] Reland #90786 ([BoundsSafety] Allow 'counted_by' attribute on pointers in structs in C) (PR #93121)

2025-03-01 Thread Kees Cook via cfe-commits
@@ -8663,31 +8663,95 @@ static const RecordDecl *GetEnclosingNamedOrTopAnonRecord(const FieldDecl *FD) { return RD; } -static bool -CheckCountExpr(Sema &S, FieldDecl *FD, Expr *E, - llvm::SmallVectorImpl &Decls) { +enum class CountedByInvalidPointeeTypeKind {

[clang] Reland #90786 ([BoundsSafety] Allow 'counted_by' attribute on pointers in structs in C) (PR #93121)

2025-02-26 Thread Kees Cook via cfe-commits
@@ -8663,31 +8663,95 @@ static const RecordDecl *GetEnclosingNamedOrTopAnonRecord(const FieldDecl *FD) { return RD; } -static bool -CheckCountExpr(Sema &S, FieldDecl *FD, Expr *E, - llvm::SmallVectorImpl &Decls) { +enum class CountedByInvalidPointeeTypeKind {

[clang] [llvm] [sancov] Introduce optional callback for stack-depth tracking (PR #138323)

2025-05-06 Thread Kees Cook via cfe-commits
@@ -158,6 +158,7 @@ struct SanitizerCoverageOptions { bool PCTable = false; bool NoPrune = false; bool StackDepth = false; + int StackDepthCallbackMin = 0; kees wrote: Yeah, I wasn't sure if I should keep it with the other StackDepth var. I've moved it

[clang] [llvm] [sancov] Introduce optional callback for stack-depth tracking (PR #138323)

2025-05-06 Thread Kees Cook via cfe-commits
@@ -1078,22 +1091,65 @@ void ModuleSanitizerCoverage::InjectCoverageAtBlock(Function &F, BasicBlock &BB, Store->setNoSanitizeMetadata(); } if (Options.StackDepth && IsEntryBB && !IsLeafFunc) { -// Check stack depth. If it's the deepest so far, record it. Modu

<    1   2