From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796382827; b=kx3wvEsgko+lVkoIa6qImEaFvgV7WRdRKvE50eyGL0BrIGd98FLKJh9FBtacRXteoSrD hTPSb/BSQBRb4cISIMQ0iLHBM+NwClGfhawkZyZ5bz1aZlJ+aQk9pKEdn/XUcy2vYZLxQ /za3CLvAYbyEuajZ6sgaZZUrijWE3N8UPXWqNZwRJ6/ls/Uak+2fW/Ckcmlu4sTCyEVYY 5zKcvjvpnSFHLF7ln7WwtdQv/QXYC4kUXMIs1oU9mIujKBNpcpDEsiGLYWBpFrtE9MR7j U63+aH+lncW7GbC7JTMt0f1uASDgRSecqQxWjtzOURQpUmYVXPmIZmvSaSOuD7Fz1ew== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382827; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:Received:From:To:Cc:Subject:Date: Message-ID:MIME-Version:Content-Transfer-Encoding:X-Scanned-By; bh=u6DizgwPZoAWAF5siX6R5uIRgCWSCyi9posbfvAJhok=; b=TQxg/mKhCOvls3VToSkLhAlHlgOX/hkOQ4R+sWqz0oP8QKCXt+TA3OUxeRqFGoeWAvky +GndMIXXsQXbawur67wFc1BwTiCth/uNRr4N8MXkfrjpb2SX52Nk5HHHZQqO9EA2YlGYO El3nDWqkC8XNSCwO9m0j8YgRW1vjjUYu0rSirDxbKJaDQwULr+ZbfxyZ1/ulWGEkvngwm NjFAAHE5oWMCF5fIotpg3+w6ouCXYDvj47aqk0/F1Qg1hsh1ObtSwkFLM7ZACX1KAone4 jJKldPZAWGaNLHbKOYI3dZTz0SSHXNlRJDzacgzTwe4qDGg5mVI6L++glkhdjeve12Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=MHmKwtM3; arc=none smtp.remote-ip=170.10.129.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 36948606A685 for ; Fri, 4 Dec 2026 11:13:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 36948606A685 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=MHmKwtM3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796382824; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=u6DizgwPZoAWAF5siX6R5uIRgCWSCyi9posbfvAJhok=; b=MHmKwtM3YBqwQ5jhuAuXil0Oft03jbaHdkLFUUEKzRFLJUE03RDYtAAzFjdrbnvu/CJ84k d9hp/OtCUtkLowKTY/xcboi5VKBVhYKmuGJ90X6KtS7q3380yn49pooX1UraPF5nN6Wvpq s4Xb0SkenpxY/2B0Cl7xfsHx5ZVuHCY= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-509-8lvxFStTPBy4bHdiA_aDbg-1; Fri, 4 Dec 2026 11:13:39 +0000 X-MC-Unique: 8lvxFStTPBy4bHdiA_aDbg-1 X-Mimecast-MFC-AGG-ID: 8lvxFStTPBy4bHdiA_aDbg_1796382818 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8B14818B5F8F; Fri, 4 Dec 2026 11:13:37 +0000 (UTC) Received: from ivecera-thinkpadp16vgen1.tpbc.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 39FC9180192F; Fri, 4 Dec 2026 11:13:35 +0000 (UTC) From: Ivan Vecera To: netdev@vger.kernel.org Cc: Min Li , Vadim Fedorenko , Arkadiusz Kubalewski , Jiri Pirko , Jakub Kicinski , Przemek Kitszel Subject: [PATCH net] dpll: zl3073x: fix parsing of the end of firmware file Date: Fri, 4 Dec 2026 12:13:31 +0100 Message-ID: <20261204111331.380897-1-ivecera@redhat.com> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 zl3073x_fw_component_load() copies the input into a local buffer with strscpy(buf, *psrc, min(sizeof(buf), *psize)). strscpy() needs room for the NUL terminator within the given size, so the last byte of the firmware file is never parsed. If the file does not end with whitespace, the last data word loses its last hex digit and the wrong value is written to the device flash without any error. The end of input is also misdetected. It is recognized only when the header sscanf() returns 0, but the kernel vsscanf() counts an empty %s match on whitespace-only input. Longer runs of whitespace, e.g. 25 or more bytes after the last data word, are then rejected as "invalid component size". Add a helper that skips whitespace in the input and copies the following bytes including the last one, and use it for both the component header and the data words. Discovered by an AI code review agent (Sashiko), not observed with real firmware files. Confirmed without kernel modifications by building the parser from fw.c with the kernel vsscanf() as a userspace test: the input "utility 1\nDEADBEEF" without a trailing newline loads the word as 0x0DEADBEE, and 25 newlines after it fail the load with -EINVAL. With the fix, the test parses both inputs and 300000 random files with varying whitespace correctly, without ASan or UBSan reports. Not tested on hardware. Fixes: ca017409da69 ("dpll: zl3073x: Add firmware loading functionality") Signed-off-by: Ivan Vecera --- drivers/dpll/zl3073x/fw.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/drivers/dpll/zl3073x/fw.c b/drivers/dpll/zl3073x/fw.c index 3acbb33ed7b8d0..fb77f6811f25ad 100644 --- a/drivers/dpll/zl3073x/fw.c +++ b/drivers/dpll/zl3073x/fw.c @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -176,6 +177,34 @@ zl3073x_fw_component_id_get(const char *name) return ZL_FW_COMPONENT_INVALID; } +/** + * zl3073x_fw_input_get - Get the beginning of the remaining input + * @buf: buffer to store the input to + * @len: size of @buf + * @psrc: data pointer to the remaining input + * @psize: remaining bytes in input + * + * The function skips whitespace in the input and copies up to @len - 1 + * following bytes into @buf and NUL-terminates it. The input does not have + * to be NUL-terminated, so its last byte is copied as well. Source data + * pointer @psrc and remaining bytes @psize are moved past the skipped + * whitespace. + */ +static void +zl3073x_fw_input_get(char *buf, size_t len, const char **psrc, size_t *psize) +{ + size_t n; + + while (*psize && isspace(**psrc)) { + (*psrc)++; + (*psize)--; + } + + n = min(len - 1, *psize); + memcpy(buf, *psrc, n); + buf[n] = '\0'; +} + /** * zl3073x_fw_component_load - Load component from firmware source * @zldev: zl3073x device structure @@ -209,7 +238,7 @@ zl3073x_fw_component_load(struct zl3073x_dev *zldev, int pos, rc; /* Fetch image name and size from input */ - strscpy(buf, *psrc, min(sizeof(buf), *psize)); + zl3073x_fw_input_get(buf, sizeof(buf), psrc, psize); rc = sscanf(buf, "%15s %u %n", name, &count, &pos); if (!rc) { /* No more data */ @@ -252,7 +281,7 @@ zl3073x_fw_component_load(struct zl3073x_dev *zldev, /* Load component data from firmware source */ for (dest = comp->data; count; count--, dest++) { - strscpy(buf, *psrc, min(sizeof(buf), *psize)); + zl3073x_fw_input_get(buf, sizeof(buf), psrc, psize); rc = sscanf(buf, "%x %n", dest, &pos); if (!rc) goto err_data; base-commit: 007722b8211f7b34fdf21b1e6a9c32497633ea29 -- 2.56.1