[PATCH] dm verity: avoid duplicate tasklet static-key references

Samuel Moelius <[email protected]>
Newsgroups dev.linux.lists.dm-devel,org.kernel.vger.linux-kernel
Message-ID <20260609003526.1237608.fab64a07d85e.dm-verity-tasklet-static-key-leak@trailofbits.com>
dm-verity parses optional arguments twice during target construction.
When `try_verify_in_tasklet` is present, each parse pass increments the
`use_bh_wq_enabled` static key, but the target destructor decrements it
only once.

Creating and removing such a target can therefore leave the static key
enabled after the target is gone.

Only increment the static key when the option first enables tasklet
verification for the target.

Assisted-by: Codex:gpt-5.5-cyber-preview
Signed-off-by: Samuel Moelius <[email protected]>
---
 drivers/md/dm-verity-target.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/md/dm-verity-target.c b/drivers/md/dm-verity-target.c
index 9a9847f94c46..c06ccf7ee1b9 100644
--- a/drivers/md/dm-verity-target.c
+++ b/drivers/md/dm-verity-target.c
@@ -1262,8 +1262,10 @@ static int verity_parse_opt_args(struct dm_arg_set *as, struct dm_verity *v,
 			continue;
 
 		} else if (!strcasecmp(arg_name, DM_VERITY_OPT_TASKLET_VERIFY)) {
-			v->use_bh_wq = true;
-			static_branch_inc(&use_bh_wq_enabled);
+			if (!v->use_bh_wq) {
+				v->use_bh_wq = true;
+				static_branch_inc(&use_bh_wq_enabled);
+			}
 			continue;
 
 		} else if (verity_is_fec_opt_arg(arg_name)) {
-- 
2.43.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.