Skip to content

net/nfc: fix skb ownership and NCI status errors

Bin Luo (University of Electronic Science and Technology of China) netdev oe-linux-nfc stable 3 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest2 patches 0 repliesNew
  2. v21 patch 1 replySuperseded
  3. v11 patch 0 repliesSuperseded

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2net/nfc: fix skb ownership on data exchange errorsdrivers/nfc/microread/microread.c drivers/nfc/pn533/pn533.c drivers/nfc/pn544/pn544.c +10 more+52 -420 replies
2/2nfc: preserve NCI data status error codesnet/nfc/nci/data.c+2 -40 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v3 yet.

Read the v3 thread

Cover letter [PATCH v3 0/2] net/nfc: fix skb ownership and NCI status errors

Hi,

This series addresses the review feedback on the v2 NFC callback-ownership fix.

The issue was found by source inspection during a callback-ownership audit. The NCI receive path can pass a non-NULL skb together with an error to a data_exchange_cb_t callback. The audit found consumers and wrapper callbacks that returned or freed only on success, leaving the response skb unconsumed. It also found terminal Digital DEP error paths that freed exchange state without completing the callback, and an NCI status conversion that truncated negative errno values through __u8.

Both the baseline and v3 x86_64 kernels were fully built with NFC, Digital, NCI, HCI/SHDLC, NFC-SIM, virtual NCI, PN533, PN544, Microread, ST21NFCA, KASAN, and kmemleak enabled. All three full build logs contain no warning or error lines.

The QEMU TCG test ran 32 NCI 1.0 MIFARE exchanges with status 0x01. The harness provisioned the virtual controller and polling session, then ran AF_NFC operations with effective UID 65534. The baseline returned SO_ERROR=-240 instead of 16 and kmemleak reported 47 unreferenced objects. The v3 kernel returned SO_ERROR=16, reported no unreferenced objects, and produced no KASAN report.

A test-only KUnit overlay, not included in this series, ran ten callback tests covering Digital DEP completion, ST21NFCA callbacks, LLCP error release, NCI loopback and NCI-HCI errors, four HCI wrapper branches, and PN533 response aggregation with an injected allocation failure. All ten passed. Real NFC controller hardware was not exercised.

The final QEMU run used one vCPU. A two-vCPU KASAN boot hit an early enqueue_task_fair int3 before userspace; it did not reach the NFC tests.

Patch 1 documents the callback ownership contract and updates the affected consumers and providers, including terminal Digital DEP completion and fragment cleanup. Patch 2 keeps NCI data-status errno values signed.

Best regards,
Bin Luo

Bin Luo (University of Electronic Science and Technology of China) (2):
net/nfc: fix skb ownership on data exchange errors
nfc: preserve NCI data status error codes

 drivers/nfc/microread/microread.c |  3 +--
 drivers/nfc/pn533/pn533.c         |  1 +
 drivers/nfc/pn544/pn544.c         |  3 +--
 drivers/nfc/st21nfca/core.c       |  3 +--
 drivers/nfc/st21nfca/dep.c        | 26 ++++++++++++-------------
 include/net/nfc/nfc.h             |  5 ++++-
 net/nfc/digital_dep.c             | 32 ++++++++++++++-----------------
 net/nfc/hci/core.c                |  5 +++--
 net/nfc/llcp_core.c               |  4 +++-
 net/nfc/nci/core.c                |  1 +
 net/nfc/nci/data.c                |  8 ++++----
 net/nfc/nci/hci.c                 |  4 ++++
 net/nfc/rawsock.c                 |  5 ++++-
 13 files changed, 54 insertions(+), 46 deletions(-)

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4