From: Jann Horn <jannh@google.com>
To: Kees Cook <kees@kernel.org>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>,
linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org,
Jann Horn <jannh@google.com>
Subject: [PATCH] bug: remove __must_check requirement for CHECK_DATA_CORRUPTION()
Date: Wed, 12 Aug 2026 21:46:14 +0200 [thread overview]
Message-ID: <20260812-data-corruption-mustcheck-v1-1-5f59bd3bc2b8@google.com> (raw)
There are codepaths that currently use something like WARN() where
CHECK_DATA_CORRUPTION() would be more appropriate, but it is not possible
to gracefully bail out when corruption has been detected.
CHECK_DATA_CORRUPTION() is currently deliberately unusable in such cases.
While it would be nice for users of CHECK_DATA_CORRUPTION() to bail out on
corruption, that shouldn't be a hard requirement for
CHECK_DATA_CORRUPTION().
So remove the __must_check requirement so that CHECK_DATA_CORRUPTION() can
be used in codepaths where bailing out is infeasible.
Signed-off-by: Jann Horn <jannh@google.com>
---
I think this should probably go through Kees' hardening tree?
This patch is inspired by me looking at file_ref_inc() and thinking
that that really should be using CHECK_DATA_CORRUPTION().
---
include/linux/bug.h | 31 +++++++++++++++----------------
1 file changed, 15 insertions(+), 16 deletions(-)
diff --git a/include/linux/bug.h b/include/linux/bug.h
index 17a4933c611b..e8d1febd8ae4 100644
--- a/include/linux/bug.h
+++ b/include/linux/bug.h
@@ -89,22 +89,21 @@ static inline void mem_dump_obj(void *object) {}
/*
* Since detected data corruption should stop operation on the affected
- * structures. Return value must be checked and sanely acted on by caller.
+ * structures. Return value should be checked and sanely acted on by caller if
+ * possible.
*/
-static inline __must_check bool check_data_corruption(bool v) { return v; }
-#define CHECK_DATA_CORRUPTION(condition, addr, fmt, ...) \
- check_data_corruption(({ \
- bool corruption = unlikely(condition); \
- if (corruption) { \
- if (addr) \
- mem_dump_obj(addr); \
- if (IS_ENABLED(CONFIG_BUG_ON_DATA_CORRUPTION)) { \
- pr_err(fmt, ##__VA_ARGS__); \
- BUG(); \
- } else \
- WARN(1, fmt, ##__VA_ARGS__); \
- } \
- corruption; \
- }))
+#define CHECK_DATA_CORRUPTION(condition, addr, fmt, ...) ({ \
+ bool corruption = unlikely(condition); \
+ if (corruption) { \
+ if (addr) \
+ mem_dump_obj(addr); \
+ if (IS_ENABLED(CONFIG_BUG_ON_DATA_CORRUPTION)) { \
+ pr_err(fmt, ##__VA_ARGS__); \
+ BUG(); \
+ } else \
+ WARN(1, fmt, ##__VA_ARGS__); \
+ } \
+ corruption; \
+})
#endif /* _LINUX_BUG_H */
---
base-commit: 3d6d817622b0a9721e3cc404df3469171582be13
change-id: 20260812-data-corruption-mustcheck-c1a8f76d6e24
Best regards,
--
Jann Horn <jannh@google.com>
reply other threads:[~2026-08-12 19:46 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260812-data-corruption-mustcheck-v1-1-5f59bd3bc2b8@google.com \
--to=jannh@google.com \
--cc=gustavoars@kernel.org \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.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®