Skip to contentSkip to conversation

compat: make block_device_operations tests grsec compatible

PATCH Applied Mathias Krause 2 participants 2 messages Nov 10, 2025 – Nov 18, 2025 DRBD driver

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 compat: make block_device_operations tests grsec compatible

The grsecurity patch enforces that instances of certain types are always constified, with the help of a compiler plugin. One of these types is 'struct block_device_operations'. Code that tries to modify a such-typed object will cause compiler errors, leading to wrong results for the kernel compatibility tests.

Change these tests to do direct type compare tests instead of trying to modify the object, making them compatible with grsecurity kernels.

---
 .../tests/block_device_operations_open_takes_gendisk.c | 10 +++-------
 .../tests/have_blk_qc_t_submit_bio.c                   |  6 +++++-
 drbd/drbd-kernel-compat/tests/have_void_submit_bio.c   |  6 +++++-
 3 files changed, 13 insertions(+), 9 deletions(-)
drbd/drbd-kernel-compat/tests/block_device_operations_open_takes_gendisk.c +3 -7
index d5f20fd569fb..9d77f16d09d8 100644
@@ -5,13 +5,9 @@
 # define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
 #endif
 
-int foo_open(struct gendisk *disk, unsigned int mode)
-{
-	return 0;
-}
+int foo_open(struct gendisk *disk, unsigned int mode);
 
-void foo(void)
+void foo(struct block_device_operations *ops)
 {
-	struct block_device_operations ops;
-	BUILD_BUG_ON(!(__same_type(ops.open, &foo_open)));
+	BUILD_BUG_ON(!(__same_type(ops->open, &foo_open)));
 }
drbd/drbd-kernel-compat/tests/have_blk_qc_t_submit_bio.c +5 -1
index d7f2310dfbbd..d3e6dd792ff1 100644
@@ -2,9 +2,13 @@
 
 #include <linux/blkdev.h>
 
+#ifndef __same_type
+# define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
+#endif
+
 blk_qc_t submit(struct bio *bio);
 
 void foo(struct block_device_operations *ops)
 {
-	ops->submit_bio = submit;
+	BUILD_BUG_ON(!(__same_type(ops->submit_bio, &submit)));
 }
drbd/drbd-kernel-compat/tests/have_void_submit_bio.c +5 -1
index c638faf020e1..09b56a658a46 100644
@@ -2,9 +2,13 @@
 
 #include <linux/blkdev.h>
 
+#ifndef __same_type
+# define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
+#endif
+
 void submit(struct bio *bio);
 
 void foo(struct block_device_operations *ops)
 {
-	ops->submit_bio = submit;
+	BUILD_BUG_ON(!(__same_type(ops->submit_bio, &submit)));
 }
Signature · 1 line
2.47.3
maintainer Applied
#1 lore raw

Am 10.11.25 um 13:59 schrieb Mathias Krause:

Quoted 10 lines

The grsecurity patch enforces that instances of certain types are always constified, with the help of a compiler plugin. One of these types is 'struct block_device_operations'. Code that tries to modify a such-typed object will cause compiler errors, leading to wrong results for the kernel compatibility tests.

Change these tests to do direct type compare tests instead of trying to modify the object, making them compatible with grsecurity kernels.

Thanks, applied: https://github.com/LINBIT/drbd/commit/376a2932bf8f44dd0a18bc70f3309f3e71e0d37d

Signature · 3 lines
Christoph Böhmwalder
LINBIT | Keeping the Digital World Running
DRBD HA —  Disaster Recovery — Software defined Storage