From patchwork Mon Jan 8 12:34:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Marussi X-Patchwork-Id: 13513418 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 DA8FBC3DA6E for ; Mon, 8 Jan 2024 12:35:20 +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:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=7KBIfaD7kDDH9NadWDgX5QvUKYRDSnIXPtpGNRdIPCs=; b=c3vdrKCaUNvbRt yopKplTVQJc7BWduHGadVbuc+6w+nEzo8RSpb+SGWOp9W9yNIrUHAT1C0JzhWlZ1v5WidOkOFur4X dMwx8ZAy/+sjpXYwvrVY010XdM3nFtetZxkIcaLbDxKSaPM9jTdD6ZUkD0omoAfuOk+e8w4jt6293 slxZFCUlUJvKFuaNQSOMo+lKyhfR6KKwS1vL1A+UEKRtV9/LHkGM+amMG79TS4bBzB4d16t6T+fJL gXA+Hf5Cnf2A6aRTTNYeMOK7xfteMfAOvGncl3DKlaH8ckskQcLhPNG0Wakr8go6LPE9LsrpH/xwy SI33XVFnAS3GiZuGHEig==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rMoqG-0054Vh-0x; Mon, 08 Jan 2024 12:34:56 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rMoqB-0054SK-1e for linux-arm-kernel@lists.infradead.org; Mon, 08 Jan 2024 12:34:52 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C60051480; Mon, 8 Jan 2024 04:35:34 -0800 (PST) Received: from [127.0.1.1] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 28D113F64C; Mon, 8 Jan 2024 04:34:48 -0800 (PST) From: Cristian Marussi Date: Mon, 08 Jan 2024 12:34:13 +0000 Subject: [PATCH 3/6] firmware: arm_ffa: Check xa_load() return value MIME-Version: 1.0 Message-Id: <20240108-ffa_fixes_6-8-v1-3-75bf7035bc50@arm.com> References: <20240108-ffa_fixes_6-8-v1-0-75bf7035bc50@arm.com> In-Reply-To: <20240108-ffa_fixes_6-8-v1-0-75bf7035bc50@arm.com> To: Sudeep Holla Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Cristian Marussi X-Mailer: b4 0.12.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240108_043451_606426_4F326560 X-CRM114-Status: UNSURE ( 8.46 ) X-CRM114-Notice: Please train this message. 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add a check to verify the result of xa_load() during partition lookups. Fixes: 0184450b8b1e ("firmware: arm_ffa: Add schedule receiver callback mechanism") Signed-off-by: Cristian Marussi --- drivers/firmware/arm_ffa/driver.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index 8df92c9521f4..0ea1dd6e55c4 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -733,6 +733,11 @@ static void __do_sched_recv_cb(u16 part_id, u16 vcpu, bool is_per_vcpu) void *cb_data; partition = xa_load(&drv_info->partition_info, part_id); + if (!partition) { + pr_err("%s: Invalid partition ID 0x%x\n", __func__, part_id); + return; + } + read_lock(&partition->rw_lock); callback = partition->callback; cb_data = partition->cb_data; @@ -915,6 +920,11 @@ static int ffa_sched_recv_cb_update(u16 part_id, ffa_sched_recv_cb callback, return -EOPNOTSUPP; partition = xa_load(&drv_info->partition_info, part_id); + if (!partition) { + pr_err("%s: Invalid partition ID 0x%x\n", __func__, part_id); + return -EINVAL; + } + write_lock(&partition->rw_lock); cb_valid = !!partition->callback;