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=1796382397; b=bdU+5wmVrGdMWXHXGFKcBamwirAzBNYF/0qHg/x5g/jGbL6zt/Q6fUym38pepqa3BxyM GaDUqpLgnwHWwZbIVhAtVldWyE93vD91GRxbmvfFtWWkj7nQ5QnSOmPjYZPlnEPdf322R s6MNvVbbwFnNnK8OSWF+4RNkRZnSYX8tRldg8Sf7XL7rzgK0nIlRJf3UOXDMQcWphCS1j tCQ0AmPN/EvDjonMpowkr4Ul+/I8EkkpnQGnVi3cphb96mINY+7o+W2W/MpnuDi34AQID wTSJPuz40v1HFUxHJ/TbWbEZjdLC9tWk8jbjtmH5hF42XTL6OV5110+82Mb0dOBed4A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382397; 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=XKC/dJ6K7Y33nAOh9hpwYspQbVVVKvrVIMtZKjji8n0=; b=13ggxwp1h/5e35TSKT8kwqhyNVMT9/D+fY0prvnBdpLXmivP6R7TjetC9lZH7Hb3svka F6WSLzrXvpGdon7lY3d1EPFGA5IOJduD63B65/AcWiOfc0osMIlvljGgwP3GdlIMPTwzz fOSBAuF4rqv+XfNeWHWQ2R70K5hsqsZWZLaAKlpaqOFU4zB4XZaXbhYJqiy3eKxCuS9tj akRsnQ2nInDTcOo+PYJhyBPKqy5pP+SQf8bo58VnG9mP8p9YQZuBdmK5WYINSBF/j/sWo bauQ/++vHidRezO2QEnDDKHikcTGO1pSpk8WtqMurARqyFm+yEyZFQPvTrx2ADyexBw== 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=FAUvfjRv; 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 C192F606A322; Fri, 4 Dec 2026 11:06:37 +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=FAUvfjRv Received: by smtp.kernel.org (Postfix) with ESMTPSA id EBCF21F000CE; Fri, 4 Dec 2026 11:06:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382397; bh=XKC/dJ6K7Y33nAOh9hpwYspQbVVVKvrVIMtZKjji8n0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=FAUvfjRv2s+GcgaXT57i0VSolDPCT21jOlsp5CnVvLJzpEcvPTHL7s9crGN0OSDiM 0UraBCmp+hcEKhMgRrGY++Zqyp0cdvYi8vknZchgfGha9DDf/blQnreKvIvu0CzRp+ 1ezxFntikGxEMGqIk6RojvCupZ9Aowun3+ud4yfs= 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.18 435/703] gpio: virtio: bound the line names block by its configured size Date: Fri, 4 Dec 2026 19:05:34 +0900 Message-ID: <20261204100639.389675884@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@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.18-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 @@ -513,13 +513,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;