From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 044AFC2D0A3 for ; Thu, 12 Nov 2020 08:18:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 67C0620870 for ; Thu, 12 Nov 2020 08:18:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726746AbgKLISW (ORCPT ); Thu, 12 Nov 2020 03:18:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725884AbgKLISV (ORCPT ); Thu, 12 Nov 2020 03:18:21 -0500 Received: from sipsolutions.net (s3.sipsolutions.net [IPv6:2a01:4f8:191:4433::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBCBAC0613D1; Thu, 12 Nov 2020 00:18:21 -0800 (PST) Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.94) (envelope-from ) id 1kd7no-006CQP-KM; Thu, 12 Nov 2020 09:17:56 +0100 Message-ID: <2f8fa91f2490eec82893fea837ec52356cda55f6.camel@sipsolutions.net> Subject: Re: [PATCH] rfkill: Fix use-after-free in rfkill_resume() From: Johannes Berg To: Claire Chang Cc: davem@davemloft.net, kuba@kernel.org, hdegoede@redhat.com, marcel@holtmann.org, "open list:NETWORKING DRIVERS (WIRELESS)" , netdev@vger.kernel.org, lkml Date: Thu, 12 Nov 2020 09:17:40 +0100 In-Reply-To: (sfid-20201111_042332_725984_06312727) References: <20201110084908.219088-1-tientzu@chromium.org> <3b851462d9bfd914aeb9f5b432e4c076f6c330f3.camel@sipsolutions.net> (sfid-20201111_042332_725984_06312727) Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-1.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-malware-bazaar: not-scanned Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2020-11-11 at 11:23 +0800, Claire Chang wrote: > On Wed, Nov 11, 2020 at 1:35 AM Johannes Berg wrote: > > On Tue, 2020-11-10 at 16:49 +0800, Claire Chang wrote: > > > If a device is getting removed or reprobed during resume, use-after-free > > > might happen. For example, h5_btrtl_resume()[drivers/bluetooth/hci_h5.c] > > > schedules a work queue for device reprobing. During the reprobing, if > > > rfkill_set_block() in rfkill_resume() is called after the corresponding > > > *_unregister() and kfree() are called, there will be an use-after-free > > > in hci_rfkill_set_block()[net/bluetooth/hci_core.c]. > > > > Not sure I understand. So you're saying > > > > * something (h5_btrtl_resume) schedules a worker > > * said worker run, when it runs, calls rfkill_unregister() > > * somehow rfkill_resume() still gets called after this > > > > But that can't really be right, device_del() removes it from the PM > > lists? > > If device_del() is called right before the device_lock() in device_resume()[1], > it's possible the rfkill device is unregistered, but rfkill_resume is > still called. OK, I see, thanks for the clarification! I'll try to add that to the commit message. Thanks, johannes