Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2855967rdb; Mon, 4 Dec 2023 09:14:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IGAKK7cYpOjwu5NFLpKfvulwbkzLi66bSlt+pCwM67h8eWkzyOg0GHcvrtQS3NveJcLEH8z X-Received: by 2002:a05:6a00:4305:b0:6bd:4ab7:5f69 with SMTP id cb5-20020a056a00430500b006bd4ab75f69mr5696175pfb.12.1701710044979; Mon, 04 Dec 2023 09:14:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701710044; cv=none; d=google.com; s=arc-20160816; b=EIalLvG1uZo7r/tgEEuVVdiCFJBVgJiB6LVUMn12KNoiNwH0CRryb8WS+KlCVCrhfA F1tgKNKS7sqPR6mY+xbSIxUePpVVfLwHJ9uuKct4+GNKvVhjVFFodE/SeqVkF+gmWTlP JsqyABi1VViFoUpgdIUW9Q1GQSyAMK/bCvqLIzExU9z922xD3c1EsbEedOVmFohY1+CV GoRjXMEJqkEGbLl24SKxRzhagnyYKQeGRr/djuA5UxxMN+NJwLsH8brNoG2ASDD5OeYT 0BEvoaflu60Ep9HqPwPli5dThrla+EdB9FcrNLH2rKqrlwfRg3TLWgAatJpbNC6ZSh9w UR7A== 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=FJb5w96o8AFv9S3GsF57g52p9vLO3PzFaADoxV+ON/E=; fh=vzydchfydnnAnaXZmI4RMFXGUjsb1Y/xu5ANtUGVyrw=; b=PGD4A6n32192gA44aBV4pNVwpsOuKNPXRHEd3Z1q2F0nwbZhREWICX1Dl5XEzS5MMK Rr3hWDAD8i3WZ7Ubul6UzA/rxQiNDbMkol6peBjtUWcsr6p+rHVjpzit9Gw8nBo2XFQA N+go1LPYw+AUToLk1Tooj/8K9Xz1HJTAR2H5QvIEKwvmJoK9dHJ/UjOMSts9cOa7VwBj q4WcHwyrGcRKC+Mql5T5TUEDbPlWA7XVsZsd1QjlRwkzsRkvSkXsDIjwhaoHEFYFlo7O MX7W7aLIe/TSPde/DfJ7/FquaoikDl+9661ih2GbS4lHg4vudYZDxCRnp2HoZYOQIA2S Md/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=r1VtWPNI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id cr8-20020a056a000f0800b006cb537d7b47si3515145pfb.309.2023.12.04.09.14.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 09:14:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=r1VtWPNI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id B500680AB1FE; Mon, 4 Dec 2023 09:14:03 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231177AbjLDRNv (ORCPT + 99 others); Mon, 4 Dec 2023 12:13:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229542AbjLDRNs (ORCPT ); Mon, 4 Dec 2023 12:13:48 -0500 Received: from mail-io1-xd34.google.com (mail-io1-xd34.google.com [IPv6:2607:f8b0:4864:20::d34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4916783 for ; Mon, 4 Dec 2023 09:13:54 -0800 (PST) Received: by mail-io1-xd34.google.com with SMTP id ca18e2360f4ac-7b393fd9419so33101639f.0 for ; Mon, 04 Dec 2023 09:13:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1701710033; x=1702314833; 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=FJb5w96o8AFv9S3GsF57g52p9vLO3PzFaADoxV+ON/E=; b=r1VtWPNIRS4ZNxGKGTgo9KUFw1ZXYHaKbgLra2Le+YTs7uhV+iuzitmPKGWOeGL/1O 64Xf0wDmj6Dg5bgI2xhWaaQVgzsVdGePLk50urnOZA+rfUR4akze68RjGRHOBG3SNXSs EDrzVR+u2robxBNUt3nL611VBDBoc96QqyB+nS97rjvg7dyOvTy+Oqqj4Jj0Gjyaru8L yoifmgyGNADDnD+WSpB+Vnj3rM+AqEEqfh/aUD9U1ORmmDN56/ifvE+a9K2+uR+7nmgj 1Wx/yR3Av0xZJDcXRvkVclub1LFX9KXqU10oMJ37kSKXo/3g36o9nok4o0QPvju5mElv FqmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701710033; x=1702314833; 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=FJb5w96o8AFv9S3GsF57g52p9vLO3PzFaADoxV+ON/E=; b=VfQg0Hg1gBEeX5c1QpFEI4P1lHHeq9hJhT6Bd4CWZMXp2kOEo5qxqEBExb/PtPVwMg Tm75hNEjuksivXwo+Lg/Lz/2FookSFbM9v9nbgQ2qJlgWF40MYBG4Pnn9uwgq2RYlzzp HtNdq0tFkUgWeKVlHE01zr9h7qg5+fRDtRhB4VEA7LKyLnJz8Bjp45uUu8bHMIv3Qx5S MMef8DYzfaXpbDyRzd7t+eCGmlDmebjnuB7b2ssKP/BRggjJFPtYEi6uV7/kV/Zspvhd FFq5w/b0A+9RzUt+eboiCnIBt7f0+nd4Bpih/C1uENq1ZXEXEYCrwsw4Aez7Pnm+RulZ 2Now== X-Gm-Message-State: AOJu0YxZSsNfSJ27gv51cVvpPAikSw6qAmulFOvYtSDjDKGmyDH1/Uic GpLW/pwZ+vUCnY3XU5fD75MSuw== X-Received: by 2002:a05:6602:2245:b0:7b3:5be5:fa55 with SMTP id o5-20020a056602224500b007b35be5fa55mr32708602ioo.2.1701710033582; Mon, 04 Dec 2023 09:13:53 -0800 (PST) Received: from [192.168.1.116] ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id p24-20020a02b898000000b0046651cf4d98sm2657679jam.78.2023.12.04.09.13.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Dec 2023 09:13:38 -0800 (PST) Message-ID: Date: Mon, 4 Dec 2023 10:13:29 -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 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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, 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-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 04 Dec 2023 09:14:03 -0800 (PST) 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. -- Jens Axboe