Problem Description:
When trying to add a new Security Device, I am instructed to load a new PKCS#11 Device Driver. But when I enter the full path /usr/lib/x86_64-linux-gnu/opensc-pkcs11.so, an alert says “Unable to add module” and I see this on dmesg:
After digging through Launchpad #1967632 and the older Mozilla/OpenSC discussions, this looks much closer to a Firefox Snap confinement issue than an OpenSC problem.
The AppArmor denial is occurring during the file_mmap stage while Firefox is trying to load the PKCS#11 module, and the fact that the path gets rewritten under /run/user/1000/doc/... is particularly interesting because that is exactly the behavior that has caused trouble in previous reports.
One thing I would verify is whether the module was added through the file picker or entered manually.
The Firefox maintainers explicitly noted that the file picker can interfere with PKCS#11 module loading and recommended typing the path directly instead. Given that your reader works from the CLI, pcscd is connected, and OpenSC itself appears functional, I would lean toward either a regression in the Snap/AppArmor policy or another edge case involving the document portal path translation rather than a problem with the smart card stack itself. The symptoms line up very closely with the long-running PKCS#11 loading issues that have been tracked in Launchpad for several releases now
The pcscdinterface does not grant you any access to /usr/lib/x86_64-linux-gnu/opensc-pkcs11.so it only gives access to the pcscd daemon socket and the opensc config file in /etc
If you look inside the snapcraft.yaml (in /snap/firefox/current/snap/) you will find a layout entry (as discussed in the conversation I linked above) that maps /usr/lib/x86_64-linux-gnu/opensc-pkcs11.so to $SNAP/usr/lib/x86_64-linux-gnu/opensc-pkcs11.so:
so this points to /snap/firefox/current/usr/lib/x86_64-linux-gnu/pkcs11/opensc-pkcs11.so
With that setup there is no way to make firefox use an outside lib here unless you would do some bad (and insecure) hack like bind mounting your opensc-pkcs11.so on top of the one that is shipped in the snap which indeed introduces a security hole into the snap confinement …
EDIT: IF Firefox allows you to actually freely specify a path here, you should copy the lib into ~/snap/firefox/common/and use this as a path to point to …
I would add one small test to the bug report: try the same module path from a non-snap Firefox build, just to separate the smart-card/OpenSC side from the snap confinement side. If that works, the important detail is probably the /run/user/1000/doc/… rewrite and file_mmap denial, not pcscd. Also worth noting whether the path was typed manually or selected through the file picker, because that changes how the document portal gets involved.