From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9B6EFCD1292 for ; Thu, 11 Apr 2024 09:03:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=9EY5ThzQLQv79EgYG1KmGUmuom8Wnw+65jDHAYEqCYs=; b=w4d866OD8urHzt EdFTsCtMByNXWUbp8+NeDZ9FlnJ/PQzg8JHm/xhKQ10MkwXJJRx4WE19nEiOjoQRv6r2AMUF4oR5D u+wxG8zohPu9fdJ/60HeuuPIHoYm7WxBXCu9MYrbo0V+YrByp8GdcqNWOH4QhHRhxs6xkMAnf09Z3 Ri21zJAKBNKGduZ/2zkcvAQ5KrHOProHCWIJvxovO3C6zz308u+l9RBDgTlQBt3omzdIRBPxHFoT+ ERYrpJZqiry2nC5kBSzOjvZe93pW6vpzPsBUqSeVhU/LykeURKPtvr+vPLPj33pldwUjuW9rC7wsV VmXjQlrVrrQ8MRCzxvqQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1ruqL8-0000000BDta-1gg2; Thu, 11 Apr 2024 09:03:26 +0000 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1ruqKz-0000000BDsO-1ddg for linux-arm-kernel@lists.infradead.org; Thu, 11 Apr 2024 09:03:25 +0000 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-41687826509so59695e9.1 for ; Thu, 11 Apr 2024 02:03:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712826195; x=1713430995; darn=lists.infradead.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=QqfSLSB/AB48WWgXAVHlYTdSSFdUvK5wajBEFofuXQg=; b=Kc6CgIfEquuJNIPkoyogtoF00UNrsTmH+1vWHizbfxd8WfyckfPEc263OZ9pUDyzg8 /W7B7tYiq9NUODX6Lw6SiGvlh5keGrd3mu/1x8oVgSuNX6Kajf1M7HFcLXxGLTi0Yok7 wfEE/QlSrjVkLbCdeuuPhUA9xP2UcRcfMYYpWsE6YLFmn+2vbcjJtPcv8o+ioqKf5pwi oJrZX0UJNwVs32XMLvWeEVkRoGmquEmlW1PZMv9m12saOR0QFpWiSb2srt8Uda+Kdpyx PyLHChcXw+CqG+Pt6GlI9lMYCWc1tAEgomKzWTvWkBUT+4Ly7Mh7sPH7u1v7jPy7AbZY F55g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712826195; x=1713430995; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=QqfSLSB/AB48WWgXAVHlYTdSSFdUvK5wajBEFofuXQg=; b=BKXkaqfujmk3Nn2LzEiqgjhI+Oxr94NbHx/Nt1lupQ3lpacbD+8sNLy1rAyIHU7d2G uk59rXp61tamURL0c1PKa1qD/BAqey6FM4j8tE53TCdL9meNulv8tstWWn5ZnnsF2UXj 12J74/Bi2kTQIHiKK0hh9oabHHcpYshvaJMo+9TTQDmvJ61aLbnzWtFhSJliWeknAAPE LWxwcEbTfKp7iY/gCWSbpRTmk6Yal2oU9gtynJkF9uAag7KwDrqoxxHAyoXFexvCIsjO pev9NIZd4kiY3x4cyT3vu57+uxz7ID27+xixUINCJ3s9NFWXlsTNjdcvuqN2VLhLfTzm bQeQ== X-Forwarded-Encrypted: i=1; AJvYcCW9/jXvo1b7JPrf1Ny+zAesTcPxgRM2rRJ6ObNDpylDiGN40vztIHQvgPP5esUyIEo98q/0ttZ2axXyZfV/Tgs3QKysM6FkGe3JxNjSnhVfDSVtkws= X-Gm-Message-State: AOJu0Yzz2VD+1vWZwbcUWTT6ubs8M7Gd+LitGSDtMoezYOZ9OktfrVIK pCsXyto3aEIDMhTSSVhXSqarKDem6wyGI+d0BZEU1hlVX7XboLXVPrBTWnaDDg== X-Google-Smtp-Source: AGHT+IH78w0bgEGjDyrKEfk+d9ic/SSQTwVwM1da8T9d732zT8YK/kjBPq2FLqf/BbcoknBcTcJF2A== X-Received: by 2002:a05:600c:3d93:b0:417:d73e:b3de with SMTP id bi19-20020a05600c3d9300b00417d73eb3demr95804wmb.0.1712826195396; Thu, 11 Apr 2024 02:03:15 -0700 (PDT) Received: from google.com (248.199.140.34.bc.googleusercontent.com. [34.140.199.248]) by smtp.gmail.com with ESMTPSA id c18-20020a5d5292000000b00341b451a31asm1271306wrv.36.2024.04.11.02.03.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 02:03:15 -0700 (PDT) Date: Thu, 11 Apr 2024 09:03:13 +0000 From: Sebastian Ene To: Vincent Donnefort Cc: catalin.marinas@arm.com, james.morse@arm.com, jean-philippe@linaro.org, maz@kernel.org, oliver.upton@linux.dev, qperret@google.com, qwandor@google.com, sudeep.holla@arm.com, suzuki.poulose@arm.com, tabba@google.com, will@kernel.org, yuzenghui@huawei.com, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com Subject: Re: [PATCH] KVM: arm64: Add support for FFA_PARTITION_INFO_GET Message-ID: References: <20240409151908.541589-1-sebastianene@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240411_020319_376912_B2F27700 X-CRM114-Status: GOOD ( 35.95 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Apr 10, 2024 at 06:10:37PM +0100, Vincent Donnefort wrote: Hi Vincent, > On Wed, Apr 10, 2024 at 10:18:18AM +0000, Sebastian Ene wrote: > > On Wed, Apr 10, 2024 at 10:53:31AM +0100, Vincent Donnefort wrote: > > > [...] > > > > > > > > > +static void do_ffa_part_get(struct arm_smccc_res *res, > > > > > > + struct kvm_cpu_context *ctxt) > > > > > > +{ > > > > > > + DECLARE_REG(u32, uuid0, ctxt, 1); > > > > > > + DECLARE_REG(u32, uuid1, ctxt, 2); > > > > > > + DECLARE_REG(u32, uuid2, ctxt, 3); > > > > > > + DECLARE_REG(u32, uuid3, ctxt, 4); > > > > > > + DECLARE_REG(u32, flags, ctxt, 5); > > > > > > + u32 off, count, sz, buf_sz; > > > > > > + > > > > > > + hyp_spin_lock(&host_buffers.lock); > > > > > > + if (!host_buffers.rx) { > > > > > > + ffa_to_smccc_res(res, FFA_RET_INVALID_PARAMETERS); > > > > > > + goto out_unlock; > > > > > > + } > > > > > > + > > > > > > + arm_smccc_1_1_smc(FFA_PARTITION_INFO_GET, uuid0, uuid1, > > > > > > + uuid2, uuid3, flags, 0, 0, > > > > > > + res); > > > > > > + > > > > > > + if (res->a0 != FFA_SUCCESS) > > > > > > + goto out_unlock; > > > > > > + > > > > > > + count = res->a2; > > > > > > + if (!count) > > > > > > + goto out_unlock; > > > > > > > > > > Looking at the table 13.34, it seems what's in "count" depends on the flag. > > > > > Shouldn't we check its value, and only memcpy into the host buffers if the flag > > > > > is 0? > > > > > > > > > > > > > When the flag is `1` the count referes to the number of partitions > > > > deployed. In both cases we have to copy something unless count == 0. > > > > > > I see "Return the count of partitions deployed in the system corresponding to > > > the specified UUID in w2" > > > > > > Which I believe means nothing has been copied in the buffer? > > > > > > > When the flag in w5 is 1 the size argument stored in w3 will be zero and > > the loop will not be executed, so nothing will be copied to the host > > buffers. > > Ha right, all good here then. > > > > > > > > > > > > > + > > > > > > + if (ffa_version > FFA_VERSION_1_0) { > > > > > > + buf_sz = sz = res->a3; > > > > > > + if (sz > sizeof(struct ffa_partition_info)) > > > > > > + buf_sz = sizeof(struct ffa_partition_info); > > > > > > > > > > What are you trying to protect against here? We have to trust EL3 anyway, (as > > > > > other functions do). > > > > > > > > > > The WARN() could be kept though to make sure we won't overflow our buffer. But > > > > > it could be transformed into an error? FFA_RET_ABORTED? > > > > > > > > > > > > > > > > > > I think we can keep it as a WARN_ON because it is not expected to have > > > > a return code of FFA_SUCCESS but the buffer to be overflown. The TEE is > > > > expected to return NO_MEMORY in w2 if the results cannot fit in the RX > > > > buffer. > > > > > > WARN() is crashing the hypervisor. It'd be a shame here as we can easily recover > > > by just sending an error back to the caller. > > > > I agree with you but this is not expected to happen unless TZ messes up > > something/is not complaint with the spec, in which case I would like to > > catch this. > > Hum, still I don't see the point in crashing anything here, nothing is > compromised. The driver can then decide what to do based on that reported > failure. I still think we should keep this (as we discussed offilne). We do WARN_ON when the behaviour doesn't follow the spec guidelines. For this particular case, if the result doesn't fit in the caller's buffer the TEE is expected to return FFA_ERROR in w0 with NO_MEMORY in w2. If it returns success but the caller doesn't have enough space to copy then something is going horribly wrong on the TEE side. Thanks, Seb _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel