Skip to content

Commit 67f31bb

Browse files
zzambersGoeLin
authored andcommitted
8293232: Fix race condition in pkcs11 SessionManager
Backport-of: 1e031e6a5886fba3009d8e5fa62416fe15a901b6
1 parent 3bcdb66 commit 67f31bb

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/SessionManager.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -207,7 +207,12 @@ void demoteObjSession(Session session) {
207207
// will be added to correct pool on release, nothing to do now
208208
return;
209209
}
210-
opSessions.release(session);
210+
// Objects could have been added to this session by other thread between
211+
// check in Session.removeObject method and objSessions.remove call
212+
// higher. Therefore releaseSession method, which performs additional
213+
// check for objects, is used here to avoid placing this session
214+
// in wrong pool due to race condition.
215+
releaseSession(session);
211216
}
212217

213218
private Session openSession() throws PKCS11Exception {

0 commit comments

Comments
 (0)