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=1796381486; b=K/wFqswKsWI0zD2s/aAj/kuuZl+kuuQU1POy4d4TuKAhLJGExIjUtCglRuTTR804LjB2 eDORgJWEy19bMcN6dRKkp5schQ/a2ZJhy3oEQPcra3WKHP1SUwtBfJyQ6yPS0XeL0yrsc Meh0TY/amPczIrt5p6a4WPOrobpuore/GKe32PoLVzozRFji7/DdzeB1ZngAhTsz6Ce9y 8zQkNUjxnYFTPyQPC+fIbgdWSYRrGH2Dyq1iXY3OWZKG+bmH/Fo6fgBwEdeBwuMBXcE6X lwv7SBfuY+qKDmVuyPhUno7rvnDzbiIVeGHtFIDvEiAdZI6WVCaLSxrYbIxpOwkWSZw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381486; 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=j2zIwk75GMJE9IJvurBXLJvaNOi8orJnebKRrL+O5EU=; b=OdfJXEo1p8Q/zJ3ruVzkOSHYg1Hp1YpFnoX6hOjJzFxJYgdz+992ZoLNL/Mw4WRiNc+D oj7lT05rQNHJabgGEPm5wdPFJ+AONruEdMVxYHOqY1wdjCuDIzVLpIDelK7JrF+7tCDcl Tvj2BPeMCXNxEktqe4/mds+jPLZxsqYDMbQ3D8IT4IBpGvzhX0Y8TUiSCsoBaUE+7lmD/ 7rBPV2TSDDRQPGmPN3vpjoEQLpwle7dNCmhdAoWKkabDSE2/DsUzu90yUQd2Vfr/u6fcD P4aAhWzP/3QD4uWD/6V4BrL9HrNeknS80kHYQhOyHjsOYnnAJXiyoyEADwGRyNXsKxg== 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=U7fDFIhX; 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 6D2FE606A32C; Fri, 4 Dec 2026 10:51:26 +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=U7fDFIhX Received: by smtp.kernel.org (Postfix) with ESMTPSA id D53F11F00897; Fri, 4 Dec 2026 10:51:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381486; bh=j2zIwk75GMJE9IJvurBXLJvaNOi8orJnebKRrL+O5EU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=U7fDFIhX5PaK+NoOHpm7shz/fGyFiTIZuZj7qo6iO7jM363UZeo1diogrj85LkcpD co+yHet6Sxi9+rdslkLxMFfMFMEX7nmClni04QbK5IVjKxo4ypm3hlvCgdfgJImCha 36aUt8hxl8wYf/5LEFBzIJ6OLa+CnkQpjccqWYWQ= 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 7.3 725/742] gpiolib: free the label of lines released after their chip was removed Date: Fri, 4 Dec 2026 19:09:49 +0900 Message-ID: <20261204100654.343078007@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@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 7.3-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 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 4b0e7d066497b..67d68806310ee 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2686,7 +2686,12 @@ void gpiod_free_commit(struct gpio_desc *desc) flags = READ_ONCE(desc->flags); - if (guard.gc && test_bit(GPIOD_FLAG_REQUESTED, &flags)) { + if (guard.gc && !test_bit(GPIOD_FLAG_REQUESTED, &flags)) + return; + + desc_set_label(desc, NULL); + + if (guard.gc) { if (guard.gc->free) guard.gc->free(guard.gc, gpiod_hwgpio(desc)); @@ -2696,7 +2701,6 @@ void gpiod_free_commit(struct gpio_desc *desc) #ifdef CONFIG_OF_DYNAMIC WRITE_ONCE(desc->hog, NULL); #endif - desc_set_label(desc, NULL); set_mask_bits(&desc->flags, BIT(GPIOD_FLAG_ACTIVE_LOW) | BIT(GPIOD_FLAG_REQUESTED) | -- 2.53.0