From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (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 C952D388396 for ; Tue, 7 Jul 2026 06:12:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783404727; cv=none; b=iWa3SykxaYwaComgNYJf11kocugo3SRz7waT2qLqqZTyi9XaVOtwwF/ndyNAI76JJkG/XCVW57UvHKjvzCtp39vI9XrJWo0FnQfA3aVWSAlbQKW5XVGEC7g9/T0tVjPaUG2vHie4hyeVSCzm7d+G5e4PAgiiYmhzt869gJoCfVk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783404727; c=relaxed/simple; bh=swwFCmvhnGXLtV5EjzA1jpj0y1exqoHCd9lIGCRTTXQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nA3US5vIF+zujyJlYoec5Pi9yA4OxMXGFIwJEJ1Hlv80r/53C8POn5Jy3LdFORkIHt5lzc2HkowhrSrIpaXr/QCpHt83hy+/RnUT4dL772WnPpjy8PTQFQVsl8amx1ko4lWSGFjV0IcCj0Gf3OB+EW6Zb+rlCLBj7A201ye/mQ4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=MgzdsOOT; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=OdecdnP/; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="MgzdsOOT"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="OdecdnP/" Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 667495JI2526330 for ; Tue, 7 Jul 2026 06:12:05 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= N4XA902sDhftTe3c8fF1ABgOsUEkFzIp03BayNh/XVE=; b=MgzdsOOT5RJ9e31e hc3ZIEwiV1AkpBSL/D4Gc2Cge35bG4qmW1gYn2At0m0ZK9L5smuDwgcI6vKHJ+uM bAw9A/oY44UpE+gLSS8V80ENUhyBKz4kwVINI2TN187Fqh62YmpGqp6R/HsDfI9v LAn7cMGZ6KWhTCxOAaE6CYgGkz10Tz0gC3WcAJNnL7o40RODPt6KoE0b2Jx/kDX+ r5fjNe4X6EQnz5pG+PJdR74W2VWdyd6M2pDnJNTZkySu7k/R729UQs0Zh9b1etqv 6m7LvxzJltaYZnb5F9XlzRp0T4iBOzZB6OdvAyigSmSu0Cguei+ZqRivG0L7pn+z zIg5QQ== Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4f8a98ma6h-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 07 Jul 2026 06:12:04 +0000 (GMT) Received: by mail-pf1-f198.google.com with SMTP id d2e1a72fcca58-8478947e047so7410522b3a.3 for ; Mon, 06 Jul 2026 23:12:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1783404724; x=1784009524; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=N4XA902sDhftTe3c8fF1ABgOsUEkFzIp03BayNh/XVE=; b=OdecdnP/lzBlXwFLh8eVpPW2EB9gGmN2oKPZe/C06+YGIg/tX9U+8+o0gxAVlJ+g+T h3vH0XhRcLzKwC3vCA2NORrboEnN1ED8cpD0rCNd0V+upCRYcUv+ZCJPrSc02D+h+42b 091yDwPBpBacQlohMjDB0XheWHAhhJ7+t1pHqJ+Z8lereL5Sp1GPYTKSyOZHrJvrcVqO e9kEZnt5lJtOCRFFM1vYHcDu7J2m2gt9EDDtgUHhujQSxN+EoPToEssLj+XlC3jjrZpv qjs1H4Bg0Kz2UWBpW67AlSSvIVqJQX/h78d8sqUMEvZlYU/5UpSmZbM6rSnWaWOLVnG0 J88A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783404724; x=1784009524; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=N4XA902sDhftTe3c8fF1ABgOsUEkFzIp03BayNh/XVE=; b=tQW0zVVuaWDiuzRihTIt7itTVXhHtJfBt4Ns5+pCoo9TxGxH2zgTyQdgM0+DoNGEhM ixq7PZy6tHmdA3k5PmvL4sOrB5D4uFxag73Wpq5dBWjm2hbrsLkB62QAFmQNQkk9gJF1 xCEmyoKaRmRHYZvOjLgiJPMpIaNVNAgYH1C82SW6QrEMQtu2+yqtGFes25yveR5ow+Tz 9Waq1NHJEXr6gQUIs4/KtgokMnXyVWEInjqwVbbdo0vrwjzEn6X7T/KobwhRPIwtiLs7 VFhi6EULtFHOzeJZ6r+JobXqx5Sex7GYw2wU/h2HUB20vyKua9r3SZka7+dJcGx+UzVD wHjQ== X-Forwarded-Encrypted: i=1; AHgh+RqQesz4M9dTpB9pw2mZOXIeiXaHM2ypmnk1R0Te33DFuo2ad8fo/CnMfowexNe274uPCamGZTgg/wXcm7E=@vger.kernel.org X-Gm-Message-State: AOJu0YwO2yEFWCNalGUTjGH2K8rjU6JpsYPzEl7UrEp1CCEMpD36+9tZ lpKaEP1Q8+Ne897DVgSa1dcTr7s854JX8/gmEGyFbVnv1UvygHYtgWK7qB1pafJsJfHIQxcufU5 MmlQuaaGBIL2D2GsvvN6KRLgIVJBRSJ+daNuMVCS3ZKvPjIqApBs3tU9ltDYXN3CKHH0= X-Gm-Gg: AfdE7ckpyhQJg2zEuC/osYf/UDUqs3YIRzV2eGzIlc7zeIE0i9i8HtZo4pqqggtPMxC uAN9URCmTJjw0125lT5l5HlWvmJSQPwjq+lKtNCzUv/jV8b80VUJurdKX1JRTiNzojlgwOd4ZPi xdfWalkeqVMQ5TzHXlXXABBbVdVILrnLBndbcEUBNbSeXd5aGSPF9N3RbSg2CGYMbEHGT+nCkSe Z7Gi5LankkQtQ0f80+8yZCIRrzqotXyq1EGIMLnxTlRgh1neLnsLfCG18PnDy1nRRkYg/lJkqRx 7vzrthiJuBZenK+kcnU5/Q8ReIyZ90/SYEgMG+VCZacZ3S35QdACg42NanIepe8eRWcDX2kzzNI 64GE8EW1i030ZfJiq5I+J4PhQLpwCSQEPtgX6 X-Received: by 2002:a05:6a00:94d2:b0:842:83d1:ee6d with SMTP id d2e1a72fcca58-84826d9e918mr3749310b3a.45.1783404724100; Mon, 06 Jul 2026 23:12:04 -0700 (PDT) X-Received: by 2002:a05:6a00:94d2:b0:842:83d1:ee6d with SMTP id d2e1a72fcca58-84826d9e918mr3749288b3a.45.1783404723570; Mon, 06 Jul 2026 23:12:03 -0700 (PDT) Received: from hu-hdev-hyd.qualcomm.com ([202.46.22.19]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8480da8bab0sm3299321b3a.8.2026.07.06.23.11.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2026 23:12:03 -0700 (PDT) From: Harshal Dev Date: Tue, 07 Jul 2026 11:41:27 +0530 Subject: [PATCH 1/6] tee: qcomtee: Track the object invocation context Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260707-qcom_uefisecapp_migrate_qcomtee-v1-1-f659cbd5d04c@oss.qualcomm.com> References: <20260707-qcom_uefisecapp_migrate_qcomtee-v1-0-f659cbd5d04c@oss.qualcomm.com> In-Reply-To: <20260707-qcom_uefisecapp_migrate_qcomtee-v1-0-f659cbd5d04c@oss.qualcomm.com> To: Jens Wiklander , Sumit Garg , Amirreza Zarrabi , Bjorn Andersson , Konrad Dybcio Cc: Basant Kumar , Apurupa Pattapu , Arun Kumar Neelakantam , op-tee@lists.trustedfirmware.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Harshal Dev X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1783404715; l=5636; i=harshal.dev@oss.qualcomm.com; s=20251124; h=from:subject:message-id; bh=swwFCmvhnGXLtV5EjzA1jpj0y1exqoHCd9lIGCRTTXQ=; b=uf/oPxl1JN73Nkc3YvvPVlkXI6dU3u1y1EVY3cA+GokfjTWaK15SIJ+daxxeOjzpHQYxkQLy9 2h2RSJwJ3AqDSDtIpcr3/0KejM+HrPn7XNC9tsN1E41B3PIXQJpD1Lx X-Developer-Key: i=harshal.dev@oss.qualcomm.com; a=ed25519; pk=SHJ8K4SglF5t7KmfMKXl6Mby40WczSeLs4Qus7yFO7c= X-Authority-Analysis: v=2.4 cv=SpigLvO0 c=1 sm=1 tr=0 ts=6a4c98b4 cx=c_pps a=m5Vt/hrsBiPMCU0y4gIsQw==:117 a=fChuTYTh2wq5r3m49p7fHw==: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.293,Aquarius:18.0.1143,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-07-07_01,2026-07-06_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 priorityscore=1501 spamscore=0 clxscore=1015 phishscore=0 bulkscore=0 adultscore=0 suspectscore=0 impostorscore=0 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607070056 QCOMTEE needs to distinguish between object invocations arriving from kernel clients and user-space clients in order to correctly marshal UBUF parameters and decide whether certain operations should be permitted. Add a kernel_ctx flag to struct qcomtee_object_invoke_context to track the context of object invocation. Objects invoked from the kernel-space are expected to have the MSB of their 64-bit object-id set to indicate a kernel context, whereas objects invoked from user-space should not set it. To ensure this, we restrict the object-id space of user-space invoked objects to 32-bits. This is in-line with QTEE expectation of 32-bit object ids. Signed-off-by: Amirreza Zarrabi Signed-off-by: Harshal Dev --- drivers/tee/qcomtee/call.c | 24 ++++++++++++++++++++++-- drivers/tee/qcomtee/qcomtee.h | 6 ++++++ drivers/tee/qcomtee/qcomtee_object.h | 8 ++++++-- drivers/tee/tee_core.c | 4 ++++ 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/drivers/tee/qcomtee/call.c b/drivers/tee/qcomtee/call.c index 0efc5646242a..a74a54d67b06 100644 --- a/drivers/tee/qcomtee/call.c +++ b/drivers/tee/qcomtee/call.c @@ -397,11 +397,31 @@ static int qcomtee_object_invoke(struct tee_context *ctx, { struct qcomtee_context_data *ctxdata = ctx->data; struct qcomtee_object *object; + bool kernel_ctx = false; int i, ret, result; if (qcomtee_params_check(params, arg->num_params)) return -EINVAL; + /* Obtain the invocation context information from the MSB of the object + * `id` field. + */ + kernel_ctx = QCOMTEE_GET_CLIENT_CTX(arg->id); + /* User-space identifies a NULL object via a 32-bit TEE_OBJREF_NULL id, whereas + * the kernel uses as 64-bit object-id. Hence, we check for a NULL object by + * sign-extending the object-id to 64 bits. If user-space is indeed invoking a + * NULL object we must extend the object-id to 64-bits from here on so that + * QCOMTEE can recognize it. + */ + if (!kernel_ctx && ((s64)(s32)arg->id) == TEE_OBJREF_NULL) + arg->id = TEE_OBJREF_NULL; + + /* If the object being invoked is not NULL, drop the MSB from the `id` field to + * obtain the actual object-id. + */ + if (arg->id != TEE_OBJREF_NULL) + arg->id = QCOMTEE_SANITIZE_OBJ_ID(arg->id); + /* First, handle reserved operations: */ if (arg->op == QCOMTEE_MSG_OBJECT_OP_RELEASE) { del_qtee_object(arg->id, ctxdata); @@ -411,7 +431,7 @@ static int qcomtee_object_invoke(struct tee_context *ctx, /* Otherwise, invoke a QTEE object: */ struct qcomtee_object_invoke_ctx *oic __free(kfree) = - qcomtee_object_invoke_ctx_alloc(ctx); + qcomtee_object_invoke_ctx_alloc(ctx, kernel_ctx); if (!oic) return -ENOMEM; @@ -648,7 +668,7 @@ static void qcomtee_get_qtee_feature_list(struct tee_context *ctx, u32 id, int result; struct qcomtee_object_invoke_ctx *oic __free(kfree) = - qcomtee_object_invoke_ctx_alloc(ctx); + qcomtee_object_invoke_ctx_alloc(ctx, true); if (!oic) return; diff --git a/drivers/tee/qcomtee/qcomtee.h b/drivers/tee/qcomtee/qcomtee.h index f39bf63fd1c2..5d292a2ff83d 100644 --- a/drivers/tee/qcomtee/qcomtee.h +++ b/drivers/tee/qcomtee/qcomtee.h @@ -17,6 +17,12 @@ #define QCOMTEE_OBJREF_FLAG_USER BIT(1) #define QCOMTEE_OBJREF_FLAG_MEM BIT(2) +/* The MSB of the object_id field indicates whether the client is invoking the + * object from user context or kernel context. + */ +#define QCOMTEE_GET_CLIENT_CTX(x) (((x) >> 63) & 1U) +#define QCOMTEE_SANITIZE_OBJ_ID(x) ((x) & (BIT(63) - 1)) + /** * struct qcomtee - Main service struct. * @teedev: client device. diff --git a/drivers/tee/qcomtee/qcomtee_object.h b/drivers/tee/qcomtee/qcomtee_object.h index 8b4401ecad48..2528d07e4576 100644 --- a/drivers/tee/qcomtee/qcomtee_object.h +++ b/drivers/tee/qcomtee/qcomtee_object.h @@ -146,6 +146,7 @@ static inline int qcomtee_args_len(struct qcomtee_arg *args) * struct qcomtee_object_invoke_ctx - QTEE context for object invocation. * @ctx: TEE context for this invocation. * @flags: flags for the invocation context. + * @kernel_ctx: flag that indicates this context is owned by a kernel client. * @errno: error code for the invocation. * @object: current object invoked in this callback context. * @u: array of arguments for the current invocation (+1 for ending arg). @@ -158,6 +159,7 @@ static inline int qcomtee_args_len(struct qcomtee_arg *args) struct qcomtee_object_invoke_ctx { struct tee_context *ctx; unsigned long flags; + bool kernel_ctx; int errno; struct qcomtee_object *object; @@ -172,13 +174,15 @@ struct qcomtee_object_invoke_ctx { }; static inline struct qcomtee_object_invoke_ctx * -qcomtee_object_invoke_ctx_alloc(struct tee_context *ctx) +qcomtee_object_invoke_ctx_alloc(struct tee_context *ctx, bool kernel_ctx) { struct qcomtee_object_invoke_ctx *oic; oic = kzalloc_obj(*oic); - if (oic) + if (oic) { oic->ctx = ctx; + oic->kernel_ctx = kernel_ctx; + } return oic; } diff --git a/drivers/tee/tee_core.c b/drivers/tee/tee_core.c index ef9642d72672..7f986d7fb47f 100644 --- a/drivers/tee/tee_core.c +++ b/drivers/tee/tee_core.c @@ -706,6 +706,10 @@ static int tee_ioctl_object_invoke(struct tee_context *ctx, goto out; } + /* Userspace object-ids are restricted to 32-bits. */ + if (arg.id > U32_MAX) + return -EINVAL; + rc = ctx->teedev->desc->ops->object_invoke_func(ctx, &arg, params); if (rc) goto out; -- 2.34.1