Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp917327rwi; Wed, 26 Oct 2022 08:40:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5CEDsghPm1Dbmhlo4TQZ3mwglGjRvr3bAOOwhX/2X5r78S5omQTMj0E/xIOLzP3NYaObJ2 X-Received: by 2002:a17:902:d512:b0:181:f1f4:fcb4 with SMTP id b18-20020a170902d51200b00181f1f4fcb4mr45163721plg.102.1666798857442; Wed, 26 Oct 2022 08:40:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666798857; cv=none; d=google.com; s=arc-20160816; b=BIrPoZ61lHnHHyaQP+6ss/V/OvvpWihvV1uiTNvZGiaJRH+h1SxpPYd+5XT0Kfo+nL hK+uaTzcfH1dQfhbcDu6iKpHPmE9MKaGKzqpEytgNPq39CMSatv0BjQjpjTjuLRN84FC mbtCcHtfFB8x6+Zi7QKimC7SCdB56P55vWqW8FT6Kn3wuqrku+8KpB33/hLIwKXFZlFG xypBe8siklQIF7zn9eNuI82rCwHDK3+S/X5YK84vSi4KZIoXTOr/JMzHeD63SrGjYHQl fQBFWRy4lOQdWJLWXJleMXJf+Sniy0aBHo5D6/K80/RnVzWdtXeGIHf44S5oNs8mRgro 1q3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=2/OQLqV5ELcTZXKUi2a3pB+sm3USCoTsaHTH0XoVNQA=; b=o3ZlRR5Q8RTzCTDlehQvidxHcyMLeWpOTGBSz/8fLL0zvgG1KhpMeEZX2sLN3d90o0 spMYpUJSonGVjSL7S/l5i40QO6HuVYYbN96VWMl2X3843Tp6IU/fPzUawNNIIN6ENVNb o2UhzAOvd9ZMbnsgdSav0u7sF0CVoMwhwTgU7ewCYCiHL3VQq4w0jbul3jY14U/aILUE RDkCLX02vfx0HSdVxUfkh68vLtLDb6QHvhv2ZCaaQ9XD60cRpEVWRCtrKAEtJ2osGWf/ dZH3H/6rdbXb3KzVYdVeA7etC6//L4jqJTBiOq2Qm3nOrUGaNC0EypvkeqtLS4cBYT02 tZ8w== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v8-20020a634648000000b0046f13b06061si4830664pgk.545.2022.10.26.08.40.44; Wed, 26 Oct 2022 08:40:57 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234428AbiJZPCW (ORCPT + 99 others); Wed, 26 Oct 2022 11:02:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234115AbiJZPCU (ORCPT ); Wed, 26 Oct 2022 11:02:20 -0400 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id AED12A50DA for ; Wed, 26 Oct 2022 08:02:18 -0700 (PDT) Received: (qmail 1489809 invoked by uid 1000); 26 Oct 2022 11:02:17 -0400 Date: Wed, 26 Oct 2022 11:02:17 -0400 From: Alan Stern To: Eli Billauer Cc: gregkh@linuxfoundation.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, imv4bel@gmail.com Subject: Re: [PATCH] char: xillybus: Prevent use-after-free due to race condition Message-ID: References: <2e5cbdfe-f6cd-d24f-9785-55176af6c975@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2e5cbdfe-f6cd-d24f-9785-55176af6c975@gmail.com> X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,SPF_HELO_PASS,SPF_PASS autolearn=no 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 On Wed, Oct 26, 2022 at 11:52:40AM +0300, Eli Billauer wrote: > xillybus_find_inode() is called by xillybus_open() and xillyusb_open() > to translate the inode's major and minor into a pointer to a relevant > data structure and an index. > > But with xillyusb_open(), the data structure can be freed by > xillyusb_disconnect() during an unintentional time gap between the > release of the mutex that is taken by xillybus_find_inode() and the > mutex that is subsequently taken by xillyusb_open(). > > To fix this, xillybus_find_inode() supplies the pointer to the mutex that > it has locked (when returning success), so xillyusb_open() releases this > mutex only after obtaining the mutex that is specific to a device file. > This ensures that xillyusb_disconnect() won't release anything that is in > use. The standard way of handling this problem is different from this. The driver defines a private mutex, and it ensures that any routine calling *_find_inode() holds the mutex. It also ensures that the mutex is held while a new device is being registered and while a device is being removed. Even that won't fix all the synchronization problems. A process can open a device, and then after the device has been removed the process can still try to access the device. The driver needs to ensure that such accesses are not allowed. Alan Stern