Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp8572996rwr; Thu, 11 May 2023 03:19:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6Wd5FIYcDxSMJbq9ofthRIjG9QO+Wvz6+MhmlayevyKgP0C4mNYNYp6WqmtCujdy7yvJDl X-Received: by 2002:a05:6a20:8e04:b0:100:1583:f230 with SMTP id y4-20020a056a208e0400b001001583f230mr21920734pzj.53.1683800341978; Thu, 11 May 2023 03:19:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683800341; cv=none; d=google.com; s=arc-20160816; b=ffeBUguSmOSMfnkUowRY8dVUPXeb/vZ4t00+BJ4eNfsVY+qfAz8IBZjDWOjQWb3404 DgKehV+X7bf12uLT36JJ9zXY2Jd2i2t55rOqF/Z52MpSyd5JVw6QTRMy4qI/ssh3RGXb 2bQ3kgZ29wYTzkfChS+4VZOyTPxuUxT4ovq53w5t3t5sBcmj1HDiH8Mid7LpWDsTixtJ Gzp4yjG0U5ED1V3K3DRui8nWE9IXq3NQ6cgPFg3UkcyGTUTfn5DYiFD5ReEy0R7UIIg2 n40aTx99KxdwuQJERT+IgicU+VQD2WcW0ug9b9gFAQNcMmrYnTtH2CQdZhPfj/IM2oFx hGgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YviNjDFHhOqwkOhoUfFml83L4Enfc2RqdN30M/s6IK4=; b=Ur3YLejs7qrW5pGIqEGtS5nBP19Yjq30XETDPWzPOQUPZZtio1IUHqQ4s+0jQ/kIOa fsO/tZLEle+5CamQfxofj7xUtxZnOEs0f5hmkkZyOfXdGoFWuQ8QxrsQl5y5MIkrhfny lFJx8V+M7be1qTfr117yEXbxkeiXc9LCUBx70SXMJMHhGKah7jJUspWfdbF+iWOxQibf uzhkMgk84s1PfrUnXuA/kS63KRo6mh2ZU6gJ5Ewz/32m4T2jwnWO5mjKXeRm2rbM2VKW BKEfIZ5akNZa8chjfsYvXwHyr0LLTFYhD0mCa9+X25POEpxTmhvuL/gpTBSD/SpEYEVY QPDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aGrI7+aN; 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 s29-20020a63925d000000b005134680e477si6258405pgn.499.2023.05.11.03.18.44; Thu, 11 May 2023 03:19:01 -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=aGrI7+aN; 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 S237370AbjEKKAC (ORCPT + 99 others); Thu, 11 May 2023 06:00:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237852AbjEKJ7u (ORCPT ); Thu, 11 May 2023 05:59:50 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1D373A82 for ; Thu, 11 May 2023 02:59:48 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-3064099f9b6so5420692f8f.1 for ; Thu, 11 May 2023 02:59:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1683799187; x=1686391187; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YviNjDFHhOqwkOhoUfFml83L4Enfc2RqdN30M/s6IK4=; b=aGrI7+aNFi4ljfy8dR3J49VBbZoM70kswN+XaFAVWv+4rpWu/UfZHTPJMy4NJQdHW7 VmN2CxovXzriyOKSBzoNIjeffT1d9k7WirSXXr6q0sTubF8BnyOpe2xR6hqsFCSRIsDZ J577lClwPZ5CTyTMwOgHdVzDgaVm7F2F904SH0OgAhTJ2uOATb+ApXJ4hZgk8wjmZJdj MdmK5lcJvYN1a2teXAKfVi7qjaEccBEn0sNUxaFjvQUWu6SCIYdxrzH5RxO4dZIPDWsX eKH+3PDzcjA65fRvSzAHBd32uAjnnnR7yCCwD3ZA+EVwJTF7zwnRQ6tB6vGstEsak6qL n+UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683799187; x=1686391187; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YviNjDFHhOqwkOhoUfFml83L4Enfc2RqdN30M/s6IK4=; b=DXzvX/khBn/qZbLTyTIlyjgSkBHuxvVpfLxDcE8iAPOetqx64Bb7d7Shb89hDpQigO IBcXZbrWg2RmHj98al3LYUhiBb/Qu8A0aI5gp0vhWABJAAi8W4cUU3wygVbf7xo1Q+9t UYQK1UkczdtbWgWgjqQwESITYnL932llFn1EfFw7x7gq3AND3xDMVslrL78ZdrZqdvgz d81wAOgm1mxDLLBmsC2vGYU9VVLClhtAhxpmhYX3O2QNFog14kvCf7hgnKmREsvVoecA jYutWcgVpO2hj9Foq8/XupG600V2ZDjkmhAiO91+jZkINq0zwe6F2aSWYdJHCRh80z92 BQog== X-Gm-Message-State: AC+VfDyg6qEPCS5T21/DLB/TkwIGg4S168OSkITLvy7ePnSR3ZbOHOmT 6I9UPOSVVbgbY9ZtzDJOOXBsFuSffsU6osz0oxiIbw== X-Received: by 2002:adf:f30b:0:b0:2cd:bc79:5432 with SMTP id i11-20020adff30b000000b002cdbc795432mr15948521wro.25.1683799187295; Thu, 11 May 2023 02:59:47 -0700 (PDT) Received: from localhost.localdomain ([64.64.123.10]) by smtp.gmail.com with ESMTPSA id k9-20020a05600c1c8900b003f4283f5c1bsm12122791wms.2.2023.05.11.02.59.40 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 11 May 2023 02:59:46 -0700 (PDT) From: Zhangfei Gao To: Greg Kroah-Hartman , Arnd Bergmann , Herbert Xu , jean-philippe , Wangzhou , Jonathan Cameron , Al Viro Cc: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, iommu@lists.linux.dev, acc@lists.linaro.org, Zhangfei Gao , Weili Qian Subject: [PATCH v2 1/2] uacce: use q->mapping to replace inode->i_mapping Date: Thu, 11 May 2023 17:59:20 +0800 Message-Id: <20230511095921.9331-2-zhangfei.gao@linaro.org> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20230511095921.9331-1-zhangfei.gao@linaro.org> References: <20230511021553.44318-1-zhangfei.gao@linaro.org> <20230511095921.9331-1-zhangfei.gao@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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->mapping to replace uacce->inode->i_mapping. Signed-off-by: Weili Qian Signed-off-by: Zhangfei Gao --- drivers/misc/uacce/uacce.c | 14 +++++++------- include/linux/uacce.h | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/misc/uacce/uacce.c b/drivers/misc/uacce/uacce.c index 346bd7cf2e94..338b59ef5493 100644 --- a/drivers/misc/uacce/uacce.c +++ b/drivers/misc/uacce/uacce.c @@ -166,8 +166,8 @@ static int uacce_fops_open(struct inode *inode, struct file *filep) init_waitqueue_head(&q->wait); filep->private_data = q; - uacce->inode = inode; q->state = UACCE_Q_INIT; + q->mapping = filep->f_mapping; mutex_init(&q->mutex); list_add(&q->list, &uacce->queues); mutex_unlock(&uacce->mutex); @@ -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 @@ -597,6 +591,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(q->mapping, 0, 0, 1); } /* disable sva now since no opened queues */ diff --git a/include/linux/uacce.h b/include/linux/uacce.h index 0a81c3dfd26c..e290c0269944 100644 --- a/include/linux/uacce.h +++ b/include/linux/uacce.h @@ -86,6 +86,7 @@ enum uacce_q_state { * @state: queue state machine * @pasid: pasid associated to the mm * @handle: iommu_sva handle returned by iommu_sva_bind_device() + * @mapping: user space mapping of the queue */ struct uacce_queue { struct uacce_device *uacce; @@ -97,6 +98,7 @@ struct uacce_queue { enum uacce_q_state state; u32 pasid; struct iommu_sva *handle; + struct address_space *mapping; }; /** @@ -114,7 +116,6 @@ struct uacce_queue { * @mutex: protects uacce operation * @priv: private pointer of the uacce * @queues: list of queues - * @inode: core vfs */ struct uacce_device { const char *algs; @@ -130,7 +131,6 @@ struct uacce_device { struct mutex mutex; void *priv; struct list_head queues; - struct inode *inode; }; #if IS_ENABLED(CONFIG_UACCE) -- 2.39.2 (Apple Git-143)