From nobody Sun Jun 14 19:01:52 2026 Received: from cstnet.cn (smtp21.cstnet.cn [159.226.251.21]) (using TLSv1.2 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D40FD3290C5 for ; Sun, 5 Apr 2026 02:15:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.226.251.21 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775355309; cv=none; b=Iu9gHo8ue9fFAlIgOOcyPpbeLhvCmjCMSSuilpJ7aUT0/qelNJkVhPvNge1lhlJqyQS37i12nr2DUGxOBWyRxZU5IZtKJbK4ieHkPvIOQxRdTtlMR4zd+B8xwvjHc5zyfXMpLryknTJua+i0UEqRDy93VqPm0Cp6//IvisjwVG8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775355309; c=relaxed/simple; bh=87MtefAZcE38CbQu3I6ls5k7FQAkfX1M9FAH9oMEFVA=; h=From:Date:Message-ID:To:Cc:In-Reply-To:References:Subject; b=H+KAsGImp/u6YZB19QyvYGPi/RI6MaGEaTQoUhb78pM0+g55gHiAJPK/rG5BKwBCaCiWTZcl+yVz5WNdc15Eyt9BGqLMzn4Bak40UnCKGYv7t6sw0R8wVlxdY7McMSb+AkbT4d81KcfJJbMgAG8mHeGtFVUUISei8NnvrmUhwJ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iscas.ac.cn; spf=pass smtp.mailfrom=iscas.ac.cn; arc=none smtp.client-ip=159.226.251.21 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iscas.ac.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iscas.ac.cn Received: from 0004-arm-mvebu-v2.eml (unknown [111.196.245.197]) by APP-01 (Coremail) with SMTP id qwCowADHa2ehxdFpTAU5DA--.28126S2; Sun, 05 Apr 2026 10:14:57 +0800 (CST) From: Pengpeng Hou Date: Sun, 5 Apr 2026 08:41:00 +0800 Message-ID: <20260405094004.4-arm-mvebu-v2-pengpeng@iscas.ac.cn> To: Andrew Lunn , Gregory Clement , Sebastian Hesselbarth Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, pengpeng@iscas.ac.cn In-Reply-To: <20260403111504.4-dt-arm-mvebu-pengpeng@iscas.ac.cn> References: <20260403111504.4-dt-arm-mvebu-pengpeng@iscas.ac.cn> Subject: [PATCH v2] ARM: mvebu: validate memory node device_type before strcmp() X-CM-TRANSID: qwCowADHa2ehxdFpTAU5DA--.28126S2 X-Coremail-Antispam: 1UD129KBjvJXoW7Kw1kGrW3XFWkuF15Kw43Awb_yoW8Wr4rpF W3C3ZrKr4j9ryxWa4qyF4DZay0kan7JrZakFnxCw129a13X345ZFWfKw1Yq3Z5CrW0ka4F 9r4YqF4UZ3ZrAFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkm14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26ryj6F1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4j 6F4UM28EF7xvwVC2z280aVAFwI0_Cr1j6rxdM28EF7xvwVC2z280aVCY1x0267AKxVWxJr 0_GcWle2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_Jrv_JF1lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJV W8JwACjcxG0xvEwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lc7CjxVAaw2AFwI0_JF0_ Jw1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxV WUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI 7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r 4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI 42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfU5oGQDUUUU X-CM-SenderInfo: pshqw1xhqjqxpvfd2hldfou0/ Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" mvebu_scan_mem() fetches the flat-DT device_type property and immediately compares it with strcmp(). Flat DT properties are external boot input, and this path does not prove that the property is NUL-terminated within the returned property length. Keep the existing flat-DT lookup path, but reject malformed unterminated device_type values before comparing them as C strings. This preserves the current distinction between an absent property and a bad property value. Signed-off-by: Pengpeng Hou --- Changes since v1: - keep `of_get_flat_dt_prop()` instead of switching to `fdt_stringlist_get(= )` - preserve the existing \ufffd\ufffd\ufffdnot found\ufffd\ufffd\ufffd vs ma= lformed-value behavior arch/arm/mach-mvebu/board-v7.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/arm/mach-mvebu/board-v7.c b/arch/arm/mach-mvebu/board-v7.c index a0740ab0..db6543ff 100644 --- a/arch/arm/mach-mvebu/board-v7.c +++ b/arch/arm/mach-mvebu/board-v7.c @@ -66,11 +66,13 @@ void __iomem *mvebu_get_scu_base(void) static int __init mvebu_scan_mem(unsigned long node, const char *uname, int depth, void *data) { - const char *type =3D of_get_flat_dt_prop(node, "device_type", NULL); + const char *type; const __be32 *reg, *endp; - int l; + int len, l; =20 - if (type =3D=3D NULL || strcmp(type, "memory")) + type =3D of_get_flat_dt_prop(node, "device_type", &len); + + if (!type || strnlen(type, len) >=3D len || strcmp(type, "memory")) return 0; =20 reg =3D of_get_flat_dt_prop(node, "linux,usable-memory", &l); --=20 2.50.1