Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3324060pxf; Mon, 15 Mar 2021 07:09:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy6tJgE/EV9TSvanOt9YGDZ8xKFKPoBvmDeMqQblEsjguyTNVWu5KUBKEDrP8EDoWoOdN2h X-Received: by 2002:a17:906:d8c6:: with SMTP id re6mr23072979ejb.311.1615817352189; Mon, 15 Mar 2021 07:09:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615817352; cv=none; d=google.com; s=arc-20160816; b=tE4M9Xnshe33cC/ToCoVj1ex5y3wCtVpHcT/W9uMgq+/cYwbfwVskm2pmput5tCT5t Eh8D1iiKlN1Yl4cXymshaKmgeqcbEqI9aSKqLFah2nz/iAT1/yasxVYPaCGhlXg2H+j3 sdRhrCDnaPJbyy0GsyvZZZqLxN+gmQyREpXss9pSY8q7PKZRH+G00UWLvxRAa90AHrLg GxL1o2041HmST7tHMKPmemiv3UsIZlDcf6WivEIPvXUbhFW6uWJ9eOFxF0i74LojZQFN 9Wn4eLZ2VvV2JoUb3PFw0uZjJT2H9ZzNQShCXCnLZSTX2f4iwvhji7qM768kLn0uaxib 30rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=V24Ic+x9lXw++0c6x39v2JrNNR24jebIxJHDQ0jkr4A=; b=ib5o5Tg8JEy+H95MSMPvr9wYicUFEbOSc8QW4oTfsVtnM2+xURwz721n2DK2oEwihA bq/r86dE3Rg82sjc5I8B5KpU1C1LVEAoLCbFZwbaM+cJYMYoGug1f+5dAZVLVYDlmp9Y xhYYhk05F1Idq9GHXjZlW9XXPO0k4IPyx3Impn7+I5d3IedtzZcFaBmRsU+E+iCH2Yym 7QADprsYSdPqc20sdxhro4WBGMdZpxEVwitHzL0J8186gwWX4wgYNDnZAYFy7dMmQLNZ buENUL/ymzmNoER7rnjuilEjVPfffKemyknw8GxyP/vx2oio4J4fujnYWQxVJJUxseNd wT/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eLsklG7E; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y3si10147617edr.457.2021.03.15.07.08.49; Mon, 15 Mar 2021 07:09:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eLsklG7E; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230518AbhCOOFY (ORCPT + 99 others); Mon, 15 Mar 2021 10:05:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:34938 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231964AbhCON5Y (ORCPT ); Mon, 15 Mar 2021 09:57:24 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D531964F26; Mon, 15 Mar 2021 13:57:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816644; bh=c0d2jQS6BFUIMLZ+8dVKgguyF42abj0GKOvlSsKcxUM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eLsklG7E3ORJPQG8A+PHJBxlD36HOXWmB3noRi77qYZtdmUP8g8gl0SubW86vDr6P x0JSZEhbIYcczKP0++V5BZWotbNgire+6Wxj7rnnY2d8GO2iZDaXS16u1oKNlnhDs4 Tl0oshCTYotCTp5/sWZX8WabAD7p9Tsz7rLN6huM= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Saravana Kannan , Johan Hovold , Bartosz Golaszewski Subject: [PATCH 5.11 038/306] gpio: fix gpio-device list corruption Date: Mon, 15 Mar 2021 14:51:41 +0100 Message-Id: <20210315135508.925911883@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135507.611436477@linuxfoundation.org> References: <20210315135507.611436477@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman From: Johan Hovold commit cf25ef6b631c6fc6c0435fc91eba8734cca20511 upstream. Make sure to hold the gpio_lock when removing the gpio device from the gpio_devices list (when dropping the last reference) to avoid corrupting the list when there are concurrent accesses. Fixes: ff2b13592299 ("gpio: make the gpiochip a real device") Cc: stable@vger.kernel.org # 4.6 Reviewed-by: Saravana Kannan Signed-off-by: Johan Hovold Signed-off-by: Bartosz Golaszewski [ johan: adjust context to 5.11 ] Signed-off-by: Johan Hovold Signed-off-by: Greg Kroah-Hartman --- drivers/gpio/gpiolib.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -469,8 +469,12 @@ EXPORT_SYMBOL_GPL(gpiochip_line_is_valid static void gpiodevice_release(struct device *dev) { struct gpio_device *gdev = dev_get_drvdata(dev); + unsigned long flags; + spin_lock_irqsave(&gpio_lock, flags); list_del(&gdev->list); + spin_unlock_irqrestore(&gpio_lock, flags); + ida_free(&gpio_ida, gdev->id); kfree_const(gdev->label); kfree(gdev->descs);