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=1796384254; b=UVhtGB2vuyB8ZGDX8QLs4RoNqZvzDh0dJ4olNRi9O3aig2i9rCaghhrHWCk3YT2ujvmC U5t99FekxCnOSrD8C3CZQQLtJ+Miy1owgncp179F+d9KT7rt2b2tRm7hC3prkDmJm1CfP SpzvIfu7r52hMvw3tIa6XGbTbbpc5se+dc+UTpvnPKNI38Ewl5HnrGFRg2OwXbw4XqhwW 8hfWgenegO6WNrjW1w/5Gr6S616iC2hWl5xIf0cwAsRxCb+VVO7KnWZbQ0BawmeeUeKPl euHyuEixN9biOMuNXmG4dUG5I+z7wLlkobnW8hO82HKE0gTfOu2uYgTaFAb/WnaiZyw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384254; 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=6Llu8qmo7wr2GNcsX79ATNGknvruI45HPOH2mVeG6sg=; b=CH8FJNzmzzolT+YbLcuZ5r+UHl8oVUr339FSM8YH9Iumt8m72QPQlMkpcuTceyjQ9eh1 Pm8VIypdC/9b0lAMYlfracGaawn2wym9F7xnGU3B1C2A9mEtAAtAk8fhI8tk+V5sJQJtF /eQYbKTjCpd4sUdantap3S8wz1jlJynGbhzNUmzvoTfAMIwX7y5VVBasghzlMzEs7UKX6 eJZDKRwyIJSdOhGmhsHTd6I0mPNo0PbUkHLCSVOyYkcvEDY25jiQXr1jD93iG/OqLTPwr ZuIIwbL/pRQf7+dGYnmV8w51tZfSZaDr6kJLrcVAb8If4+cB/de/vXtYfvaqJV5dm9g== 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=Yq2PYr1Q; 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 F1A0B606A322; Fri, 4 Dec 2026 11:37:33 +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=Yq2PYr1Q Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B3E51F000C2; Fri, 4 Dec 2026 11:37:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384253; bh=6Llu8qmo7wr2GNcsX79ATNGknvruI45HPOH2mVeG6sg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Yq2PYr1QVITaxsJv7YdSDwmlqEfHm1r9pJLH8E0Q4ukzqZR6F8/9rRK7WQ3xEaj2w KwdryBzyGbktntgXeUNkfIAbjNbn54eAjVNaX8Rh3S+H/gERvoJtGTxlyIl3Kt6RLL /vPaq9y5nx1oAqyGXeImaFhKcj/TjYvv1oUtKh1I= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Andy Shevchenko , Adrian Ambrozewicz , Bartosz Golaszewski , Sasha Levin Subject: [PATCH 6.12 553/555] gpiolib: free the label of lines released after their chip was removed Date: Fri, 4 Dec 2026 19:09:56 +0900 Message-ID: <20261204100629.585294288@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: stable@vger.kernel.org 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: Adrian Ambrozewicz [ Upstream commit 4bc5e234e10866ebaad01ce11ed08f64333dcac0 ] gpiod_free_commit() drops the consumer label only while the chip is still there. A line that user space keeps requested across gpiochip_remove() is released when gdev->chip is already NULL, and its label leaks: unreferenced object (size 32): comm "gpio-hold" backtrace (crc 7ff222d9): desc_set_label gpiod_request_commit gpiod_request linereq_create gpio_ioctl Clear the label before the chip check. The ->free() callback, the flags update and the line state notification need the chip and stay under it. Reproduced with gpio-sim: request a line, set the chip's "live" attribute to 0, then close the request. kmemleak reports up to 30 such objects after 30 cycles; with this change, none after 100. Fixes: 35b545332b80 ("gpio: remove gpio_lock") Cc: stable@vger.kernel.org Reviewed-by: Andy Shevchenko Signed-off-by: Adrian Ambrozewicz Link: https://patch.msgid.link/20261124-gpiolib-chip-removal-v8-2-aambrozewicz@nvidia.com Signed-off-by: Bartosz Golaszewski [ sashal: Replaced the GPIOD_FLAG_REQUESTED name in the test_bit() condition with this tree's older FLAG_REQUESTED, leaving the rest of the upstream logic unchanged. ] Signed-off-by: Sasha Levin --- drivers/gpio/gpiolib.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 86ab8bc142ca1..129b8345b5d4c 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2427,14 +2427,18 @@ static void gpiod_free_commit(struct gpio_desc *desc) flags = READ_ONCE(desc->flags); - if (guard.gc && test_bit(FLAG_REQUESTED, &flags)) { + if (guard.gc && !test_bit(FLAG_REQUESTED, &flags)) + return; + + desc_set_label(desc, NULL); + + if (guard.gc) { if (guard.gc->free) guard.gc->free(guard.gc, gpio_chip_hwgpio(desc)); #ifdef CONFIG_OF_DYNAMIC WRITE_ONCE(desc->hog, NULL); #endif - desc_set_label(desc, NULL); set_mask_bits(&desc->flags, BIT(FLAG_ACTIVE_LOW) | BIT(FLAG_REQUESTED) | -- 2.53.0