[opensc-devel] Segmentation fault in pkcs11-tool
Hello, I am new to OpenSC but I was looking for a 3rd party tool with which I could test my self-developed pkcs11 library and I came across the OpenSC pkcs11-tool. I installed OpenSC under Ubuntu11.10, following http://www.gooze.eu/howto/smartcard-quickstarter-guide/opensc-installation-under-gnu-linux everything went fine, but when I wanted to run the pkcs11-tool: pkcs11-tool --module /home/anna/PKCS11_Project/libPkcs11.so -l -O I got segmentation fault. I was able to find the place where the code crashed. In pkcs11-tool.c the line (558): rv = p11-C_Initialize(NULL); seem to crash. The message is just Segmentation fault The module loads apparently fine. module = C_LoadModule(opt_module, p11); //no error here The problem is, that in my pkcs11 library I put an error message at the very beginning of the C_Initialize function, but not even this is printed out. So I don't think the crash comes from my library. I turned on the creation of a log file in my pkcs11 library, but not even my pkcs11 library log file is created. I tried to google this problem and found this old thread: http://www.opensc-project.org/pipermail/opensc-devel/2003-April/000831.html But it didn't really help me (rebuilding openssl didn't solve the problem..). Could anyone help? Thanks for any help, Anna ___ opensc-devel mailing list opensc-devel@lists.opensc-project.org http://www.opensc-project.org/mailman/listinfo/opensc-devel
Re: [opensc-devel] Segmentation fault in pkcs11-tool
On 12/17/2012 7:01 AM, Anna Pavlova wrote: Hello, I am new to OpenSC but I was looking for a 3rd party tool with which I could test my self-developed pkcs11 library and I came across the OpenSC pkcs11-tool. I installed OpenSC under Ubuntu11.10, following http://www.gooze.eu/howto/smartcard-quickstarter-guide/opensc-installation-under-gnu-linux everything went fine, but when I wanted to run the pkcs11-tool: pkcs11-tool --module /home/anna/PKCS11_Project/libPkcs11.so -l -O I got segmentation fault. I was able to find the place where the code crashed. In pkcs11-tool.c the line (558): rv = p11-C_Initialize(NULL); Sounds like p11 == NULL, or p11-C_Initialize is NULL or not valid. It should point at your C_Initialize routine. Can you run this under gdb? seem to crash. The message is just Segmentation fault The module loads apparently fine. module = C_LoadModule(opt_module, p11); //no error here The problem is, that in my pkcs11 library I put an error message at the very beginning of the C_Initialize function, but not even this is printed out. So I don't think the crash comes from my library. I turned on the creation of a log file in my pkcs11 library, but not even my pkcs11 library log file is created. Did you define a C_GetFunctionList in the module? You must make sure the you module is linked as a module and not just a shared library, so that functions returned by C_GetFunctionList points at the functions in your module, and not ones that may be defined by the caller. Have a look at the pkcs11-spy too which is a PKCS#11 module that loads a second PKCS#11 module. I tried to google this problem and found this old thread: http://www.opensc-project.org/pipermail/opensc-devel/2003-April/000831.html But it didn't really help me (rebuilding openssl didn't solve the problem..). Could anyone help? Thanks for any help, Anna ___ opensc-devel mailing list opensc-devel@lists.opensc-project.org http://www.opensc-project.org/mailman/listinfo/opensc-devel -- Douglas E. Engert deeng...@anl.gov Argonne National Laboratory 9700 South Cass Avenue Argonne, Illinois 60439 (630) 252-5444 ___ opensc-devel mailing list opensc-devel@lists.opensc-project.org http://www.opensc-project.org/mailman/listinfo/opensc-devel
Re: [opensc-devel] Segmentation fault in pkcs11-tool
Hello Douglas, Sounds like p11 == NULL, or p11-C_Initialize is NULL or not valid. I did: printf(p11 = 0x%0x, p11-C_Initialize = 0x%0x\n, p11, p11-C_Initialize); in pkcs11-tool.c, just after C_LoadModule and before p11-C_Initialize(NULL) and got: p11 = 0xb7214060, p11-C_Initialize = 0x5810b6fa so it is not null. Can you run this under gdb? Unfortunately I'm not very good in gdb :-( anna@anna:~/OpenSC/src/tools$ export LD_LIBRARY_PATH=`ls ../*/.libs -d | tr '\012' :` anna@anna:~/OpenSC/src/tools$ cd .libs/ anna@anna:~/OpenSC/src/tools/. libs$ gdb 'pkcs11-tool --module /home/anna/PKCS11_Project/libPkcs11.so' the last command returns: pkcs11-tool --module /home/anna/PKCS11_Project/libPkcs11.so: No such file or directory. Of course, when I run only: anna@anna:~/OpenSC/src/tools/.libs$ gdb pkcs11-tool that one runs and I can run in debug mode, but I'm afraid that then I'm not loading my module. Do you know how can I run gdb and also use my own library? Sorry, I'm not really used to work with gdb :-( Did you define a C_GetFunctionList in the module? Yes I did. In fact when I printed out in pkcs11-tool.c printf(%d \n,p11-version.major); printf(%d \n,p11-version.minor); it printed out the correct values. This is also the only thing that I can call with p11. But yes, C_GetFunctionList is defined in my library. You must make sure the you module is linked as a module and not just a shared library, so that functions returned by C_GetFunctionList points at the functions in your module, and not ones that may be defined by the caller. This is an interesting point, thank you. Actually no, I have built and linked it just like a shared library. I thought what's written as 'module' in the code and 'shared library' are the same things. Thanks, Anna On Mon, Dec 17, 2012 at 4:18 PM, Douglas E. Engert deeng...@anl.gov wrote: On 12/17/2012 7:01 AM, Anna Pavlova wrote: Hello, I am new to OpenSC but I was looking for a 3rd party tool with which I could test my self-developed pkcs11 library and I came across the OpenSC pkcs11-tool. I installed OpenSC under Ubuntu11.10, following http://www.gooze.eu/howto/smartcard-quickstarter-guide/opensc-installation-under-gnu-linux everything went fine, but when I wanted to run the pkcs11-tool: pkcs11-tool --module /home/anna/PKCS11_Project/libPkcs11.so -l -O I got segmentation fault. I was able to find the place where the code crashed. In pkcs11-tool.c the line (558): rv = p11-C_Initialize(NULL); Sounds like p11 == NULL, or p11-C_Initialize is NULL or not valid. It should point at your C_Initialize routine. Can you run this under gdb? seem to crash. The message is just Segmentation fault The module loads apparently fine. module = C_LoadModule(opt_module, p11); //no error here The problem is, that in my pkcs11 library I put an error message at the very beginning of the C_Initialize function, but not even this is printed out. So I don't think the crash comes from my library. I turned on the creation of a log file in my pkcs11 library, but not even my pkcs11 library log file is created. Did you define a C_GetFunctionList in the module? You must make sure the you module is linked as a module and not just a shared library, so that functions returned by C_GetFunctionList points at the functions in your module, and not ones that may be defined by the caller. Have a look at the pkcs11-spy too which is a PKCS#11 module that loads a second PKCS#11 module. I tried to google this problem and found this old thread: http://www.opensc-project.org/pipermail/opensc-devel/2003-April/000831.html But it didn't really help me (rebuilding openssl didn't solve the problem..). Could anyone help? Thanks for any help, Anna ___ opensc-devel mailing list opensc-devel@lists.opensc-project.org http://www.opensc-project.org/mailman/listinfo/opensc-devel -- Douglas E. Engert deeng...@anl.gov Argonne National Laboratory 9700 South Cass Avenue Argonne, Illinois 60439 (630) 252-5444 ___ opensc-devel mailing list opensc-devel@lists.opensc-project.org http://www.opensc-project.org/mailman/listinfo/opensc-devel ___ opensc-devel mailing list opensc-devel@lists.opensc-project.org http://www.opensc-project.org/mailman/listinfo/opensc-devel
Re: [opensc-devel] Segmentation fault in pkcs11-tool
Anna, greetings -- On Mon, Dec 17, 2012 at 10:37 AM, Anna Pavlova funny.sweet.naug...@gmail.com wrote: Unfortunately I'm not very good in gdb :-( anna@anna:~/OpenSC/src/tools$ export LD_LIBRARY_PATH=`ls ../*/.libs -d | tr '\012' :` anna@anna:~/OpenSC/src/tools$ cd .libs/ anna@anna:~/OpenSC/src/tools/. libs$ gdb 'pkcs11-tool --module /home/anna/PKCS11_Project/libPkcs11.so' the last command returns: pkcs11-tool --module /home/anna/PKCS11_Project/libPkcs11.so: No such file or directory. Of course, when I run only: anna@anna:~/OpenSC/src/tools/.libs$ gdb pkcs11-tool that one runs and I can run in debug mode, but I'm afraid that then I'm not loading my module. Do you know how can I run gdb and also use my own library? Sorry, I'm not really used to work with gdb :-( What should work is: 1. start gdb with just the executable name: $ gdb pkcs11-tool 2. Use the run command to start your program with the desired arguments. (gdb) run --module /home/anna/PKCS11_Project/libPkcs11.so More info: http://sourceware.org/gdb/current/onlinedocs/gdb/Starting.html#Starting Example: $ gdb /bin/echo GNU gdb (GDB) Fedora (7.4.50.20120120-52.fc17) Copyright (C) 2012 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type show copying and show warranty for details. This GDB was configured as x86_64-redhat-linux-gnu. For bug reporting instructions, please see: http://www.gnu.org/software/gdb/bugs/... Reading symbols from /usr/bin/echo...(no debugging symbols found)...done. Missing separate debuginfos, use: debuginfo-install coreutils-8.15-8.fc17.x86_64 (gdb) run foo bar baz Starting program: /usr/bin/echo foo bar baz foo bar baz [Inferior 1 (process 9980) exited normally] (gdb) Hope this helps. Best regards, Anthony Foiani ___ opensc-devel mailing list opensc-devel@lists.opensc-project.org http://www.opensc-project.org/mailman/listinfo/opensc-devel
Re: [opensc-devel] Segmentation fault in pkcs11-tool
On 12/17/2012 11:37 AM, Anna Pavlova wrote: Hello Douglas, Sounds like p11 == NULL, or p11-C_Initialize is NULL or not valid. I did: printf(p11 = 0x%0x, p11-C_Initialize = 0x%0x\n, p11, p11-C_Initialize); in pkcs11-tool.c, just after C_LoadModule and before p11-C_Initialize(NULL) and got: p11 = 0xb7214060, p11-C_Initialize = 0x5810b6fa OK, but is 0x5810b6fa in your module? What version of OpenSC are you running? On what OS? so it is not null. Can you run this under gdb? Unfortunately I'm not very good in gdb :-( anna@anna:~/OpenSC/src/tools$ export LD_LIBRARY_PATH=`ls ../*/.libs -d | tr '\012' :` anna@anna:~/OpenSC/src/tools$ cd .libs/ anna@anna:~/OpenSC/src/tools/. libs$ gdb 'pkcs11-tool --module /home/anna/PKCS11_Project/libPkcs11.so' the last command returns: pkcs11-tool --module /home/anna/PKCS11_Project/libPkcs11.so: No such file or directory. One way is to use the --args gdb --args pkcs11-tool --module /home/anna/PKCS11_Project/libPkcs11.so -l -O break pkcs11-tool.c:558 run If it crashes, It should show a back trace. If it does not then to print out the p11 structure: p *p11 I will ask again, does your module define the C_GetFunctionList, and does it return a valid function list? How did you link it? Of course, when I run only: anna@anna:~/OpenSC/src/tools/.libs$ gdb pkcs11-tool that one runs and I can run in debug mode, but I'm afraid that then I'm not loading my module. Do you know how can I run gdb and also use my own library? Sorry, I'm not really used to work with gdb :-( Did you define a C_GetFunctionList in the module? Yes I did. In fact when I printed out in pkcs11-tool.c printf(%d \n,p11-version.major); printf(%d \n,p11-version.minor); it printed out the correct values. This is also the only thing that I can call with p11. But yes, C_GetFunctionList is defined in my library. You must make sure the you module is linked as a module and not just a shared library, so that functions returned by C_GetFunctionList points at the functions in your module, and not ones that may be defined by the caller. This is an interesting point, thank you. Actually no, I have built and linked it just like a shared library. I thought what's written as 'module' in the code and 'shared library' are the same things. Thanks, Anna On Mon, Dec 17, 2012 at 4:18 PM, Douglas E. Engert deeng...@anl.gov mailto:deeng...@anl.gov wrote: On 12/17/2012 7:01 AM, Anna Pavlova wrote: Hello, I am new to OpenSC but I was looking for a 3rd party tool with which I could test my self-developed pkcs11 library and I came across the OpenSC pkcs11-tool. I installed OpenSC under Ubuntu11.10, following http://www.gooze.eu/howto/smartcard-quickstarter-guide/opensc-installation-under-gnu-linux everything went fine, but when I wanted to run the pkcs11-tool: pkcs11-tool --module /home/anna/PKCS11_Project/libPkcs11.so -l -O I got segmentation fault. I was able to find the place where the code crashed. In pkcs11-tool.c the line (558): rv = p11-C_Initialize(NULL); Sounds like p11 == NULL, or p11-C_Initialize is NULL or not valid. It should point at your C_Initialize routine. Can you run this under gdb? seem to crash. The message is just Segmentation fault The module loads apparently fine. module = C_LoadModule(opt_module, p11); //no error here The problem is, that in my pkcs11 library I put an error message at the very beginning of the C_Initialize function, but not even this is printed out. So I don't think the crash comes from my library. I turned on the creation of a log file in my pkcs11 library, but not even my pkcs11 library log file is created. Did you define a C_GetFunctionList in the module? You must make sure the you module is linked as a module and not just a shared library, so that functions returned by C_GetFunctionList points at the functions in your module, and not ones that may be defined by the caller. Have a look at the pkcs11-spy too which is a PKCS#11 module that loads a second PKCS#11 module. I tried to google this problem and found this old thread: http://www.opensc-project.org/pipermail/opensc-devel/2003-April/000831.html But it didn't really help me (rebuilding openssl didn't solve the problem..). Could anyone help? Thanks for any help, Anna ___ opensc-devel mailing list opensc-devel@lists.opensc-project.org mailto:opensc-devel@lists.opensc-project.org http://www.opensc-project.org/mailman/listinfo/opensc-devel -- Douglas E. Engert deeng...@anl.gov mailto:deeng...@anl.gov