Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 391C3378833 for ; Mon, 22 Jun 2026 10:57:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782125877; cv=none; b=MsKWW4byGzkfVP8COlVJynk8xq89LBlkJNYjiHliVGR+ab0K+cBRiUDuHvlx0vqzveyEDq2mxz089eXo6QLOv5qRAjbM41fHuIPhlq8c+pM1J/0u6jMJdhb6AwBWMBNXbI9OP7492A1kfmQNoM4LNJ0W38PrR59IF6XuLH7x3tU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782125877; c=relaxed/simple; bh=X5gorfuJPDZFOymAJv3msHD9nN7rpuhw51e3DJt02mw=; h=From:To:Subject:Date:Message-ID:Content-Type:MIME-Version; b=ljSmzmpGknUxl0KQqx7v5WhYfyVe56vTvYYYoMFs48XZxFUOI2YnJ4Kuv/5u3xqH6Z31baHH3LqpF632TUSnwLyia/2NFk2gT8LBBoiwEPM8AIpQG52r8VVhoSw3UJWVLSljfcSpLBQgNPjOaAfuZjwFQ1muErQFbR1WbPpnAKo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=digiscrypt.com; spf=pass smtp.mailfrom=digiscrypt.com; dkim=pass (2048-bit key) header.d=digiscrypt.com header.i=@digiscrypt.com header.b=A3Q7CVOX; arc=none smtp.client-ip=209.85.210.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=digiscrypt.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=digiscrypt.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=digiscrypt.com header.i=@digiscrypt.com header.b="A3Q7CVOX" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-842307472d4so1718485b3a.0 for ; Mon, 22 Jun 2026 03:57:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=digiscrypt.com; s=google; t=1782125875; x=1782730675; darn=vger.kernel.org; h=mime-version:content-transfer-encoding:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=91AFZocYyUsmEdH6tfTO+7fcSu1TprYkXySfRLDvDaA=; b=A3Q7CVOXqbtD6EyyKgsEFLwozDDyHvtUSAe/CTmIjsyV+GdzA5ERmCvCjK+FVtdBDQ QZyUTbqvQtMBbIFllt/LjR9WNsrtP22avcq3B9GolLZ8ldjfi8bIuCuKGxKDH/Std0wW 3pAvwFXjn8K7aLuVMLN9PpbVCAsrMdfurIHrA+Brmh0Bg8mGeqnTZp3SEDrBk2F3mDoZ 73lzUSRibaJQHBSxD+bZEqF9+PnsF1zrFnZnbpU4whYiUIzgZRrea0oibye8B64NPiiY TQSB683CXYe0F+wwbE6xpFpCsvInSCGk9T97dYY9iHzO29TJ0QCUhPoEBtZIV9y53OPW LHiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782125875; x=1782730675; h=mime-version:content-transfer-encoding:message-id:date:subject:to :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=91AFZocYyUsmEdH6tfTO+7fcSu1TprYkXySfRLDvDaA=; b=H/KU+5jAhssGrOF1HSC7ZUmT/+cjTF7SDQU1n3miBeH9UFCNrEpY1zRGLQ89T5e1Xz hZ4RqUcsIZc0A5VSLoDCx5hIqcmvH4SaAWxen+RRaZEExxYhE2HjD4w5KVmvBkh/npdA cjxGG/QCics9q9trAB8NPq4HmRjNuWifexRtE1ST0FWU0pv/KZ/uOLFnwGJT4wfgKHop +Qu8QqfxNHEpMIzSrITR14KG9+u0X1wqpGIaUuJ2tT0DPeg6M+R3I6GGg5P7/8MRASBa +qAbHD0jWiYdZ8atIvfX6TEQjHCtw3Ck9OtzOYeXflo7wccJqagzsJQN9y8z5kOJEaXv uoLA== X-Gm-Message-State: AOJu0YyIlqi9QnhWzfjcrPFDbbBudmESddqiyJjQDmpbL4DpoCRRMXO1 kxdTdMm97/lWyi0fbpMBS2eb4C34mR8NQLaD+llGBzEogtXcNLGGnFZ0l/KlcH5p/Ekb8RnRnL2 iYgfleIGAtV8= X-Gm-Gg: AfdE7cnomkygo0FfQgge4CvBkcwKHd4me+yUX/KseuvEI/gTHXNZ1pAYPxRc+5lM+Kg lsw+4/1hAj8NCh4vACBxyTdnBNYJJ4s/cVUAnefIbzhC44Ng3k57rpdLcwGF9kUp56yF3Q0SJLM se6mfJMw9ojdcmonxIoJU6l8vxwJFh3tqfjdto0EbG3Q+enJ/izFuh+ZVsp3td7zxhhc02MsuxY nXIFVuBwYy9kwkWbqtsgGcsPxXlle+x/Hl0cdPuGj5oX5k26MyZptCdUI+U/M6itB7W2RsNTBRX k1kf2VRCXqLgVqLtemtk2nEVChzAkRvMjbO4IzDRuYP+f+RL9XgjTpRQuKIWDGwq3DUohdt0tgQ z9c0qSTP6pi3ua7CsE030dW8eLACFkjl9Ph3YXRpqVWWg+RqirFsumIBKZkVTjvw6YxOc0SSptg yENyT/ANNY4RlI7cY2xwse0d7o5cY7gDSG2nilZELhlUbDE4UJXuTNrilgkFRz0Eoe3lc= X-Received: by 2002:a05:6a00:2381:b0:835:405a:7e6f with SMTP id d2e1a72fcca58-84562478defmr12630712b3a.14.1782125875363; Mon, 22 Jun 2026 03:57:55 -0700 (PDT) Received: from 3.1.168.192.in-addr.arpa ([2401:4900:1c07:5bb8:c9c3:ff21:7fc5:f37]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84564e76d3csm7158970b3a.30.2026.06.22.03.57.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jun 2026 03:57:54 -0700 (PDT) From: Naveed Khan To: linux-kernel@vger.kernel.org Subject: [PATCH] nfc: llcp: validate TLV bounds when parsing CONNECT service name Date: Mon, 22 Jun 2026 16:27:51 +0530 Message-ID: <178212587161.42169.9788634600316505484@digiscrypt.com> X-CodeOps-Marker: 7032b53c4dac4f7aa87422f9e9fa0223 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 nfc_llcp_connect_sn() walks the TLV array of a received LLCP CONNECT PDU to locate the service name (SN) parameter, but it never checks that a TLV stays within the packet. The two-byte TLV header is read as soon as offset < tlv_array_len, so when only a single byte is left the length byte tlv[1] is read past the end of skb->data. When an SN TLV is found its declared length is stored in *sn_len and a pointer just past the length byte is returned, again without verifying that 'length' value bytes are present. The caller hands the result to nfc_llcp_sock_from_sn(), which does memcmp(sn, service_name, sn_len), reading up to 255 bytes out of bounds. A remote peer can trigger this by sending a CONNECT PDU addressed to the SDP SAP that carries a truncated SN TLV, or a TLV whose declared length exceeds the remaining frame. Make sure two bytes are available before reading the TLV header and that the whole type/length/value triplet fits in the remaining buffer before using or skipping it. tlv_array_len and offset are size_t and offset is only advanced when the TLV fits, so the subtractions cannot wrap. Signed-off-by: Naveed Khan --- diff --git a/net/nfc/llcp_core.c b/net/nfc/llcp_core.c index dc65c719f3..f437d82b3d 100644 --- a/net/nfc/llcp_core.c +++ b/net/nfc/llcp_core.c @@ -853,11 +853,17 @@ static const u8 *nfc_llcp_connect_sn(const struct sk_buff *skb, size_t *sn_len) size_t tlv_array_len = skb->len - LLCP_HEADER_SIZE, offset = 0; while (offset < tlv_array_len) { + if (tlv_array_len - offset < 2) + break; + type = tlv[0]; length = tlv[1]; pr_debug("type 0x%x length %d\n", type, length); + if (tlv_array_len - offset < length + 2U) + break; + if (type == LLCP_TLV_SN) { *sn_len = length; return &tlv[2]; -- 2.52.0