Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2014532rwl; Wed, 12 Apr 2023 23:57:31 -0700 (PDT) X-Google-Smtp-Source: AKy350ZyaXrIsK3SJCONiOHP6QrWTfrKiWnwO4YH59Il+maRCbyh0UjH/xnDpYhsu2RXKLv1J0eB X-Received: by 2002:a17:902:e5ce:b0:1a6:4cbc:14dd with SMTP id u14-20020a170902e5ce00b001a64cbc14ddmr1231390plf.8.1681369051251; Wed, 12 Apr 2023 23:57:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681369051; cv=none; d=google.com; s=arc-20160816; b=N51S3Rr4i//2mZ7VFOkpoDZnaJSfZFJq2cvnw/oHDKxaOpYS4S8fdElmuN61559vS+ AwDY4XAfthvQajzIfP0uSlha/cR6Ub4wYHQIPmpmPcSV0FB0NH5eyyzTQzdNf1tKZVS6 F3b/3cYKeY5L3zktkedzTLxkXNN42nR9C0Et/MYdO2rPALRh/I5kzi5nwqDrkJm/Wesg ieoxbF1jI79OXq0hggipfHbhV2TlxWurNYuHPL5IEj2q+CpwbKm019SE0S6YgVrJLqVA S0earw8jcU4oR+JYCtDWGylxE/NMndIW/ApwHGRLUPdrq5FCWJPxekvyHft9k5TPTp7S MShg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=SUsKt2lHJnjrXbgq0PTMq4qqzRohQ6pUT+rmtPm80ZA=; b=RLlnI78eVAuPMmQtL3hOtLwxhp6b96qw0J9HVDZrIbTOn7O3UHdsdzKj0yBp2BfzdZ pQz6cAUa4FYETjWrn8/k1mx25PBosoyD2ogj0mbcQCWvQxXvWdOj7ISsiqz1lk+jPv3o k1l3lI0qn/n0psgWR4bAEKR8jilGrcuyAnkta2yKgyiwT+LqusL7T5yaWNbqEfWfvzJM oBKnKdZaxRKvF0YXSQr92BrEFKEsGJGGt3k4zHJEyh5P+ZCvMiB1kJHfHKOD1jx57W8S qfbeR+4DWYq+KLjN01S5txzzjwM5l+8Gt85qL/bGpK+53Xs3SFCgVgmuaVnfJ4n30UML yJnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=J94kIAJo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i17-20020a17090332d100b0019cec510d4csi1359735plr.444.2023.04.12.23.57.16; Wed, 12 Apr 2023 23:57:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=J94kIAJo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229546AbjDMGpb (ORCPT + 99 others); Thu, 13 Apr 2023 02:45:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229482AbjDMGp3 (ORCPT ); Thu, 13 Apr 2023 02:45:29 -0400 Received: from m12.mail.163.com (m12.mail.163.com [220.181.12.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2063719A for ; Wed, 12 Apr 2023 23:45:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=SUsKt 2lHJnjrXbgq0PTMq4qqzRohQ6pUT+rmtPm80ZA=; b=J94kIAJoQVkv8tYUYaLvN N0eXHdmWVscOjCErRYCMwjaGc+2H6oWyepXOagOfGpRn6vwLUproNqFVdXSy/G3U un5/BpILabGJDG+1QNtxiWl6HS6luLcB1IGMmbjrr/r+PxdyXpnBv6iTklsoxEJv irrk70MJ1F1RqU424V/yKo= Received: from leanderwang-LC2.localdomain (unknown [111.206.145.21]) by zwqz-smtp-mta-g3-1 (Coremail) with SMTP id _____wAnUgy+pDdkiIVgBQ--.9286S2; Thu, 13 Apr 2023 14:44:14 +0800 (CST) From: Zheng Wang To: dri-devel@lists.freedesktop.org Cc: andrzej.hajda@intel.com, neil.armstrong@linaro.org, jonas@kwiboo.se, airlied@gmail.com, daniel@ffwll.ch, linux-kernel@vger.kernel.org, hackerzheng666@gmail.com, 1395428693sheep@gmail.com, alex000young@gmail.com, Zheng Wang Subject: [PATCH] drm/bridge: adv7511: fix use after free bug in adv7511_remove due to race condition Date: Thu, 13 Apr 2023 14:44:12 +0800 Message-Id: <20230413064412.185040-1-zyytlz.wz@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: _____wAnUgy+pDdkiIVgBQ--.9286S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7Ary7JrW3XFWDtrW7Cry8Zrb_yoW8WFWfp3 y3uF90krWUXFnrKa9rJF43Aa4rCanrtr1S9FZruwnIvrn8ZF1kCrZ0yF15try7XrWkXw42 qr4UAFykWFn8AaUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0ziFAprUUUUU= X-Originating-IP: [111.206.145.21] X-CM-SenderInfo: h2113zf2oz6qqrwthudrp/1tbiXB5QU1Xl6PToPQAAs4 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In adv7511_probe, adv7511->hpd_work is bound with adv7511_hpd_work. adv7511_irq_process might be called to start the work. If we call adv7511_remove with an unfinished work. There may be a race condition. Here is the possible sequence: CPU0 CPU1 |adv7511_hpd_work adv7511_remove | cec_devnode_release | cec_unregister_adapter| cec_devnode_unregister| put_device(&devnode->dev);| cec_devnode_release | cec_delete_adapter | kfree(adap); | |cec_phys_addr_invalidate |//use adap Fix it by canceling the work before cleanup in adv7511_remove. This is the patch with new title in order to clarify the bug. Old patch is here. The root cause is the same as old one. https://lore.kernel.org/all/20230316160548.1566989-1-zyytlz.wz@163.com/ Fixes: 518cb7057a59 ("drm/bridge: adv7511: Use work_struct to defer hotplug handing to out of irq context") Signed-off-by: Zheng Wang --- drivers/gpu/drm/bridge/adv7511/adv7511_drv.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c b/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c index ddceafa7b637..e702a993fe6f 100644 --- a/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c +++ b/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c @@ -1349,6 +1349,10 @@ static void adv7511_remove(struct i2c_client *i2c) { struct adv7511 *adv7511 = i2c_get_clientdata(i2c); + if (i2c->irq) + devm_free_irq(&i2c->dev, i2c->irq, adv7511); + cancel_work_sync(&adv7511->hpd_work); + adv7511_uninit_regulators(adv7511); drm_bridge_remove(&adv7511->bridge); -- 2.25.1