Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp347609rwi; Thu, 27 Oct 2022 01:59:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6uECa3cPQWx/pJgFKiy7yUyMS8NBrk4enmvnW3OfyRqvNDUIFqpa3+LKni807DvkYqvvZZ X-Received: by 2002:a17:906:58d2:b0:78d:9d2f:3005 with SMTP id e18-20020a17090658d200b0078d9d2f3005mr39727824ejs.697.1666861182540; Thu, 27 Oct 2022 01:59:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666861182; cv=none; d=google.com; s=arc-20160816; b=h2Ek53vbdCWu6vXv7I2NULk+ixcskhdCYKmA5N5/2Q+dfh6hakLOkaJKkDdFlxR/CU pMUAtCxQWtQ0thzhMl9O/cdaKCG/Bu0to2Tj0xswU+ov3iKNKsNQhK5Yi75Dl/Uo8Q6n OHYkOtXjV4t4SqkVj8BxgQxSmeI8eyywy5/f5XcbUN2VXWZB3eBZfdAzZ6J+cBI95bzG BaftIJ3KFnFtmJVCFfYzohfyKOFIqjkm7Qv4bS7WT851Y3OJtMkuJalOFBefeaI7St0S hCGeNsvvh6/jd5/jzM21z3m0gJzTzKYsi27NFH3lsQkTQyK+brw8/kIEQ4z0yTgfY4me RI+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :content-language:references:cc:to:subject:from:user-agent :mime-version:date:message-id:dkim-signature; bh=7ZnInTEdE6m53x3YlPmddOdHI+B78CP4lWnvW8zAy/0=; b=cAFTuPJSvI2yvI5EOc3nIRs3FAG3v8UpFBxrsQhzkCgetDM/wgFhVimN4e5VOmTctl 2Lm+BFImzG2ilxKU8MHgn3cN7HjIT1iRlla/xa1VG42Wwc9qM6mAoP0/gS8mZvC4jgsO zy7Q9yIEIYZfonL59+MyPvuqCUADofrcSsJ+wWagoVqmG06YfdS7YCbtWvAfpBAq5lr0 wiNakLOp28ytJk2+93uDGEbQytNWfo4xbWUCUTfbj6mBXwtTfFDoFpE9J/A2NisGopmF 1z6DhNTU73KHRZilRkUQPKlBeB8U/wQz7C4R19n7kX+fkITyLhtGVF9yyHMeNFDbUNaT E4UQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ijWZqBV+; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hw9-20020a170907a0c900b00787e1d77943si1020903ejc.49.2022.10.27.01.59.17; Thu, 27 Oct 2022 01:59:42 -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=@gmail.com header.s=20210112 header.b=ijWZqBV+; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234881AbiJ0IGc (ORCPT + 99 others); Thu, 27 Oct 2022 04:06:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234877AbiJ0IGN (ORCPT ); Thu, 27 Oct 2022 04:06:13 -0400 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 248C4ABD72; Thu, 27 Oct 2022 01:06:12 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id y69so1381551ede.5; Thu, 27 Oct 2022 01:06:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:from:user-agent:mime-version:date:message-id:from:to :cc:subject:date:message-id:reply-to; bh=7ZnInTEdE6m53x3YlPmddOdHI+B78CP4lWnvW8zAy/0=; b=ijWZqBV+oMnTpDEG9zR9caw+iwlaX7CYJw2Embia1jt1NznC/HIaMuLgihBh63YR8P FduJhc5Du/rWyhH+BEO76Q0gLyyDvi1UMpTRrnc35G7zBKq7Ld+Ub0T3CTb9B2n7fiJs 8cmBHpZSHKGgeD86hRzLZIT1Io1Nl7i1AVRR5zAmfnNz8JNQo1lAKiYFuw7bUJv+7BuI ynuwL9UP2+apZ+yumVbT7VHZIV+UIFwB4kgJ/xAR59IRrxhX3vLoG99cuGcA8dD949ZO xZVQE6n4Wn8yLon3vDh6CkrhbO7QldJN2Uu2dBHxM95NhI7M5pYv4asW0bZhNxXgl1Da c92Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:from:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7ZnInTEdE6m53x3YlPmddOdHI+B78CP4lWnvW8zAy/0=; b=G2VMBoPgX0FUcscM6IRzTGhqvrtOym7SH/rywvV9QvGcN3NudmpRjl9TeoOg/gPHbY WttHTpde60CYfG8ioO1UTDjUtAJ/JUXcKVDrh5O108ohGyoVqHZX/AQykwkhIPiafKKH cQ6H2mis04j2e0eiHunvZaLhn8w/5C1B8YEHyvuwKuvBauTFdNz8j3lmQHBW4aM27oDN OvCilbdB4H8F7XhS8g+VCpH+e3LHC0Wm80jFLsqyTNVehpa+Pb6unb99C3jv/Xhq/YZh le0RcnIDMD9VyWWiJK79TkHfm1DEmWefiRqe4gXHElliQNZekY+VYVCZTV8H4KWx6qUi Sriw== X-Gm-Message-State: ACrzQf2MvwjnYZKguLEuj4sFZ9ZFXrBDHH2ITBOCk/Nxh36C1muKh/ut H+vWB3UtPN3c40u2bdP0VY+86blQNnpEug== X-Received: by 2002:a17:907:9611:b0:78d:bb06:90a3 with SMTP id gb17-20020a170907961100b0078dbb0690a3mr41222667ejc.233.1666857959802; Thu, 27 Oct 2022 01:05:59 -0700 (PDT) Received: from [109.186.183.118] (109-186-183-118.bb.netvision.net.il. [109.186.183.118]) by smtp.gmail.com with ESMTPSA id h3-20020a50ed83000000b00451319a43dasm570872edr.2.2022.10.27.01.05.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 27 Oct 2022 01:05:59 -0700 (PDT) Message-ID: Date: Thu, 27 Oct 2022 11:05:21 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 From: Eli Billauer Subject: Re: [PATCH] char: xillybus: Prevent use-after-free due to race condition To: Alan Stern Cc: gregkh@linuxfoundation.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, imv4bel@gmail.com References: <2e5cbdfe-f6cd-d24f-9785-55176af6c975@gmail.com> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,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 Hello Alan, On 26/10/2022 18:02, Alan Stern wrote: > On Wed, Oct 26, 2022 at 11:52:40AM +0300, Eli Billauer wrote: >> 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. Thanks, I'm going to follow that advice in my v2 patch. > > 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. Indeed. For that purpose, the relevant struct has a kref_counter, and an error flag that indicates a removal among others, along with mutexes. The problem is the time gap from the moment that the struct has been found by xillybus_find_inode() until it has been secured with the kref. A new mutex is going to solve that. Regards, Eli