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=1796382924; b=RYJIhEw2soPi9KMubCTGQCKm43ShEy/cAz93vFDm/fEaFHRuwSPDnzhQmHfP8EV3lhNm ElVq3aJkEXdWGWU4WySOEt7xwKIqH0qqZFa7RjUJ3lYtNve3xPnwfb5/HN8KeQ50uCRBP e7WagYYW4eLIucntdnogarJmD6Zop9ZatUyk8xSVgiQp0ovVyXRLkU3maq76f0TRme7ng xccAsTO/e+alNFlrUw/B0Z8/G73lrOBsqV9DDqxUgsUGNuoNah1pUBCu3Ic07XkpQrxgC gaOY/Ee7ZhbhecBuPRzGW/EpPIpsK4y5vyGdbLCXbiDIJ669PerC4Q3thbHMls2nwrg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382924; 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=xF6yYS3uxH7DCRppxrdB7KKuU871Fvr/DONDtHA/Nxw=; b=kQ7c+jOcYdGodWxypJFo3XmQo3pIPot6sKchPj8A76tireEjpg/Nv7ll18BsiBa9Y1XK KtfnfdgDdQVxxNl1ZM6SHLx0MGrs3ewLgpiW0pUy1rAmnbv78H61SUJpJW5i/buIHHpFf ohwKyyO6meoAOSm+AaKNvo75QHWzX1DLUK/e3nAVLga3igrfMRLuvOsTVwc9UGHChImps F44QbXl7m9p0/II1thIifw6KaFfK47o4m2qpWkcQf8gU0MXJztJznaJRl1Po3CmA2GS0R LvfwUNrbWsR2yRRboHSia6JViuaCaVnopQhnKAHnt5qzzR9X1q6IVpfU7DmvJyjh0OA== 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=zbF8R3qt; 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 9ACCD606A322; Fri, 4 Dec 2026 11:15:24 +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=zbF8R3qt Received: by smtp.kernel.org (Postfix) with ESMTPSA id ACB8F1F00931; Fri, 4 Dec 2026 11:15:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382924; bh=xF6yYS3uxH7DCRppxrdB7KKuU871Fvr/DONDtHA/Nxw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=zbF8R3qtqv55PZpUaTtwaVD/08mfN8h40Da1NfSZxx1y4BmHPzfOZQp3VcvfYy3nM pVGqNMxtk7wEX+v2V3tmCgDN6dCrFlfiibfa+G5l3clF1HUldpC+sXlavgNMtR2aRk mdwu/mqfwUibC6wDKiLrUZ+dQiLbKVsxDJJFqrvE= 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.18 652/703] gpiolib: free the label of lines released after their chip was removed Date: Fri, 4 Dec 2026 19:09:11 +0900 Message-ID: <20261204100645.125633571@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: 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.18-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 1ea1adde96c5b..5ebd6902fbf46 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2514,7 +2514,12 @@ static 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)); @@ -2524,7 +2529,6 @@ static 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