Received: by 2002:ac0:a591:0:0:0:0:0 with SMTP id m17-v6csp2077413imm; Fri, 6 Jul 2018 11:24:58 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeYdj4iXW0H7hWzpX17PfqY2vRUP2S5VLuLwq1v8ysq5fzmxsXnv3eKNGVXmGAOO4QAv17l X-Received: by 2002:a65:4107:: with SMTP id w7-v6mr10007578pgp.90.1530901498266; Fri, 06 Jul 2018 11:24:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530901498; cv=none; d=google.com; s=arc-20160816; b=eGHdLyFPLs0nf7fTEZs6bE/Ph+65TxSjFcIRChHMFB13AHLoqmIILLYT9VlNMaAogK lVcaG4ST3dMTW1t2sVzaABZdyW5W0FviC9IFeOGN71wkgriqsCjHACpvUeKt9BBi6KJl 8TSK3BOY6QRX6u+N8CmMkM8A/x/x1n4BndZuYqNT+k1dwRseFmB7I11cHQDBTBvDEBJ9 4Ln3icxfH5bWNOjaienw80tQw0RDPsgnbgzow/PHfEWUudunyxr26yswxUiR/Sz/WyO8 6ZYFNFKyAQjbQNysepUCc6jyEcCCvUrd0lsTZZMxN/qcdhKhw1/7+Qc3F/HZTMsiEHiB ed+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject:arc-authentication-results; bh=9+inYVR7E9g82LHWSO6aXa06/bCcZ8KxCUstsX56Zl0=; b=Ivi+pjl5YGMlLfUsK9j6i8h1oksE6qEMwYjQHp13/vtanZZvYv39BHNlyP3MJczull 9yPykN1oQ+3z9bXx1UJhArdHhXent24N44A8C+0qrjC6XEIe+mTI/TKEf/7rjEQJFJqL IhYoKk+a4oFyrckqO3aPt+GO4iMSbWr/TOx6bpomGOtf2vVaX9tPujCx/tLc+AXeh+zy B6c0YNiL2U1pohPiq6iACiZOnY5Wf0kJlM5Vm6zuQY+oBmlv4V20s6WKFQUYHtZQ2+0i 8mjyPg/k9jeB5BSjyHrxfiz4RKpXRLuM66PUOJcLc+jhJNrFF+HFCG9WPFyGP06aKWJE kzjw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x69-v6si8601007pgd.635.2018.07.06.11.24.44; Fri, 06 Jul 2018 11:24:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934445AbeGFSXt (ORCPT + 99 others); Fri, 6 Jul 2018 14:23:49 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51142 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934440AbeGFSXq (ORCPT ); Fri, 6 Jul 2018 14:23:46 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DFA8C3468C; Fri, 6 Jul 2018 18:23:45 +0000 (UTC) Received: from [10.10.121.173] (ovpn-121-173.rdu2.redhat.com [10.10.121.173]) by smtp.corp.redhat.com (Postfix) with ESMTP id C91FF76CE; Fri, 6 Jul 2018 18:23:44 +0000 (UTC) Subject: Re: [PATCH v3 3/3] uio: fix crash after the device is unregistered To: xiubli@redhat.com, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org References: <1530845836-49101-1-git-send-email-xiubli@redhat.com> <1530845836-49101-4-git-send-email-xiubli@redhat.com> Cc: hamish.martin@alliedtelesis.co.nz, jannh@google.com, pkalever@redhat.com, pkarampu@redhat.com, atumball@redhat.com, sabose@redhat.com From: Mike Christie Message-ID: <5B3FB3B0.7010105@redhat.com> Date: Fri, 6 Jul 2018 13:23:44 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <1530845836-49101-4-git-send-email-xiubli@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 06 Jul 2018 18:23:45 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 06 Jul 2018 18:23:45 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mchristi@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/05/2018 09:57 PM, xiubli@redhat.com wrote: > static irqreturn_t uio_interrupt(int irq, void *dev_id) > { > struct uio_device *idev = (struct uio_device *)dev_id; > - irqreturn_t ret = idev->info->handler(irq, idev->info); > + irqreturn_t ret; > + > + mutex_lock(&idev->info_lock); > + if (!idev->info) { > + ret = IRQ_NONE; > + goto out; > + } > > + ret = idev->info->handler(irq, idev->info); > if (ret == IRQ_HANDLED) > uio_event_notify(idev->info); > > +out: > + mutex_unlock(&idev->info_lock); > return ret; > } Do you need the interrupt related changes in this patch and the first one? When we do uio_unregister_device -> free_irq does free_irq return when there are no longer running interrupt handlers that we requested? If that is not the case then I think we can hit a similar bug. We do: __uio_register_device -> device_register -> device's refcount goes to zero so we do -> uio_device_release -> kfree(idev) and if it is possible the interrupt handler could still run after free_irq then we would end up doing: uio_interrupt -> mutex_lock(&idev->info_lock) -> idev access freed memory.