Distributed Replicated Block Device (DRBD) development
 help / color / mirror / Atom feed
From: Mathias Krause <minipli@grsecurity.net>
To: "Philipp Reisner" <philipp.reisner@linbit.com>,
	"Lars Ellenberg" <lars.ellenberg@linbit.com>,
	"Christoph Böhmwalder" <christoph.boehmwalder@linbit.com>
Cc: Mathias Krause <minipli@grsecurity.net>, drbd-dev@lists.linbit.com
Subject: [PATCH] compat: make block_device_operations tests grsec compatible
Date: Mon, 10 Nov 2025 12:59:33 -0000	[thread overview]
Message-ID: <20251110125924.511384-1-minipli@grsecurity.net> (raw)

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.

Signed-off-by: Mathias Krause <minipli@grsecurity.net>
---
 .../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(-)

diff --git a/drbd/drbd-kernel-compat/tests/block_device_operations_open_takes_gendisk.c b/drbd/drbd-kernel-compat/tests/block_device_operations_open_takes_gendisk.c
index d5f20fd569fb..9d77f16d09d8 100644
--- a/drbd/drbd-kernel-compat/tests/block_device_operations_open_takes_gendisk.c
+++ b/drbd/drbd-kernel-compat/tests/block_device_operations_open_takes_gendisk.c
@@ -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)));
 }
diff --git a/drbd/drbd-kernel-compat/tests/have_blk_qc_t_submit_bio.c b/drbd/drbd-kernel-compat/tests/have_blk_qc_t_submit_bio.c
index d7f2310dfbbd..d3e6dd792ff1 100644
--- a/drbd/drbd-kernel-compat/tests/have_blk_qc_t_submit_bio.c
+++ b/drbd/drbd-kernel-compat/tests/have_blk_qc_t_submit_bio.c
@@ -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)));
 }
diff --git a/drbd/drbd-kernel-compat/tests/have_void_submit_bio.c b/drbd/drbd-kernel-compat/tests/have_void_submit_bio.c
index c638faf020e1..09b56a658a46 100644
--- a/drbd/drbd-kernel-compat/tests/have_void_submit_bio.c
+++ b/drbd/drbd-kernel-compat/tests/have_void_submit_bio.c
@@ -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)));
 }
-- 
2.47.3


             reply	other threads:[~2025-11-10 12:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-10 12:59 Mathias Krause [this message]
2025-11-18 10:50 ` [PATCH] compat: make block_device_operations tests grsec compatible Christoph Böhmwalder

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=20251110125924.511384-1-minipli@grsecurity.net \
    --to=minipli@grsecurity.net \
    --cc=christoph.boehmwalder@linbit.com \
    --cc=drbd-dev@lists.linbit.com \
    --cc=lars.ellenberg@linbit.com \
    --cc=philipp.reisner@linbit.com \
    /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