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=1796383829; b=YhptB9GH2vXbFZ/R8whR1ED9RebfQSHNvRXRNgg2AG5/+L1O9YNuiI4pnlCpVs/62OnJ EGSm2RLd6k+fXtYRQVhOORQma3PYGxIrlVcrBnWBO6CpRrdzjTGRTtaOcCJETBQUkAaqm 0un44xVX8FGgCRQTcRjfEgi8nrpjlg6rn0R7qLoukky4SqA5mxmJAwDZVHutMpfJMzKXO 7bo0s1xD9A8y/n36As1Oxo0M9g+z77rhYuPgYd2JAqDKmM+D+bsYUTwarAd3hsy0CkSe0 YNUBWWJgOkFOlwyIl1fYlSd45qBJ+6Y5J01LbL9AQH7YCCMX4YeR+x8MyzrxG6q60Lw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383829; 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=JmTsRO8ORmbOvC4vTL/I79OVS/ksqRCifMGZ2tyrYPk=; b=motJMwK2z3kCGLstqRIZ0PDluSPbAMnLMJiVa4FmznfiVo3VTx86gKzwBaof0poXmQZq zbrvMjekBL8M81IwmxNpII/Q6MVa1EeuYwvYgTAYdo4re+LY6inXvV0tAo0H3D6ro7Ozz Uwh1I+0mOBVlFhTxtMvdZGmrRRlJK5L7zZM8t+jQ/wAnrnzdH4bOZGpUpbiGxz+p0Bw41 rrwnIofQJ4/gYAe6BSrvcNY9KM5EdqVop6gWPipbMM7RzyLKUmXjR5RR95LhmyP6hRS/0 lP+lihLvGQzRYNBluxu8gAnd7Pc4/8jeOkaUrhJtuW4dwl5d0uGzhCBA409njJZEFeQ== 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=BhZjQ64j; 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 8DD30606A32D; Fri, 4 Dec 2026 11:30:29 +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=BhZjQ64j Received: by smtp.kernel.org (Postfix) with ESMTPSA id 06B3C1F000CE; Fri, 4 Dec 2026 11:30:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383829; bh=JmTsRO8ORmbOvC4vTL/I79OVS/ksqRCifMGZ2tyrYPk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=BhZjQ64jqhdDBITQkrNluoqhT0Q+SwDu77ajXdSYuwjHI5iPetxWCVivgIKJTy5xc fQ+RZhXG5wgtbk7w8qQT8ovMs3ejz9bRNIO2TVgKj1XtBDGUytxOWCPi6svhjO3L2R UGFdzoNo+YGbzxnfl89qOHH70djNnHVWS5UJJB0A= 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.12 386/555] gpio: virtio: bound the line names block by its configured size Date: Fri, 4 Dec 2026 19:07:09 +0900 Message-ID: <20261204100624.465902237@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@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.12-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;