Skip to contentSkip to conversation

apparmor: use the condition in AA_BUG_FMT even with debug disabled

PATCH In review Mateusz Guzik 3 participants 4 messages Jan 27, 2025 – Jan 29, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 apparmor: use the condition in AA_BUG_FMT even with debug disabled

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;
| ^~~~

---

Plausibly the sock var wants to be eliminated altogether, but I just want this to build.

 security/apparmor/include/lib.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
security/apparmor/include/lib.h +5 -1
index 256f4577c653..d947998262b2 100644
@@ -60,7 +60,11 @@ do {									\
 #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
 
 int aa_parse_debug_params(const char *str);
Signature · 1 line
2.43.0
#1 lore raw

For the record, a previous patch that removes the sock variable was previously accepted:
https://lists.ubuntu.com/archives/apparmor/2025-January/013449.html
(patch) and https://lists.ubuntu.com/archives/apparmor/2025-January/013463.html
(ack from John Johansen)

Quoted 37 lines · Mateusz Guzik

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;
| ^~~~

---

Plausibly the sock var wants to be eliminated altogether, but I just want this to build.

 security/apparmor/include/lib.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
security/apparmor/include/lib.h +5 -2
index 256f4577c653..d947998262b2 100644
@@ -60,7 +60,11 @@ do {                                                                 \
 #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
 
 int aa_parse_debug_params(const char *str);
--

2.43.0

#2 lore raw
Quoted 7 lines · Ryan Lee

For the record, a previous patch that removes the sock variable was previously accepted:
https://lists.ubuntu.com/archives/apparmor/2025-January/013449.html
(patch) and https://lists.ubuntu.com/archives/apparmor/2025-January/013463.html
(ack from John Johansen)

That makes sense, but imo the posted patch is still warranted -- all other debug macros (WARN_ON, VM_WARN_ON etc.) are expected to evaluate the condition.

Signature · 1 line
Mateusz Guzik <mjguzik gmail.com>
maintainer Acked-by on v1 1/1
#3 lore raw
In reply to Mateusz Guzik
Quoted 7 lines · Mateusz Guzik

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;
| ^~~~

thanks, I have pulled this into my tree

Quoted 25 lines

---

Plausibly the sock var wants to be eliminated altogether, but I just want this to build.

  security/apparmor/include/lib.h | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
security/apparmor/include/lib.h +5 -1
index 256f4577c653..d947998262b2 100644
@@ -60,7 +60,11 @@ do {									\
  #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
 
  int aa_parse_debug_params(const char *str);