From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796389404; b=lIzFiQzRF/CfibJR2DysRPj3cf0ce10dSWmO0kQYVkk5r1Cfif36cmVU+Cf22HlRuKM5 GUV8a6XsWb+WTjOZ+MV3DBe5N8d7VEE1A4NaVDSZn7mA8GtkC6DKDKgJOYmFaAkto3Sfj LmsPhUTs+LuSUxoz1TXgR4NpRs6+PfP9Vu4dEAHftNiTF0LCuzsU9Mx1tmUeHS3p9LTF/ mBNA0aOCB/IklDoDyzwFKFFGl7fDkHlraHjZNdMzkS9yWc0yvRw3G1EycZWs/hQNuBL59 Y7WGaoF+QGraPn2kUfMhlQuiKSJ5puEoAEha+DdBTexCzht6jlMWNwZZx8HgRFwi9rw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796389404; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=9DAGNOCSjdgivCPC0twQmDkjVQM/sIZAcg+42QBAr/4=; b=B1VI4hWl1M/2rVmccVScOQvYYMxqdvKEHUt2BL70LHz4dCE6/7u332rVLHanx4KAWWxt 22osd+2DVpC208rUHZoIC1riV1+057nMIhBlAPcrK3StibUiwt0T+Sr2fOKHr2w5Yk5Hg +pZHE4Tc4ymdz0WcBhgwRZQMEvAU3LTnImvJVSylSsO4PvdgSM2wkdRVNOYvB5rxONeAg yJUUwZRDr5RDTJXrnCMoSkEi4b+NKxZ5qgQc7/mnDwcyD8CDG5WYXafayWmCgPutbbyJQ Ir+l8jOj+5G0Dejg2HGCGkmZJ9Mp7f0idyEABSzR7UsuUGt9P/llEMFy5j/LuUE/PDQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=yRYkhcOp; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A8AEB606A32D; Fri, 4 Dec 2026 13:03:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=yRYkhcOp Received: by smtp.kernel.org (Postfix) with ESMTPSA id B19DB1F0092C; Fri, 4 Dec 2026 13:03:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796389404; bh=9DAGNOCSjdgivCPC0twQmDkjVQM/sIZAcg+42QBAr/4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=yRYkhcOpPbV8W3+6QVDsmPNfEqFScJFYXu1lzyA1APfl/FD6ZnCVhZVMIcMEc+z+J vkzqDJUdKUvP21nd4Z8bkTyCIfl37EGp3qHeASWvALOsnLtzDNWP+TLv52vnH+3xaM sYJt4LPcS/2ju9dJSKMPDjyn/jt6CxMMes1xORW0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Lianjie Wang , Viresh Kumar , Bartosz Golaszewski Subject: [PATCH 6.1 0938/1059] gpio: virtio: bound the line names block by its configured size Date: Fri, 4 Dec 2026 19:07:49 +0900 Message-ID: <20261204100708.320754466@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Lianjie Wang commit 74aee8e06277df39ec10ed043bae0ed5b7a83864 upstream. virtio_gpio_get_names() walks the line names that the device returns in a block of gpio_names_size bytes, which the driver ends with a NUL, and checks each name only after stepping past it. If the block holds fewer than ngpio names, the walk reaches the end of the block after the last name, and the next iteration starts strlen() at the byte after the allocation. With a block that holds one name for four lines, KASAN reports: BUG: KASAN: slab-out-of-bounds in strlen+0x57/0x70 Read of size 1 at addr ffff8880026687c0 by task swapper/0/1 Call Trace: strlen+0x57/0x70 virtio_gpio_probe+0xcb4/0xfc0 virtio_dev_probe+0xa7a/0xc50 Allocated by task 1: devm_kmalloc+0x6e/0x280 virtio_gpio_probe+0xc06/0xfc0 The buggy address is located 0 bytes to the right of allocated 64-byte region [ffff888002668780, ffff8880026687c0) Check that a name starts inside the block before reading it. Fixes: 3a29355a22c0 ("gpio: Add virtio-gpio driver") Cc: stable@vger.kernel.org Signed-off-by: Lianjie Wang Acked-by: Viresh Kumar Link: https://patch.msgid.link/20261104195632.1702765-1-lian@is.s.u-tokyo.ac.jp Signed-off-by: Bartosz Golaszewski Signed-off-by: Greg Kroah-Hartman --- drivers/gpio/gpio-virtio.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/drivers/gpio/gpio-virtio.c +++ b/drivers/gpio/gpio-virtio.c @@ -525,13 +525,13 @@ static const char **virtio_gpio_get_name gpio_names[gpio_names_size - 1] = '\0'; for (i = 0, str = gpio_names; i < ngpio; i++) { - names[i] = str; - str += strlen(str) + 1; /* zero-length strings are allowed */ - - if (str > gpio_names + gpio_names_size) { + if (str >= gpio_names + gpio_names_size) { dev_err(dev, "gpio_names block is too short (%d)\n", i); return NULL; } + + names[i] = str; + str += strlen(str) + 1; /* zero-length strings are allowed */ } return names;