Skip to contentSkip to conversation

nfc: llcp: fix WKS SAP hijacking via prefix match in nfc_llcp_wks_sap()

PATCH New Ömer Mete Kaya 1 participant 1 message Sep 9

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nfc: llcp: fix WKS SAP hijacking via prefix match in nfc_llcp_wks_sap()

nfc_llcp_wks_sap() compares only service_name_len bytes, so a short service_name like "u" matches longer WKS strings like "urn:nfc:sn:snep". Fix by requiring exact length match before strncmp().

Fixes d646960f7986 ("NFC: Initial LLCP support")
---
 net/nfc/llcp_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/nfc/llcp_core.c +2 -1
index fda236e4d9fd..5025d8bdfc36 100644
@@ -352,7 +352,8 @@ static int nfc_llcp_wks_sap(const char *service_name, size_t service_name_len)
 		if (wks[sap] == NULL)
 			continue;
 
-		if (strncmp(wks[sap], service_name, service_name_len) == 0)
+		if (strlen(wks[sap]) == service_name_len &&
+		    !strncmp(wks[sap], service_name, service_name_len))
 			return sap;
 	}
 
Signature · 1 line
2.55.0