From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 09DD632D7C7; Thu, 21 May 2026 12:12:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779365576; cv=none; b=dz2r2IC9D25kgOlOTsMQH24ljjddounSZ6TrkjgKdZdC4khPMsG0/Bu1pmktKJKhKL0AHrOoiCuKpCvrgbgqyDvA8F+6u61duKpUWVmgkY1ZUPCYfep+QSvRVQIqmKzNMsGSROse296PWEPbcq4lU4hwgYHM5kQcxz4zWMynbbA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779365576; c=relaxed/simple; bh=Cf0gkJ/hqVpBhd7UkFOvMBJKVL30EatSj5Ex55m5CfE=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=spYvNJDnK/Pxup1ERILw5J02q9kEN76r4PckiFB3bUorVjbfYm8ahXetJF5WZe4cKkVaLsFs4VoHjR4UkBxMczpoIUAGZgKfITRqLi5HY8pxi2MkN05yF7W2s5q9FeWuIkyq02CN7HcfT31y2pUkJ3tlEPRH51QdMao2LyeSQpI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cdqQBgdX; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cdqQBgdX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D63C1F00A3B; Thu, 21 May 2026 12:12:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779365574; bh=QXychn9L0mxdWwBTB7z2HXwk+PRqle39TGYH6NUQk0Y=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=cdqQBgdX4gUwX9OmhPoMjIGM/CW9yfN8zKNNFcfBWKNEQtv1iwpnD8xXmH+Ovdt6g Nb9QE/CeAVzuJ03zyLL92uN51RT04aSQl/xFznE6tRiHlf58QJaBsJWwrU0lje0k8w YnTKt8FQfFlOiPplGA9LmCV9emUvVMZQmScmiqmCFRwId/JxVtQOpE/FyU9Fe6QPIu dfj0QgZh8bgn0f2dB9uTTmSkp6hXfRzHMgh9Vo6s6BFgzw16Vf4QyyHsIXOQG7aQ4N 65bYEZEcX95fQ4AkCJwsGS9EtUycxiIMj3VzkGIlvAs7zKOawjeHqzeCDfurqg0I+Z LKZiUfpBAQygQ== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wQ2Gi-00000004o66-1DzI; Thu, 21 May 2026 12:12:52 +0000 Date: Thu, 21 May 2026 13:12:51 +0100 Message-ID: <86h5o1vu4c.wl-maz@kernel.org> From: Marc Zyngier To: Mostafa Saleh Cc: op-tee@lists.trustedfirmware.org, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, oupton@kernel.org, joey.gouly@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, jens.wiklander@linaro.org, sumit.garg@kernel.org, sebastianene@google.com, vdonnefort@google.com, sudeep.holla@kernel.org Subject: Re: [PATCH v4 4/5] KVM: arm64: Fix bounds checking in do_ffa_mem_reclaim() In-Reply-To: References: <20260520204948.2440882-1-smostafa@google.com> <20260520204948.2440882-5-smostafa@google.com> <86ldddw4ht.wl-maz@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: smostafa@google.com, op-tee@lists.trustedfirmware.org, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, oupton@kernel.org, joey.gouly@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, jens.wiklander@linaro.org, sumit.garg@kernel.org, sebastianene@google.com, vdonnefort@google.com, sudeep.holla@kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On Thu, 21 May 2026 11:43:58 +0100, Mostafa Saleh wrote: >=20 > On Thu, May 21, 2026 at 11:30=E2=80=AFAM Mostafa Saleh wrote: > > > > Hi Marc, > > > > On Thu, May 21, 2026 at 09:28:46AM +0100, Marc Zyngier wrote: > > > On Wed, 20 May 2026 21:49:47 +0100, > > > Mostafa Saleh wrote: > > > > > > > > Sashiko (locally) reports out of bound write possiblity if SPMD > > > > returns an invalid data. > > > > > > > > While SPMD is considered trusted, pKVM does some basic checks, > > > > for offset to be less than or equal len. > > > > > > > > However, that is incorrect as even if the offset is smaller than > > > > len pKVM can still access out of bound memory in the next > > > > ffa_host_unshare_ranges(). > > > > > > > > Split this check into 2: > > > > 1- Check that the fixed portion of the descriptor fits. > > > > 2- After getting reg, check the variable array size addr_range_cnt > > > > fits. > > > > > > > > Signed-off-by: Mostafa Saleh > > > > --- > > > > arch/arm64/kvm/hyp/nvhe/ffa.c | 7 ++++++- > > > > 1 file changed, 6 insertions(+), 1 deletion(-) > > > > > > > > diff --git a/arch/arm64/kvm/hyp/nvhe/ffa.c b/arch/arm64/kvm/hyp/nvh= e/ffa.c > > > > index 1af722771178..e6aa2bfa63b1 100644 > > > > --- a/arch/arm64/kvm/hyp/nvhe/ffa.c > > > > +++ b/arch/arm64/kvm/hyp/nvhe/ffa.c > > > > @@ -607,7 +607,7 @@ static void do_ffa_mem_reclaim(struct arm_smccc= _1_2_regs *res, > > > > * check that we end up with something that doesn't look _compl= etely_ > > > > * bogus. > > > > */ > > > > - if (WARN_ON(offset > len || > > > > + if (WARN_ON(offset + CONSTITUENTS_OFFSET(0) > len || > > > > fraglen > KVM_FFA_MBOX_NR_PAGES * PAGE_SIZE)) { > > > > > > Do you really want to keep this a WARN_ON(), given that this results > > > in a panic in most pKVM configurations? > > > > Which kind of configuration will that check fail on? > > Does that mean at the moment pKVM does out-of-bound access for > > the header? > > > I might have misunderstood the point. I thought you meant the new > change would cause a panic on most configurations, or were you > suggesting just removing the WARN_ON? Just dropping the WARN_ON(), because for most users, that means just killing the machine (only configurations with debug will give you a stack trace). > I can do that, I just updated the current faulty check and left the > WARN_ON as is. I'd be all for that. Thanks, M. --=20 Without deviation from the norm, progress is not possible. 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 lists.trustedfirmware.org (lists.trustedfirmware.org [18.214.241.189]) (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 AECA7CD4F5E for ; Thu, 21 May 2026 12:13:02 +0000 (UTC) Received: from lists.trustedfirmware.org (localhost [127.0.0.1]) by lists.trustedfirmware.org (Postfix) with ESMTP id D0084444F0 for ; Thu, 21 May 2026 12:13:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=lists.trustedfirmware.org; s=2024; t=1779365581; bh=Cf0gkJ/hqVpBhd7UkFOvMBJKVL30EatSj5Ex55m5CfE=; h=Date:To:Subject:In-Reply-To:References:CC:List-Id:List-Archive: List-Help:List-Owner:List-Post:List-Subscribe:List-Unsubscribe: From:Reply-To:From; b=V4PzPOU2URuMa106hdYtFD6f2hDMcQ+ThiFjz8A+H0nCOd/YM0LtvryL0YL/rlv6Z R2wALa5YpsPUGpEaH/oreFXM39MlBH8tNEeiW8KlYfQS0ZA8KJAB7I7upNRMty25Ix qwgZ2oS4aUIE/TRhuhdHoPq6vqj/gXm1sXV7SoSKVf/wy211/Pim0zf90y3A5WvP7O 11tR7jM6whf7L9m+zIQ4rQ1fu62SoIRBMGG0po/0dukpLTi52uZcxej2QVGGYmREiO a9bnM20sq1Y7IjVxPA0khfY1dTdBDSwgFXz6Oox6Tq0MluOwTEUvEkm0VxsdDDM2ug cI81o33HMPa5A== Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by lists.trustedfirmware.org (Postfix) with ESMTPS id 2051241BB7 for ; Thu, 21 May 2026 12:12:55 +0000 (UTC) Authentication-Results: lists.trustedfirmware.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=cdqQBgdX; dkim-atps=neutral Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id B755F60210; Thu, 21 May 2026 12:12:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D63C1F00A3B; Thu, 21 May 2026 12:12:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779365574; bh=QXychn9L0mxdWwBTB7z2HXwk+PRqle39TGYH6NUQk0Y=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=cdqQBgdX4gUwX9OmhPoMjIGM/CW9yfN8zKNNFcfBWKNEQtv1iwpnD8xXmH+Ovdt6g Nb9QE/CeAVzuJ03zyLL92uN51RT04aSQl/xFznE6tRiHlf58QJaBsJWwrU0lje0k8w YnTKt8FQfFlOiPplGA9LmCV9emUvVMZQmScmiqmCFRwId/JxVtQOpE/FyU9Fe6QPIu dfj0QgZh8bgn0f2dB9uTTmSkp6hXfRzHMgh9Vo6s6BFgzw16Vf4QyyHsIXOQG7aQ4N 65bYEZEcX95fQ4AkCJwsGS9EtUycxiIMj3VzkGIlvAs7zKOawjeHqzeCDfurqg0I+Z LKZiUfpBAQygQ== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wQ2Gi-00000004o66-1DzI; Thu, 21 May 2026 12:12:52 +0000 Date: Thu, 21 May 2026 13:12:51 +0100 Message-ID: <86h5o1vu4c.wl-maz@kernel.org> To: Mostafa Saleh Subject: Re: [PATCH v4 4/5] KVM: arm64: Fix bounds checking in do_ffa_mem_reclaim() In-Reply-To: References: <20260520204948.2440882-1-smostafa@google.com> <20260520204948.2440882-5-smostafa@google.com> <86ldddw4ht.wl-maz@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: smostafa@google.com, op-tee@lists.trustedfirmware.org, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, oupton@kernel.org, joey.gouly@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, jens.wiklander@linaro.org, sumit.garg@kernel.org, sebastianene@google.com, vdonnefort@google.com, sudeep.holla@kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-Rspamd-Action: no action X-Spamd-Result: default: False [-4.00 / 15.00]; BAYES_HAM(-3.00)[99.99%]; DWL_DNSWL_LOW(-1.00)[kernel.org:dkim]; MID_CONTAINS_FROM(1.00)[]; DMARC_POLICY_ALLOW(-0.50)[kernel.org,quarantine]; R_SPF_ALLOW(-0.20)[+ip4:172.105.4.254]; R_DKIM_ALLOW(-0.20)[kernel.org:s=k20260515]; MIME_GOOD(-0.10)[text/plain]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:63949, ipnet:172.105.0.0/19, country:SG]; RCPT_COUNT_TWELVE(0.00)[14]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; NEURAL_HAM(-0.00)[-1.000]; RCVD_TLS_LAST(0.00)[]; FROM_HAS_DN(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DKIM_TRACE(0.00)[kernel.org:+] X-Rspamd-Server: lists.trustedfirmware.org X-Rspamd-Queue-Id: 2051241BB7 X-Spamd-Bar: --- Message-ID-Hash: GEHFY2TEYJKJOQDP55UW3A4XHLULMGOX X-Message-ID-Hash: GEHFY2TEYJKJOQDP55UW3A4XHLULMGOX X-MailFrom: maz@kernel.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-op-tee.lists.trustedfirmware.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: op-tee@lists.trustedfirmware.org, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, oupton@kernel.org, joey.gouly@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, sumit.garg@kernel.org, sebastianene@google.com, vdonnefort@google.com, sudeep.holla@kernel.org X-Mailman-Version: 3.3.5 Precedence: list List-Id: Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Marc Zyngier via OP-TEE Reply-To: Marc Zyngier On Thu, 21 May 2026 11:43:58 +0100, Mostafa Saleh wrote: >=20 > On Thu, May 21, 2026 at 11:30=E2=80=AFAM Mostafa Saleh wrote: > > > > Hi Marc, > > > > On Thu, May 21, 2026 at 09:28:46AM +0100, Marc Zyngier wrote: > > > On Wed, 20 May 2026 21:49:47 +0100, > > > Mostafa Saleh wrote: > > > > > > > > Sashiko (locally) reports out of bound write possiblity if SPMD > > > > returns an invalid data. > > > > > > > > While SPMD is considered trusted, pKVM does some basic checks, > > > > for offset to be less than or equal len. > > > > > > > > However, that is incorrect as even if the offset is smaller than > > > > len pKVM can still access out of bound memory in the next > > > > ffa_host_unshare_ranges(). > > > > > > > > Split this check into 2: > > > > 1- Check that the fixed portion of the descriptor fits. > > > > 2- After getting reg, check the variable array size addr_range_cnt > > > > fits. > > > > > > > > Signed-off-by: Mostafa Saleh > > > > --- > > > > arch/arm64/kvm/hyp/nvhe/ffa.c | 7 ++++++- > > > > 1 file changed, 6 insertions(+), 1 deletion(-) > > > > > > > > diff --git a/arch/arm64/kvm/hyp/nvhe/ffa.c b/arch/arm64/kvm/hyp/nvh= e/ffa.c > > > > index 1af722771178..e6aa2bfa63b1 100644 > > > > --- a/arch/arm64/kvm/hyp/nvhe/ffa.c > > > > +++ b/arch/arm64/kvm/hyp/nvhe/ffa.c > > > > @@ -607,7 +607,7 @@ static void do_ffa_mem_reclaim(struct arm_smccc= _1_2_regs *res, > > > > * check that we end up with something that doesn't look _compl= etely_ > > > > * bogus. > > > > */ > > > > - if (WARN_ON(offset > len || > > > > + if (WARN_ON(offset + CONSTITUENTS_OFFSET(0) > len || > > > > fraglen > KVM_FFA_MBOX_NR_PAGES * PAGE_SIZE)) { > > > > > > Do you really want to keep this a WARN_ON(), given that this results > > > in a panic in most pKVM configurations? > > > > Which kind of configuration will that check fail on? > > Does that mean at the moment pKVM does out-of-bound access for > > the header? > > > I might have misunderstood the point. I thought you meant the new > change would cause a panic on most configurations, or were you > suggesting just removing the WARN_ON? Just dropping the WARN_ON(), because for most users, that means just killing the machine (only configurations with debug will give you a stack trace). > I can do that, I just updated the current faulty check and left the > WARN_ON as is. I'd be all for that. Thanks, M. --=20 Without deviation from the norm, progress is not possible.