From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795998483; b=Ofp8F63X07XNqDPU7DuMv4Efcw6p5nGo5rPFeTkmobwNvDGD4e6UO6JFrhfLffsysN3g tqy3+UqT2BrVMzdJwv5dhpPByTAFrJjcsRhrP23eqHij6kFcOGSgkfOAUWxmLTR3I4all HY90mLkDH1ayA+w//F+VeSUHKJCPymPmtpvroZsJRr6N3Wr3gWRa7FIIQaPZIvkeEw56w iWxeDyTajXJV9f45h0HCTE6wxEUPo+ohVMtMoI1d1I9qwHNSqF2c/1UqJIzB3SDmiPiHd u78wbePu/34xKA6ag7in9NJbnQI0KU4zvmqrUbSY3ksZPHEsxHpHnvbz3BaWW4hgLHw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795998483; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:To:Cc:Message-ID:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=9ad8LJM2dnOCxwXsVVgh9D4UiJxZaaBspo1LVIyOjBk=; b=0qutT46U4Q+NRAZBhUPRqUH9ao/tEYkOpYrscc+1x3BQ/hq3U/godFOMD3bm4O56lA6R vDrZyfKeSz9YlDab4SJa6W6XTIvzO/EfNRylTog1ruluwk9A+QgwKSzy7pDjFgIh3fk3W 2vZXjhUxt1bsUCeW6VWOaU/+GOWhQLkpKBtVpEVNiKZBNUNi4kGkDijbgy1Tt2+9UpVfd QzszzcS3r2raaOsP9W7eA8KJIwQKhzw+3StnvLztGR7jlKmNGK0OGpIojjGpGwHLOYDQS 4I7pBzfubH2OGSTvJPE7lshxfonTBQK+go4SwgrhC80IES2E58OlIiO25NZGVYMZSsw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=C9RZQxEn; arc=none smtp.remote-ip=209.85.216.45 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1987D606A31C for ; Mon, 30 Nov 2026 00:28:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1987D606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=C9RZQxEn Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-3b532f8a51eso1052384a91.1 for ; Sun, 29 Nov 2026 16:28:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795998482; x=1796603282; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:message-id:cc :to:subject:date:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=9ad8LJM2dnOCxwXsVVgh9D4UiJxZaaBspo1LVIyOjBk=; b=C9RZQxEn9eunh5OJBAiJITloYc53scIkhJUS5AZG/RhuwjGn4LDcf9q2kD9EVEWfAw exdIfM92Ryh2XQGmum5isJ69gyLx7lRkDpRT9ItaAXvsnn1Eqe1p0GqkF+eWHwJ/eZiH BBGGRUNrcKqeS4oP9fR7AzUHBkdtl6DPD1s3/YSW3itla7+FPlkZG21Hid5bUF3SifpT G12gjRNCRoBYGECgRReCmg/xOyl4enCLGYWiw1Zj/C7RzPYJsQAQL9ZaM+KfImLh9xJE hWxvwhLOYVVHlzGG0xZBd2Ma2AuK3u0kcXRanN1gu4G01uiMSjyA/eIO/z7D4ZyjIT6s pbIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795998482; x=1796603282; h=content-transfer-encoding:content-type:mime-version:message-id:cc :to:subject:date:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=9ad8LJM2dnOCxwXsVVgh9D4UiJxZaaBspo1LVIyOjBk=; b=DlvXzQN7wKXKAlKzdmIo9f1sMs2BvipLUU9ZMPgG5X3xjdbgEqm82/avJMiyu1d27w 6Fz2VinsJf4MTuNrnnykd26sOgGK+gFDeIi2gQt84CuEYb8MqAStLgBW7WN+7mOEoOCh 0eF7Po1L6WqHVPYJ4qgSMTA/IF3yTnoYpNm7Hguwmc8NQnIa7g/JWLtnxNZTRfXDZjnN 3aAlA+4ACR3LeEK2MBlslQGhZ/XTw8eFyrx6y2Nurp0Lfue0AVtAIULy1/BoSV2U7xrN PXdrKKnh7znwTVtrL4H85hw29RlsB7/siB4ax8emDXC7nSKDCGDxMeYvannZMpDk6tMw GERg== X-Forwarded-Encrypted: i=1; AL+hErGhHc/58xphPhjpo7gn//mawcJrmlg/qz2PsEEamJJGIuzqOC6XPDssA6oxI8u88Z/RdKopOKdB0w7BV8w=@vger.kernel.org X-Gm-Message-State: APuU4Z8qNxz8QVoD2PqwwFtbHmOxO7G2mAPDFqk0wd/XC7MbipxBQaD4 ObUpoBM8d1ZGCbXhtR25w4qm90MvpDDRWJFX/cL1c8LhUA5+TGPN77Dt X-Gm-Gg: AZFdTZeXuMOYMagUoxiCaVbd4Yg34o9m+KNg0GoCz6eOVjHpM9NIQlA6DPM/r2M7NcA 9QdalG5CPZmnyIGdWFXUYHBA96feRngDjMyC+NUnnoHtZhm3CgvYxsh5fLtjnVrRNGpHp+hgO/I BoCwZ7PEyoJ1jIpfOwX6WSmAajgwotxvs7CUx8Hqp8KKqlVILL/B+1GwyK6XUuTPYgp64v+SJKU URY64XeZCjTv+foUf53o94ovpNg4hTh9o3jvlD2vgvjRfJMIspe5LbZPaIQioxm4qaWphrbauRY I0FQYjaQjquuiy2W9RbzFEH16ctlxE++4ozZRo43ZUMos3ccCZ/LG/XwHpxWHigdT0e8i/l/h8Y aZ7+qVVs1DrmzRfOvYgi6pnXVprJQuvt0TZ/Ui5+bMHxxGaJQJ6VlQ2pUlUFeruuPsybN/xtdsE GEtz2NQ3ewv7kk6RDy8haJw1mIsdtnWerP59h35hP3VProN7GAZcU+ipoTjxffVXvjBve3ghF8+ i5YbXbFRvwdLmMaojfiAKj/iu9w+QE9kWrOyLueN+fdkVzOpCsMO5Q534ITmkI1C39PxLX3kFgo MHrItkO11QmtMHaL6EKvXzejEW1WYSd5HLE= X-Received: by 2002:a17:90b:3d92:b0:3ac:83c1:2c0 with SMTP id 98e67ed59e1d1-3b41c9b2de6mr28453497a91.64.1795998482296; Sun, 29 Nov 2026 16:28:02 -0800 (PST) Received: from [192.168.45.62] ([218.48.198.193]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b405d63728sm55868265a91.8.2026.11.29.16.28.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 16:28:01 -0800 (PST) From: "Baek Kyu, Kim" Date: Mon, 30 Nov 2026 09:27:47 +0900 Subject: [PATCH v2] gpio: avoid undersized array bitmap in get fastpath To: Linus Walleij , Bartosz Golaszewski Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Message-ID: <179599846717.10686.17869004160600605139.c258-v2@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit The array get fast path passes the caller's value bitmap directly to get_multiple(). The bitmap is sized for the requested array, but providers such as gpio-sim process it for the entire chip. With a 128-line chip and a one-line array on a 64-bit kernel, gpio-sim's bitmap_replace() reads and writes two words when the caller has allocated only one. The second word is accessed even though its mask is zero. Use the existing per-chip path when the chip needs more bitmap words than the caller provides. That path uses a chip-sized temporary bitmap and copies only the requested values back. Fixes: b17566a6b08b ("gpiolib: Implement fast processing path in get/set array") Signed-off-by: Baek Kyu, Kim --- Changes in v2: - Regenerate against gpio/for-next after the public v1 diff arrived with a wrapped hunk header; omit the long header context. Code is unchanged. Link to v1: https://lore-kernel.gnuweeb.org/linux-gpio/nh-fc54eb6a-a671-409c-bf5d-51ad5828438e@google.com/ The arm64 QEMU/KVM KASAN comparison of the original code and this one-line change used gpio-virtuser with a 128-line gpio-sim chip and a one-line array. The original kernel reported an 8-byte out-of-bounds read and write; the changed kernel completed the read without a KASAN report. A 64-line control case had no KASAN report on either kernel. These are preserved v1 kernel images; the v2 base was not rebuilt. No physical GPIO chip was tested. drivers/gpio/gpiolib.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index c09342fc5..5ff53c2a8 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -3560,6 +3560,7 @@ */ if (array_info && array_info->desc == desc_array && array_size <= array_info->size && + BITS_TO_LONGS(array_info->gdev->ngpio) <= BITS_TO_LONGS(array_size) && (void *)array_info == desc_array + array_info->size) { if (!can_sleep) WARN_ON(array_info->gdev->can_sleep); -- 2.55.0