A malicious NFC peer can send a SENSF_RES that is longer than the NFC_SENSF_RES_MAXSIZE (18 byte) sensf_res field in the onstack struct nfc_target. digital_in_recv_sensf_res() validates that the response is at least DIGITAL_SENSF_RES_MIN_LENGTH bytes but applies no upper bound before memcpy(target.sensf_res, sensf_res, resp->len) is called, allowing a stack buffer overflow with attacker-controlled length and content. Commit e329e71013c9 ("NFC: nci: Bounds check struct nfc_target arrays") fixed identical missing checks for the same target->sensf_res field on the NCI path; the Digital Protocol path was never patched. Fix this all up by just rejecting responses that exceed NFC_SENSF_RES_MAXSIZE. Cc: "David S. Miller" Cc: Eric Dumazet Cc: Jakub Kicinski Cc: Paolo Abeni Cc: Simon Horman Cc: Greg Kroah-Hartman Cc: Kees Cook Cc: Thierry Escande Cc: Samuel Ortiz Fixes: 8c0695e4998d ("NFC Digital: Add NFC-F technology support") Cc: stable Assisted-by: gregkh_clanker_t1000 Signed-off-by: Greg Kroah-Hartman --- net/nfc/digital_technology.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/nfc/digital_technology.c b/net/nfc/digital_technology.c index ae63c5eb06fa..e18bdb231352 100644 --- a/net/nfc/digital_technology.c +++ b/net/nfc/digital_technology.c @@ -774,6 +774,11 @@ static void digital_in_recv_sensf_res(struct nfc_digital_dev *ddev, void *arg, skb_pull(resp, 1); + if (resp->len > NFC_SENSF_RES_MAXSIZE) { + rc = -EPROTO; + goto exit; + } + memset(&target, 0, sizeof(struct nfc_target)); sensf_res = (struct digital_sensf_res *)resp->data; -- 2.53.0