From: "tip-bot2 for Jann Horn" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Jann Horn <jannh@google.com>,
"Peter Zijlstra (Intel)" <peterz@infradead.org>,
Will Deacon <will@kernel.org>,
x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: locking/core] refcount: Use CONFIG_BUG_ON_DATA_CORRUPTION for UAF-related errors
Date: Fri, 02 Oct 2026 09:38:40 -0000 [thread overview]
Message-ID: <179093392037.3910103.15878606329217264167.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20260812-refcount-bug-on-data-corruption-v1-1-c6da63566101@google.com>
The following commit has been merged into the locking/core branch of tip:
Commit-ID: 5b5224220747029bbaee8ab851cc6c599c48eded
Gitweb: https://git.kernel.org/tip/5b5224220747029bbaee8ab851cc6c599c48eded
Author: Jann Horn <jannh@google.com>
AuthorDate: Wed, 12 Aug 2026 20:56:38 +02:00
Committer: Peter Zijlstra <peterz@infradead.org>
CommitterDate: Thu, 01 Oct 2026 14:00:40 +02:00
refcount: Use CONFIG_BUG_ON_DATA_CORRUPTION for UAF-related errors
Some refcount issues are not necessarily associated with memory corruption,
but REFCOUNT_ADD_UAF suggests that a UAF either just happened or is about
to happen.
REFCOUNT_SUB_UAF is also an indicator that reference counting is wrong, and
suggests (less strongly) that a UAF access might have happened recently.
In these cases, BUG() is appropriate if CONFIG_BUG_ON_DATA_CORRUPTION is
set.
Signed-off-by: Jann Horn <jannh@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Will Deacon <will@kernel.org>
Link: https://patch.msgid.link/20260812-refcount-bug-on-data-corruption-v1-1-c6da63566101@google.com
---
lib/refcount.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/lib/refcount.c b/lib/refcount.c
index a207a8f..c0f0dc5 100644
--- a/lib/refcount.c
+++ b/lib/refcount.c
@@ -10,6 +10,15 @@
#define REFCOUNT_WARN(str) WARN_ONCE(1, "refcount_t: " str ".\n")
+#ifdef CONFIG_BUG_ON_DATA_CORRUPTION
+#define REFCOUNT_CORRUPTION(str) ({ \
+ pr_err("refcount_t: " str ".\n"); \
+ BUG(); \
+})
+#else
+#define REFCOUNT_CORRUPTION(str) REFCOUNT_WARN(str)
+#endif
+
void refcount_warn_saturate(refcount_t *r, enum refcount_saturation_type t)
{
refcount_set(r, REFCOUNT_SATURATED);
@@ -22,10 +31,10 @@ void refcount_warn_saturate(refcount_t *r, enum refcount_saturation_type t)
REFCOUNT_WARN("saturated; leaking memory");
break;
case REFCOUNT_ADD_UAF:
- REFCOUNT_WARN("addition on 0; use-after-free");
+ REFCOUNT_CORRUPTION("addition on 0; use-after-free");
break;
case REFCOUNT_SUB_UAF:
- REFCOUNT_WARN("underflow; use-after-free");
+ REFCOUNT_CORRUPTION("underflow; use-after-free");
break;
case REFCOUNT_DEC_LEAK:
REFCOUNT_WARN("decrement hit 0; leaking memory");
@@ -84,7 +93,7 @@ bool refcount_dec_not_one(refcount_t *r)
new = val - 1;
if (new > val) {
- WARN_ONCE(new > val, "refcount_t: underflow; use-after-free.\n");
+ REFCOUNT_CORRUPTION("underflow; use-after-free");
return true;
}
prev parent reply other threads:[~2026-10-02 9:38 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-12 18:56 [PATCH] " Jann Horn
2026-09-29 13:13 ` Will Deacon
2026-09-29 14:05 ` Jann Horn
2026-09-29 14:29 ` Peter Zijlstra
2026-10-02 9:38 ` tip-bot2 for Jann Horn [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179093392037.3910103.15878606329217264167.tip-bot2@tip-bot2 \
--to=tip-bot2@linutronix.de \
--cc=jannh@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=will@kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®