Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp455684rdb; Tue, 5 Dec 2023 09:51:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IGKZIuaDhYosv6jlJ0OEdqH4BwGAyFjHNB2KzvP+EsADJECghbeQis4yRUJCljC/lvWRg5V X-Received: by 2002:a17:90a:fd83:b0:286:818c:27a2 with SMTP id cx3-20020a17090afd8300b00286818c27a2mr1709187pjb.49.1701798661503; Tue, 05 Dec 2023 09:51:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701798661; cv=none; d=google.com; s=arc-20160816; b=niLkSnKerJmuxgAqx0Ng1vfptr7RjHgwDYzBogBRSeMNqUWTsZM8XIpypNJohgahCz LiCls0LuuKeTjrpCGZ1C8z/kWeyLwAR8Mf5Z9LSsW/4FfWzSztt4OhSRbgJUjjjn5ZBa 70HMPyNM2pI+iiyD2vv7DB2zWdDfp5N3KUSQN1L4QWkNh8ObEUi4Te8d6rhlnWmBVfuD 57Y+av44AzgR353LM4e+Je0xhCgBaIcgN6GVFxQpjVl0SB8B1JK9Fq9+ncYGAQPNoGp2 bxmCgcjAKpebeJdQ/tlUZbFWf+0RcpKHXF7GBSv9ZgeuEyF5TdvX+LxlcSqy8bdd3lWI WfaQ== 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:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=JWhgpL4e6i6Z9Im0QBvWyMzLmXP3wPlkoP31YPGlwhc=; fh=bEvwa2WgyooGuXxrJL6kKHd4ON8IjQaFs0MnwMu/0yY=; b=SdUIFiYM8svTep1vKZ/4495htiCg9n8wb0KXQo77cM+ryqmV8NrdMdQ7PWTP4nCGSF ggAmyvbXJSyobYSnNr4CYMf6ZngFcUVxA+3ucGZjx/8NFDNIGi8mleEdZnbPT4VMmpBP k15W8KIGBdFFQwfZaD2BokFRLqTF1YH4tFIEOqRg0PBqJEVyLeOYntthmr+ZW5DDYDQX fr3E5uAqyiTRlRP/NUU0S7/5V1QQHI8ro3SM4OMP7SY3YW4XPcGcGZU4/L2JqIvBzHL8 UOzQ//iiYeHGGEiGur7sOS0qwdWWStQdBpy/roZvndh4dPcDl+F0N5JdKjzXzk1/e7t3 rOIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=cb0pshkD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id a14-20020a17090a688e00b00286e6c8b27csi999847pjd.9.2023.12.05.09.51.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 09:51:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=cb0pshkD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 7CF9B804C57C; Tue, 5 Dec 2023 09:50:58 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232110AbjLERun (ORCPT + 99 others); Tue, 5 Dec 2023 12:50:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232240AbjLERum (ORCPT ); Tue, 5 Dec 2023 12:50:42 -0500 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3783018F for ; Tue, 5 Dec 2023 09:50:47 -0800 (PST) Received: by mail-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-286de610668so250521a91.1 for ; Tue, 05 Dec 2023 09:50:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1701798647; x=1702403447; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=JWhgpL4e6i6Z9Im0QBvWyMzLmXP3wPlkoP31YPGlwhc=; b=cb0pshkDuiURIuHA4wSh6i0Y7csdWlIgEl9pyVwudjUUXDeB17Yta5wRtsgLl855WJ rP+5dgs8vyBlQZstokaNKMqCr+awmG+wKSKpI5TXbgJx4mka+nOY07AORmGF9Zml0Tr1 xWO/ket1oAjaeCKemsvVbM2d3iEtcyUP0t4+enCe/t5DTNESU1nLBBlZTjC7y/D0WUEN 39quAZ2N55jhAUXih03DuTQbLvomi/7rANRfO8r6gtw7o1Kv8ut9ET1bbBRDe8EgdLup fKvwCwn/A86Mai8fFlWhaQNdNoWeHoqBHtm8ApWmRvQkG4wnPqv7SqRFWbrbZZY9UDl0 ILkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701798647; x=1702403447; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JWhgpL4e6i6Z9Im0QBvWyMzLmXP3wPlkoP31YPGlwhc=; b=dsIbJA4mm8dlGQCuAlPZTgrmzvT8cZZRlAq20Jb2veuoqpfz5XCKOkYAuaKGBdBuR7 rh5m1FDR6GX1oFMshjLOvF+bIwKGCWYURaOjrvGMVJbYtgwX1oZJr0zqsKW/rBFyPd3A TENuvfXySMjgilzbqatRPAxYyZ+wJ3aFHzjzFBfC7ZhmwsqQgHvyOO7y1g3VfojRwndE 2WuxSqLjeK5aSYF/ae5FymR3Qfr00TRv43lsbKhkwJ1ySYhoBgXfAw6S+6IerhZZBJkG 844qp9GB0Heui3T9ggb7AjSw88l6lzXKLxh5XkoDboEfwqRiB1nb/scNBLQJOGCdFjoO 1oYg== X-Gm-Message-State: AOJu0YyQUTdSi5JZuh5gMtg6HoLlRHpp5PNgb3mMc7lEznt+3SDaakF6 WNR6TQ4zhoFFnuJQ1Df5odrJpl6CRZ9orISPcsS6hA== X-Received: by 2002:a17:90a:f98d:b0:286:f1b8:da7b with SMTP id cq13-20020a17090af98d00b00286f1b8da7bmr1210704pjb.0.1701798646622; Tue, 05 Dec 2023 09:50:46 -0800 (PST) Received: from [192.168.1.150] ([198.8.77.194]) by smtp.gmail.com with ESMTPSA id o12-20020a17090ac08c00b00286d905535bsm1704514pjs.0.2023.12.05.09.50.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Dec 2023 09:50:45 -0800 (PST) Message-ID: <206b634d-1d10-4057-ad8d-93e29fda5d6e@kernel.dk> Date: Tue, 5 Dec 2023 10:50:44 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4] tee: Use iov_iter to better support shared buffer registration Content-Language: en-US To: Arnaud POULIQUEN , Sumit Garg , Al Viro Cc: Jens Wiklander , Christoph Hellwig , op-tee@lists.trustedfirmware.org, linux-kernel@vger.kernel.org, Christian Brauner References: <20231129164439.1130903-1-arnaud.pouliquen@foss.st.com> <60b67bd5-36c3-4318-9a2b-bcf172681d45@foss.st.com> <40902a86-3b88-45bc-bb6f-2de0eb48dc9d@foss.st.com> <438a8b44-ea5f-4e13-bd7e-e1c2e2a481c4@kernel.dk> From: Jens Axboe In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,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 lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Tue, 05 Dec 2023 09:50:58 -0800 (PST) On 12/5/23 9:55 AM, Arnaud POULIQUEN wrote: > hi Jens Axboe, Al Viro, > > On 12/4/23 18:13, Jens Axboe wrote: >> On 12/4/23 10:02 AM, Arnaud POULIQUEN wrote: >>> Hi, >>> >>> On 12/4/23 17:40, Jens Axboe wrote: >>>> On 12/4/23 9:36 AM, Jens Axboe wrote: >>>>> On 12/4/23 5:42 AM, Sumit Garg wrote: >>>>>> IMO, access_ok() should be the first thing that import_ubuf() or >>>>>> import_single_range() should do, something as follows: >>>>>> >>>>>> diff --git a/lib/iov_iter.c b/lib/iov_iter.c >>>>>> index 8ff6824a1005..4aee0371824c 100644 >>>>>> --- a/lib/iov_iter.c >>>>>> +++ b/lib/iov_iter.c >>>>>> @@ -1384,10 +1384,10 @@ EXPORT_SYMBOL(import_single_range); >>>>>> >>>>>> int import_ubuf(int rw, void __user *buf, size_t len, struct iov_iter *i) >>>>>> { >>>>>> - if (len > MAX_RW_COUNT) >>>>>> - len = MAX_RW_COUNT; >>>>>> if (unlikely(!access_ok(buf, len))) >>>>>> return -EFAULT; >>>>>> + if (len > MAX_RW_COUNT) >>>>>> + len = MAX_RW_COUNT; >>>>>> >>>>>> iov_iter_ubuf(i, rw, buf, len); >>>>>> return 0; >>>>>> >>>>>> Jens A., Al Viro, >>>>>> >>>>>> Was there any particular reason which I am unaware of to perform >>>>>> access_ok() check on modified input length? >>>>> >>>>> This change makes sense to me, and seems consistent with what is done >>>>> elsewhere too. >>>> >>>> For some reason I missed import_single_range(), which does it the same >>>> way as import_ubuf() currently does - cap the range before the >>>> access_ok() check. The vec variants sum as they go, but access_ok() >>>> before the range. >>>> >>>> I think part of the issue here is that the single range imports return 0 >>>> for success and -ERROR otherwise. This means that the caller does not >>>> know if the full range was imported or not. OTOH, we always cap any data >>>> transfer at MAX_RW_COUNT, so may make more sense to fix up the caller >>>> here. >>>> >>> >>> Should we limit to MAX_RW_COUNT or return an error? Seems to me that >>> limiting could generate side effect later that could be not simple to >>> debug. >> >> We've traditionally just truncated the length, so principle of least >> surprise says we should continue doing that. >> > > > As Jens Wiklander has proposed using iov_iter_ubuf() instead of > import_ubuf(), should I propose a patch updating import_ubuf() and > import_single_range()? Or would you prefer that we keep the functions > unchanged for the time being? Arguably it should be consistent with iovec imports, which return the length (or error). But it might be safer to just check access_ok() first and then truncate at least, vs what is there now. Note that for 6.8 import_single_range() is gone as it was really just doing the same thing that import_ubuf() is. Any further changes in this area should CC Christian Brauner as well, as he has that staged in his tree. -- Jens Axboe