Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3515221pxf; Mon, 15 Mar 2021 11:15:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzHsYtApCrwZW40Pkw625qzLJNPRydDTG67XcYQlElycKB50mNrTC639sG3wEyIAKcpu3ZU X-Received: by 2002:a17:906:7c44:: with SMTP id g4mr24835144ejp.269.1615832104130; Mon, 15 Mar 2021 11:15:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615832104; cv=none; d=google.com; s=arc-20160816; b=W/5z6d05WcOjOX3xpk/zVlbGLhBlFCg4IWPM3nmI28auSezt+qOtN0Yj6Bpa3nnRv0 r3GZ8LPSLx73NBIpR3UJDAOijXQs0+yJ4mRHGMwfgSce6RBWL6w9Kcw8mmTIPEfhNkbf J7t2j0GOFsbIrhg6T7OimOB43JPEdy14OWVORlUyPqqXn59k5x8K9JAsEbjys1X/Fe2b C4D2nfVO/HXH+0AoBaodXsHPCAHRAHlc9GjRo4IlFCVKQFHoiWPjmMncSxnHkf3H60pg 36PFL5yoehi0fb1cgK8d4qBrA4JyUidp+oZ1o+WHId0G59Id5csxG5Q0Fkc9IH8ZUHp3 5wdw== 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=iw1Mq7ecqNJv4ZthZX81cHs4Tb8ZcR7ru8a8IpVnLLs=; b=UR4Z/cMYK1Rrd61u4uDJ/ZBPBU02jWJep42K78GruvSQBCIX2/AfFFRiE9z2Cgvaru OCvstvTayOrqtYuw08WKnEkA3Y7aFcqVZdhwP0AXbm1FRpV8uhdVazJNxv2dNHH3/MuY 16+kiRdf/7XNq0ujtP4O/foCJKIa55XIJyV2A7BRi95Ll9nMhAPL23IJYYdMHD37p1C5 xSEYkeCstB47stDw4/LBgeX/xPshxQd4DH00O6zh2+X1Bzf8Ln3OeYN9H1/UkqSydQkk TzkP0cNzNC+C4RsvD0aswqm3Uwp1k82gi36WxAJM4ysmezs9lFZKXaGr0Ah92VU7bMi3 WAsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IvrxcZ4e; 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 ot6si12051747ejb.337.2021.03.15.11.14.41; Mon, 15 Mar 2021 11:15:04 -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=IvrxcZ4e; 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 S236639AbhCOONU (ORCPT + 99 others); Mon, 15 Mar 2021 10:13:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:35186 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232589AbhCON7E (ORCPT ); Mon, 15 Mar 2021 09:59:04 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 31DD864F5D; Mon, 15 Mar 2021 13:58:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816735; bh=2HPj8oLrztMtAUCh9hgAZnZg5TF3uvxDrlotwYjiObQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IvrxcZ4eharmiKsFeRIgLJj7cf+bSWLel1ot/uM9FdtSUP2qwEQ6ZfQuB351NNOB2 GuMrZsBeiGqriA5DqbVFH1zTCtpAga+9cpMWBcMKdX0VDwmlC3ZToU8oIWWanxxgRM /hLizkmtdGmuoK+64rovn42sEKZbbYDhW08ooBWo= 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.10 083/290] gpio: fix gpio-device list corruption Date: Mon, 15 Mar 2021 14:52:56 +0100 Message-Id: <20210315135544.723265412@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135541.921894249@linuxfoundation.org> References: <20210315135541.921894249@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 @@ -468,8 +468,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);