From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Mateusz Guzik <mjguzik@gmail.com>,
John Johansen <john.johansen@canonical.com>,
Sasha Levin <sashal@kernel.org>,
rdunlap@infradead.org, ryan.lee@canonical.com, linux@treblig.org
Subject: [PATCH AUTOSEL 6.16-6.1] apparmor: use the condition in AA_BUG_FMT even with debug disabled
Date: Fri, 8 Aug 2025 11:30:50 -0400 [thread overview]
Message-ID: <20250808153054.1250675-10-sashal@kernel.org> (raw)
In-Reply-To: <20250808153054.1250675-1-sashal@kernel.org>
From: Mateusz Guzik <mjguzik@gmail.com>
[ Upstream commit 67e370aa7f968f6a4f3573ed61a77b36d1b26475 ]
This follows the established practice and fixes a build failure for me:
security/apparmor/file.c: In function ‘__file_sock_perm’:
security/apparmor/file.c:544:24: error: unused variable ‘sock’ [-Werror=unused-variable]
544 | struct socket *sock = (struct socket *) file->private_data;
| ^~~~
Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
LLM Generated explanations, may be completely bogus:
**Backport Status: YES**
This commit should be backported to stable kernel trees for the
following reasons:
1. **It fixes a real build failure**: The commit message clearly states
it fixes a build failure with `-Werror=unused-variable`. When
`CONFIG_SECURITY_APPARMOR_DEBUG_ASSERTS` is disabled, the
`AA_BUG_FMT` macro becomes just `no_printk(fmt, ##args)`, which
doesn't evaluate the condition `X`. This causes the `sock` variable
in `__file_sock_perm()` to be unused, triggering a compiler warning
that becomes an error with `-Werror`.
2. **The fix is minimal and contained**: The change only modifies the
`AA_BUG_FMT` macro definition when debug is disabled, adding
`BUILD_BUG_ON_INVALID(X)` which forces the compiler to evaluate the
condition without generating any runtime code. This is a well-
established pattern in the kernel (as seen in `VM_BUG_ON` and similar
macros in `include/linux/mmdebug.h`).
3. **No functional changes or side effects**: The fix doesn't change any
runtime behavior. `BUILD_BUG_ON_INVALID(e)` is defined as
`((void)(sizeof((__force long)(e))))` which only evaluates the
expression at compile time to ensure it's valid, without generating
any code.
4. **Follows established kernel patterns**: The commit message states
"This follows the established practice," and indeed, examining other
kernel debug macros like `VM_BUG_ON` shows they use the exact same
pattern - using `BUILD_BUG_ON_INVALID` when debug is disabled to
ensure the condition is still evaluated by the compiler.
5. **Low risk**: This is a compile-time only change that prevents build
failures. It cannot introduce runtime regressions since it generates
no runtime code.
6. **Affects a security subsystem**: AppArmor is a security module, and
build failures in security code can prevent users from building
kernels with their desired security configuration.
The commit is a classic example of a safe, minimal fix that resolves a
real problem without introducing new risks, making it an ideal candidate
for stable backporting.
security/apparmor/include/lib.h | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/security/apparmor/include/lib.h b/security/apparmor/include/lib.h
index f11a0db7f51d..e83f45e936a7 100644
--- a/security/apparmor/include/lib.h
+++ b/security/apparmor/include/lib.h
@@ -48,7 +48,11 @@ extern struct aa_dfa *stacksplitdfa;
#define AA_BUG_FMT(X, fmt, args...) \
WARN((X), "AppArmor WARN %s: (" #X "): " fmt, __func__, ##args)
#else
-#define AA_BUG_FMT(X, fmt, args...) no_printk(fmt, ##args)
+#define AA_BUG_FMT(X, fmt, args...) \
+ do { \
+ BUILD_BUG_ON_INVALID(X); \
+ no_printk(fmt, ##args); \
+ } while (0)
#endif
#define AA_ERROR(fmt, args...) \
--
2.39.5
next prev parent reply other threads:[~2025-08-08 15:31 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-08 15:30 [PATCH AUTOSEL 6.16-6.6] apparmor: shift ouid when mediating hard links in userns Sasha Levin
2025-08-08 15:30 ` [PATCH AUTOSEL 6.16-5.10] md: dm-zoned-target: Initialize return variable r to avoid uninitialized use Sasha Levin
2025-08-08 15:30 ` [PATCH AUTOSEL 6.16-5.4] i3c: don't fail if GETHDRCAP is unsupported Sasha Levin
2025-08-08 15:30 ` Sasha Levin
2025-08-08 15:30 ` [PATCH AUTOSEL 6.16-5.10] dm-mpath: don't print the "loaded" message if registering fails Sasha Levin
2025-08-08 15:30 ` [PATCH AUTOSEL 6.16-5.10] rtc: ds1307: handle oscillator stop flag (OSF) for ds1341 Sasha Levin
2025-08-11 16:46 ` Meagan Lloyd
2025-08-16 13:07 ` Sasha Levin
2025-08-08 15:30 ` [PATCH AUTOSEL 6.16-5.4] i3c: add missing include to internal header Sasha Levin
2025-08-08 15:30 ` Sasha Levin
2025-08-08 15:30 ` [PATCH AUTOSEL 6.16-6.1] i3c: master: Initialize ret in i3c_i2c_notifier_call() Sasha Levin
2025-08-08 15:30 ` Sasha Levin
2025-08-08 15:30 ` [PATCH AUTOSEL 6.16-5.4] PCI: pnv_php: Work around switches with broken presence detection Sasha Levin
2025-08-08 15:30 ` [PATCH AUTOSEL 6.16-6.1] module: Prevent silent truncation of module name in delete_module(2) Sasha Levin
2025-08-08 15:30 ` Sasha Levin [this message]
2025-08-08 15:30 ` [PATCH AUTOSEL 6.16-6.6] powerpc/eeh: Make EEH driver device hotplug safe Sasha Levin
2025-08-08 15:30 ` [PATCH AUTOSEL 6.16-6.12] apparmor: fix x_table_lookup when stacking is not the first entry Sasha Levin
2025-08-08 15:30 ` [PATCH AUTOSEL 6.16-6.1] dm-table: fix checking for rq stackable devices Sasha Levin
2025-08-08 15:30 ` [PATCH AUTOSEL 6.16-5.10] PCI: pnv_php: Clean up allocated IRQs on unplug Sasha Levin
2025-08-08 15:59 ` Timothy Pearson
2025-08-08 17:04 ` Sasha Levin
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=20250808153054.1250675-10-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=john.johansen@canonical.com \
--cc=linux@treblig.org \
--cc=mjguzik@gmail.com \
--cc=patches@lists.linux.dev \
--cc=rdunlap@infradead.org \
--cc=ryan.lee@canonical.com \
--cc=stable@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.