Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IASECC: error when getting access to 2F00 #2231

Closed
vjardin opened this issue Feb 10, 2021 · 9 comments
Closed

IASECC: error when getting access to 2F00 #2231

vjardin opened this issue Feb 10, 2021 · 9 comments

Comments

@vjardin
Copy link
Contributor

vjardin commented Feb 10, 2021

Problem Description

From time to time, openSC fails with the APDU sequence:

      00000200 [139681798813440] APDU: 00 A4 09 04 02 2F 00
      00029790 [139681798813440] SW: 6A 82

In order to reproduce this issue, I need to dump all the objects of a CPX card using C_GetAttributeValue(). Then, on some objects, I get an error because we get the SW 6A 82.

vjardin added a commit to vjardin/OpenSC that referenced this issue Feb 10, 2021
Few years ago, the commit 0362844
did squash the 3F00nnnn path to nnnn. For instance, 3F002F00
becomes 2F00. It is an issue such as:
  00000200 [139681798813440] APDU: 00 A4 09 04 02 2F 00
  00029790 [139681798813440] SW: 6A 82

Fix: issue OpenSC#2231
@vjardin
Copy link
Contributor Author

vjardin commented Feb 10, 2021

The current patch does not revert the memmove() since it seems to be required for some cards ; but it skips it only for the CPX cards.

@vjardin
Copy link
Contributor Author

vjardin commented Feb 11, 2021

For the records, CVE-2018-16426 https://vuldb.com/?id.123550

vjardin added a commit to vjardin/OpenSC that referenced this issue Feb 13, 2021
Few years ago, the commit 0362844
did squash the 3F00nnnn path to nnnn. For instance, 3F002F00
becomes 2F00. It is an issue such as:
  00000200 [139681798813440] APDU: 00 A4 09 04 02 2F 00
  00029790 [139681798813440] SW: 6A 82

Fix: issue OpenSC#2231
vjardin added a commit to vjardin/OpenSC that referenced this issue Feb 14, 2021
Few years ago, the commit 0362844
did squash the 3F00nnnn path to nnnn. For instance, 3F002F00
becomes 2F00. It is an issue such as:
  00000200 [139681798813440] APDU: 00 A4 09 04 02 2F 00
  00029790 [139681798813440] SW: 6A 82

Fix: issue OpenSC#2231
@frankmorgner
Copy link
Member

what does it mean to fail from time to time? can you reliably reproduce this, is this related to a specific object? If not, this may be due to path caching. If so, path caching should be disabled instead...

@vjardin
Copy link
Contributor Author

vjardin commented Feb 23, 2021

I tried both with and without cache, I faced the same issue. "from time to time" means that over a long sequence of APDUs including this command, I do not have the return'd values 6A 82. If 3F00 is not removed, then, it always work for any sequence.

@frankmorgner
Copy link
Member

So can you reproduce the result reliably by issuing the same long sequence of commands, or not?

please note that with cache, I mean card->cache, which cannot be disabled by the configuration file. it is not related to the file cache from opensc.conf

@vjardin
Copy link
Contributor Author

vjardin commented Feb 24, 2021

I'll check this card->cache, I did only disable the cache from the configuration file.

@frankmorgner
Copy link
Member

card->cache remembers which path has been selected previously to avoid unnecessary commands. If some other process accesses the card while it is unlocked, this path may get invalidated without being noticed. That's why, I think, the concept of keeping card->cache is a misconception in a concurrent environment... Unfortunately I never had the time to go for a generic fix, but you may need to disable it here for your card to avoid these kinds of problems.

@frankmorgner
Copy link
Member

frankmorgner commented Feb 25, 2021

If concurrency is the reason for your problems while selecting the path, you can also lock the card once you start the selection process:

  1. lock the card
  2. select MF (3F00)
  3. select the rest of the path (path - 3F00)
  4. unlock the card

This avoids being interrupted by a different process. You need to take care to catch all error cases to correctly unlock the card.

vjardin added a commit to vjardin/OpenSC that referenced this issue Mar 4, 2021
Few years ago, the commit 0362844
did squash the 3F00nnnn path to nnnn. For instance, 3F002F00
becomes 2F00. It is an issue such as:
  00000200 [139681798813440] APDU: 00 A4 09 04 02 2F 00
  00029790 [139681798813440] SW: 6A 82

Fix: issue OpenSC#2231
vjardin added a commit to vjardin/OpenSC that referenced this issue Mar 5, 2021
Few years ago, the commit 0362844
did squash the 3F00nnnn path to nnnn. For instance, 3F002F00
becomes 2F00. It is an issue such as:
  00000200 [139681798813440] APDU: 00 A4 09 04 02 2F 00
  00029790 [139681798813440] SW: 6A 82

Fix: issue OpenSC#2231
vjardin added a commit to vjardin/OpenSC that referenced this issue Mar 9, 2021
Few years ago, the commit 0362844
did squash the 3F00nnnn path to nnnn. For instance, 3F002F00
becomes 2F00. It is an issue such as:
  00000200 [139681798813440] APDU: 00 A4 09 04 02 2F 00
  00029790 [139681798813440] SW: 6A 82

Fix: issue OpenSC#2231
vjardin added a commit to vjardin/OpenSC that referenced this issue Mar 16, 2021
Few years ago, the commit 0362844
did squash the 3F00nnnn path to nnnn. For instance, 3F002F00
becomes 2F00. It is an issue such as:
  00000200 [139681798813440] APDU: 00 A4 09 04 02 2F 00
  00029790 [139681798813440] SW: 6A 82

Fix: issue OpenSC#2231
frankmorgner pushed a commit that referenced this issue Mar 17, 2021
Few years ago, the commit 0362844
did squash the 3F00nnnn path to nnnn. For instance, 3F002F00
becomes 2F00. It is an issue such as:
  00000200 [139681798813440] APDU: 00 A4 09 04 02 2F 00
  00029790 [139681798813440] SW: 6A 82

Fix: issue #2231
@vjardin
Copy link
Contributor Author

vjardin commented Mar 17, 2021

merged => fixed.

@vjardin vjardin closed this as completed Mar 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants