Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp8558711rwr; Thu, 11 May 2023 03:05:36 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4tJ13rZvJJZxt1AS6cfEsW3tsmx9d+XchnByOizhuDhmhAQdVwyQnwNydlnosdYUZUtJof X-Received: by 2002:a4a:ea0e:0:b0:54f:5c56:a0c3 with SMTP id x14-20020a4aea0e000000b0054f5c56a0c3mr4317943ood.0.1683799535832; Thu, 11 May 2023 03:05:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683799535; cv=none; d=google.com; s=arc-20160816; b=wDGMiTtDJKuXgLR/bI9Onq6b1qBfXot4Rs9oI2ZOxd42xHyabzoSXQapm7dUrTjUAq LzelyNE8GyhYEtiE1zndd/48wKm0FbRkzdzTlGNi12vDKO3HEPqKX/4ak4t84yE4+sn2 Ly3IIX5N5xHwbFMJsc/bju+PtWwHFk6KpGNNMI2jdModDbBp9jeQmvvN6BV6XGYMwWnT 0NRO+Hd4MHndUzDXu3FnVQDxO16TCfMtkFDH8eP8QwuLq8FN5mlVedOr8hoJX8/kLV03 pVpv3yFrploBEbCcgtV+7GhdnQOEmVhw0D9367vt6iixNk5/hrxaqytCCxArYbf1wWvu E3/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=SSI1132STpqumEpf5Ec2V/BEc2eB+fNK9tPTW1B97gw=; b=ZWEAWz5jEjsYpx4K7RYZIKMB//G9ueX7p1Y+CKqXeZJTW2boB2ajClxQiUmTnJe21A ArF9DklKQcDi5lAkwzOo0d36knym3Ci/3Iau8CT/KGqiDVylPmpgFHxmi7aRKLgRQ685 9QZCqJehh6OT71sn6L1ETEHhgdAG4KsUaffMOaWjptuAZVGR59r9ibmwdq73PDCdnbRH nTqUbLgCUOABKMZTh8YbnL5Nc6zHxbpyJbmwJ13nmBZqWxPnAgYfwEZv1luZPv7wEbHI fcnvGSuSEkvJXCMNMO+91U1ABzpyfRq2uxHuQW8YX25iGemZ2JUGFdyElBUkqPquoVIX qaUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Nrx9UrUd; 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=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d15-20020a4a918f000000b0051ab21db97bsi9199003ooh.10.2023.05.11.03.05.22; Thu, 11 May 2023 03:05:35 -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=@linaro.org header.s=google header.b=Nrx9UrUd; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237833AbjEKJ5Y (ORCPT + 99 others); Thu, 11 May 2023 05:57:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237843AbjEKJ4y (ORCPT ); Thu, 11 May 2023 05:56:54 -0400 Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE5139ED1 for ; Thu, 11 May 2023 02:56:34 -0700 (PDT) Received: by mail-qk1-x729.google.com with SMTP id af79cd13be357-75765c213fbso296949085a.2 for ; Thu, 11 May 2023 02:56:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1683798994; x=1686390994; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=SSI1132STpqumEpf5Ec2V/BEc2eB+fNK9tPTW1B97gw=; b=Nrx9UrUdsK+HUWMkWqBZ3TLP43oATk4+Hg2L6O/B52KpFdhsmhgxU0R59nQuNE1D6K RAqIIx/MyIBOmDErPHfk0NiYNjvGSagoMAQHx/zaBfuGNKkVbnefpTh6RV4rAkKKw5OJ o/9KjWLXQFoUqPTOk3L39Ql1q33x3UaGGBTTVQ4zgMyshDyYFtv4IfpPqR0MTk43NOWF +ZSiSJRj7TuobBu4y8zpryafBQzwhN2qLR/5wkr6PmZlejq/N74usVCz7rnWNa4dXaCM kkEuQGaEIcFcIrHJemeAQZb79a374m6vZI2Co0qvTlvr18XO9heswrGiytaankpJu7qN uzRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683798994; x=1686390994; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=SSI1132STpqumEpf5Ec2V/BEc2eB+fNK9tPTW1B97gw=; b=gwCbHhP/Dr1otNZvVeE7OVdyWhosGEhttN13hIdykDIO2+VvlFOWMB+Mz+9pwYNrUA y1iFcAeinFdcS+jfsxw4ckt1/RgQze4RLDHKbgKTM2+R7OaT1MyY533kSPiiqBVbUoUF a97GU3G0w4kVKCCkEwyf8FPEvl0X4upt0WWGA8q99YdkVHg4qRQAoYY2rj01dOWnUZ8N s1k8fvyuM8FSiMwL/RKP5CpvEco9SgSceiUkAzCemDdoBrmp57V1qRVCrY7qWGMfM3hK K8DbO9JFVH1ek/H9gDJ9jFCGXePymFwTkDQ96qe+zNsNK5QIMjzzSoRVBnksTOGCR7Gd 690Q== X-Gm-Message-State: AC+VfDzFObhMdlLnpRrFqHbD02HX6sNNwRQzh7CY2WJvv1ZMuHbxvqAG YJpj13cm9waMlXO+CV6mgqwEIpK7qhsyDfczXIEIoGlsfOJbc8mH2uqazrz+ X-Received: by 2002:a05:6214:27e1:b0:56e:a96a:2bdc with SMTP id jt1-20020a05621427e100b0056ea96a2bdcmr24213392qvb.40.1683798993806; Thu, 11 May 2023 02:56:33 -0700 (PDT) MIME-Version: 1.0 References: <20230511021553.44318-1-zhangfei.gao@linaro.org> <20230511040508.GF3390869@ZenIV> In-Reply-To: <20230511040508.GF3390869@ZenIV> From: Zhangfei Gao Date: Thu, 11 May 2023 17:56:22 +0800 Message-ID: Subject: Re: [PATCH] uacce: use filep->f_mapping to replace inode->i_mapping To: Al Viro 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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, 11 May 2023 at 12:05, Al Viro wrote: > > 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... Yes, a struct address_space is enough. > > 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? Good catch, will fix it. Thanks