Hi @Kan_Li ,
I tried looking into the code further, below is my observation.
The SM_Close(NULL,0) call from within the sss_pkcs11_pal_core.c is closing fd "0" even though there is no prior connection to the Security module.
This is because the "pSockCtx->sockfd" is initialized as static so gets a default value of 0.
See below code for reference from smComSocket_linux.c line ~50.
typedef struct
{
int sockfd;
char * ipString;
} socket_Context_t;
static socket_Context_t sockCtx;
static socket_Context_t* pSockCtx = (socket_Context_t *)&sockCtx;
static U32 smComSocket_GetATR(U8* pAtr, U16* atrLen);
U16 smComSocket_Close()
{
if (pSockCtx->ipString != NULL)
free(pSockCtx->ipString);
pSockCtx->ipString = NULL;
close(pSockCtx->sockfd);
return SW_OK;
}
I think adding a static initializer to sockfd (may be -1) and a condition to check if fd is valid before closing should fix the issue.
Let me know your thoughts.
I have another question:
Why is the SM_Close(NULL, 0) call inside the sss_pkcs11_pal_core.c file required at all??

I temporarily removed the SM_Close(NULL, 0) and ran pkcs11 operations concurrently. Everything seemed to work fine.
Can you clarify on why this is really required at first place please?
Thanks in advance.
Regards,
Riz