libsemanage: release the transaction lock when setup fails
Stephen Smalley
maintainerPATCH 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
@@ -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
Stephen Smalley
maintainerQuoted 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 setsis_in_transactiononly 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.
Signed-off-by Stephen Smalley <[email protected]>
This has been merged.