Skip to contentSkip to conversation

libsemanage: release the transaction lock when setup fails

PATCH In review Stephen Smalley 1 participant 2 messages Oct 23 – Oct 26 SELinux security module

lore
Share & tools
lore

Stephen Smalley

author maintainer
#0 lore raw

PATCH 1/1 libsemanage: release the transaction lock when setup fails

After acquiring the transaction lock, direct_begintrans() can fail while creating the sandbox or final output directory. The public begin function sets is_in_transaction only on success, so disconnect does not release the lock after such a failure. Destroying the handle then loses the descriptor without closing it. Other writers can remain blocked until the process exits.

Release the transaction lock on both post-acquisition setup failures. The existing release helper preserves errno and resets the descriptor. Leave the lock-acquisition failure path and successful transactions unchanged, so a failed contender cannot release another owner's lock.

---
 libsemanage/src/direct_api.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
libsemanage/src/direct_api.c +6 -2
index 05c9392c..db74fe93 100644
@@ -422,12 +422,16 @@ static int semanage_direct_begintrans(semanage_handle_t *sh)
 		return -1;
 	}
 	if ((semanage_make_sandbox(sh)) < 0) {
-		return -1;
+		goto err_unlock;
 	}
 	if ((semanage_make_final(sh)) < 0) {
-		return -1;
+		goto err_unlock;
 	}
 	return 0;
+
+err_unlock:
+	semanage_release_trans_lock(sh);
+	return -1;
 }
 
 /********************* utility functions *********************/
Signature · 1 line
2.56.0
author maintainer
#1 lore raw
Quoted 8 lines · Stephen Smalley

After acquiring the transaction lock, direct_begintrans() can fail while creating the sandbox or final output directory. The public begin function sets is_in_transaction only on success, so disconnect does not release the lock after such a failure. Destroying the handle then loses the descriptor without closing it. Other writers can remain blocked until the process exits.

Quoted 6 lines

Release the transaction lock on both post-acquisition setup failures. The existing release helper preserves errno and resets the descriptor. Leave the lock-acquisition failure path and successful transactions unchanged, so a failed contender cannot release another owner's lock.

This has been merged.