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 2B770CD11C2 for ; Wed, 10 Apr 2024 17:11:01 +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=QT2l9ltKTBgNz+R08coWSa0KfwmqyLR5a0nguBFZPFs=; b=qtGFg7NaEJJVpe kGQL1P5e0YEdEdNdz2kcv9zf1sANxKcm2q6HnRq7e8e2GD5RzPs2fCF4NTmyAe20INpH6X0+5BG/O AS88Bqf08pk+VcKvsUQaU4cFtte4Y5ro4F2lSGTq+8Lve40nR5z8XKGvn5pcBfDwe0ZSGftF42p0h lThx3+SSeYHDgZeBcIvvaSYb4Jt84T0hXiujXUUFdvNTL/iopJJ6IDIaK3ZqtisEpAmulcvknts1o zAZ6arbciunVy33HfRHcnufkv9kceBL3g88aTj+dPZBpwORQrzpUcHl30X9ptS520v/p+Tk0Ru1u8 aZ31sp8IbNRnyraI9toQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rubTH-00000008BAa-06Y8; Wed, 10 Apr 2024 17:10:51 +0000 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rubTD-00000008B8i-2ea9 for linux-arm-kernel@lists.infradead.org; Wed, 10 Apr 2024 17:10:49 +0000 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-416f04059beso5869675e9.1 for ; Wed, 10 Apr 2024 10:10:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712769042; x=1713373842; 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=jPAolQcDDgJY4OktndQFfIkIGL4ln6Jfg8j7dRhT7sM=; b=TJC2Rm+DDKRIZT7yob7yj2QtrcetUx2c1cuQvoC/FEbyrmFeus4hUQxlfQU7sYURFE HX/IHfkomsowLAXo+mkr9KQgTDxx6G762f3dQ8rN03tRDu/wvbTsjlJ/7hC39E3QRhlc gqivq9FXQaP/0yzyUSrNqpNcSZ/HTFtBlC//YEm5hREUw8LhrAit8P3G0HA9Mgx2D++i I3Z3NY34FTdqSM0YgdJvWS48EiXy1ZX9ZD0zSq9anJ6HRB9Fk9JMnJzNbSaHBdqIvO+n V+u38RaY5xrhiJckIJaTff682TyAEgo02RWk0EmSx5W3qy3fM32mj3e1MGb6QrjccSl7 lXLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712769042; x=1713373842; 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=jPAolQcDDgJY4OktndQFfIkIGL4ln6Jfg8j7dRhT7sM=; b=NEkezpy16gjp7y0OB/uvUFjvytuiU3YCMGVe36c2JdPUq3d5T2IfXVI2G22cVK709p 5MibfMIH4L2k5sVoCFOvKkMPBtFRbrRulkxM9tA1QYKra+amOHVtukKX7TtTP2pp1Eip R2qq6e5y6rdvxfBmOB34CHgzK/uAcX4EdLvESmagtvRMvHUGOX0KLFKhaE8UHlYt3bAN nM6NXMCAiEJ8gzbiFVAyCglHZnuaOwuDVQfAooY9IAP0499xL0QOhdCl31G0fsYVDOaY s+A+ivwuya03bMasN4d7WO5vITXQHhjydwlczhL5bltb5kY7lOY4d5NfHhzsG5djekY9 iWsg== X-Forwarded-Encrypted: i=1; AJvYcCVdiq7A+aj97FvggDMHpNMU0kbLNKiBeuzXJ/+IahdoUVS9IF9C8F9tjQ+A0SeFXYflSnCVAkboz6Wtlv2GpcUCM0r18Lzy3vghtHj3mUHZ4O/iyMM= X-Gm-Message-State: AOJu0YxGs8cSh/a76CIpd8GKDqeXfHWlMa6ySp9TpBSuUszMcsTTOmTt T0qsPEJNB9Wrq+VQNWRVTLenA54ho2EKYYpwI9rCU6PQYJxGO2jN0DQ3A9tTPA== X-Google-Smtp-Source: AGHT+IFuiUBGc1CYJe0Ub3hOpD127J9JpZKYHIWmsNnnCQ5/iQn3KNoIGFXIGnRIbSfXm9fkSnUotg== X-Received: by 2002:a05:6000:225:b0:346:4d41:8d5a with SMTP id l5-20020a056000022500b003464d418d5amr1974050wrz.56.1712769041816; Wed, 10 Apr 2024 10:10:41 -0700 (PDT) Received: from google.com (161.126.77.34.bc.googleusercontent.com. [34.77.126.161]) by smtp.gmail.com with ESMTPSA id j11-20020adff54b000000b003433bf6651dsm13429411wrp.75.2024.04.10.10.10.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 10:10:41 -0700 (PDT) Date: Wed, 10 Apr 2024 18:10:37 +0100 From: Vincent Donnefort To: Sebastian Ene 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-20240410_101047_783145_2C347526 X-CRM114-Status: GOOD ( 32.32 ) 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 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. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel