Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp8237863rwr; Wed, 10 May 2023 21:06:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7uLPQSy8kB+Y555r29KnAk58QFIWu9BheAep8tVLE9uqe0zpCW9zSoZGs5Tn3yuvdtVSQC X-Received: by 2002:a05:6a00:2d06:b0:645:1fc7:881e with SMTP id fa6-20020a056a002d0600b006451fc7881emr20422638pfb.22.1683777978424; Wed, 10 May 2023 21:06:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683777978; cv=none; d=google.com; s=arc-20160816; b=TaeP/Jasfrr+QxASml22kqOUWCqqbzqzDSME7ZIUbBmu5SvFfhzAudJJmvT72POg4B Ly/suuptA8OdsbgTUiE+9muP2K0y7ziGKGYM1yQOuCopHt7kVz0Bs/hHw9n5VgDz4bX9 CtUMSbvZ+/vzNEVAonl/RxBf9rTSBLZvyA58bm87R/Lf0ml8IRJ4lP2MapIjaWKE4K5Q udJeeJPuxPN5lVQmsStqdN4VB8UHPWd38qLx6VjoOv9YHW5E3bhGVXZ6PhHdk8gR3T98 RnaLjwvoBOPPb+DkQlErXFD4aztOCfNjfJWz55EZ77iSGU2eVxTF3V03fYiGyjbE6LfZ N8Jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=es1hAOZEanSpUzrO4i+W99kSmiTSzzhtBMlo8JnwlYU=; b=CEns2YI5V+4ty31acymOu+f3t6qL8Lrw4vn4Sy6LftnkZuqMUqkEZ6qFaozNR1VYug 7wmsLXyfMfhgo0UEKiLE503R+PL22sKW1LbiOFwgGUR3MwwPnSxtqGqpqk+T8Ukcw2os VtXvfDp17VzDcrcQzdRTCZAgJ0Fay1pPeLpu5X2DYEsmKr8URzvtE6nZaPsD81XvG39N zJVidLGGfsyjiKsy+O6dCH9Enw2SCdrJv2Gpe3/WItTJfsUhsByvt+8C09SVrNEUF5Fl s8Iuemk7IXDqB3rE5Ah8J545ak0V6pOBHYW+sU5c6N420XSHkHdDcRxFV+dsOGogeXLi kXLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=XiM0jwFn; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k13-20020aa79d0d000000b006375460490dsi6721413pfp.136.2023.05.10.21.06.05; Wed, 10 May 2023 21:06:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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=@linux.org.uk header.s=zeniv-20220401 header.b=XiM0jwFn; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229485AbjEKEFg (ORCPT + 99 others); Thu, 11 May 2023 00:05:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229473AbjEKEFe (ORCPT ); Thu, 11 May 2023 00:05:34 -0400 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [IPv6:2a03:a000:7:0:5054:ff:fe1c:15ff]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 949E23AA5; Wed, 10 May 2023 21:05:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=es1hAOZEanSpUzrO4i+W99kSmiTSzzhtBMlo8JnwlYU=; b=XiM0jwFnKxFWGJpiCOPcZXBOTf 7Lff2nNv1b4BAaAzu2+8+Z6IL8XztnltccQ/JJuih56T1wL6PGmnGsDk5E0M2IhLX/LK07JbuLSIZ 7MeUi0RBKlVjXfF2dQ49aEOFQTTDRlx51zHwTVQTE5xRu4I0fDcigOhciITUn6bZwgzkWHvP5GDoh 2fdZoKkTwbsFp75btQY8vp64HMyDOb8xRvh6sSFXwAn6is5GoyjejZl85uiLUVi+kd01BW70CUhr5 tVCPkz/2NQ/hoG7jre3wotCKe/XGVrVJE/Z2HuYhiIxeH3PutobfBK7QQ7ocB4hd/asQ7TR+7XP1K n3LuDq7A==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1pwxYC-001apk-2B; Thu, 11 May 2023 04:05:08 +0000 Date: Thu, 11 May 2023 05:05:08 +0100 From: Al Viro To: Zhangfei Gao Cc: Greg Kroah-Hartman , Arnd Bergmann , Herbert Xu , jean-philippe , Wangzhou , Jonathan Cameron , linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, iommu@lists.linux.dev, acc@lists.linaro.org, Weili Qian Subject: Re: [PATCH] uacce: use filep->f_mapping to replace inode->i_mapping Message-ID: <20230511040508.GF3390869@ZenIV> References: <20230511021553.44318-1-zhangfei.gao@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230511021553.44318-1-zhangfei.gao@linaro.org> Sender: Al Viro X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE 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-crypto@vger.kernel.org On Thu, May 11, 2023 at 10:15:53AM +0800, Zhangfei Gao wrote: > The inode can be different in a container, for example, a docker and host > both open the same uacce parent device, which uses the same uacce struct > but different inode, so uacce->inode is not enough. > > What's worse, when docker stops, the inode will be destroyed as well, > causing use-after-free in uacce_remove. > > So use q->filep->f_mapping to replace uacce->inode->i_mapping. > @@ -574,12 +574,6 @@ void uacce_remove(struct uacce_device *uacce) > > if (!uacce) > return; > - /* > - * unmap remaining mapping from user space, preventing user still > - * access the mmaped area while parent device is already removed > - */ > - if (uacce->inode) > - unmap_mapping_range(uacce->inode->i_mapping, 0, 0, 1); > > /* > * uacce_fops_open() may be running concurrently, even after we remove > @@ -589,6 +583,8 @@ void uacce_remove(struct uacce_device *uacce) > mutex_lock(&uacce->mutex); > /* ensure no open queue remains */ > list_for_each_entry_safe(q, next_q, &uacce->queues, list) { > + struct file *filep = q->private_data; > + > /* > * Taking q->mutex ensures that fops do not use the defunct > * uacce->ops after the queue is disabled. > @@ -597,6 +593,12 @@ void uacce_remove(struct uacce_device *uacce) > uacce_put_queue(q); > mutex_unlock(&q->mutex); > uacce_unbind_queue(q); > + > + /* > + * unmap remaining mapping from user space, preventing user still > + * access the mmaped area while parent device is already removed > + */ > + unmap_mapping_range(filep->f_mapping, 0, 0, 1); IDGI. Going through uacce_queue instead of uacce_device is fine, but why bother with file *or* inode? Just store a reference to struct address_space in your uacce_queue and be done with that... Another problem in that driver is uacce_vma_close(); this if (vma->vm_pgoff < UACCE_MAX_REGION) qfr = q->qfrs[vma->vm_pgoff]; kfree(qfr); can't be right - you have q->qfrs left pointing to freed object. If nothing else, subsequent mmap() will fail with -EEXIST, won't it?