From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.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 1BACD37DEA3 for ; Fri, 10 Jul 2026 06:37:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783665434; cv=none; b=Z5hyXIukhfc1ZJDPOfzs1YgjLsRgScfs38brstbPvQxJ852R8MIttjkLgWR+WqJDRCeKKqVPV3d+BpgY4xKAWnh0NCTVw7aA/JuVsKfYpj7A8ZVadIEZM/d/gnAv9iyR4RJxjVFGp/HCDPuTT9bT+m4zyNRsVwrvqDQRKF/SCO8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783665434; c=relaxed/simple; bh=mBSuDQvKojrT0IOU24GSxHqlrGwicSKqabhsxL5NX+c=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=fBMKif6+olJiIJn/yCHt6oMC66fZ9oxi7am4JfLWz9VjN2O3tlJXuHzpIIygGVOPfsjgnrRgKFfusk7njJSM3x3tUEvhW/bnLWvle+1nnhUyxq16crXlNNPajAHNuGIt7zyxNQdDjjr8JxQNvi10MhTmWDb+ikyK14RsC3ooBoo= 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=c8ReGJRI; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=IWd19biU; arc=none smtp.client-ip=205.220.180.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="c8ReGJRI"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="IWd19biU" Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 66A3p2AN3855173 for ; Fri, 10 Jul 2026 06:37:12 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= b0Nr6OZmag1QtQ05vPgvrW7VieRyDOuUjbEvIh1Jvgc=; b=c8ReGJRIJHnOBoCQ BUV9qTWqMXZjONBtYJq+NVtWvwKj8WuGG2poB05YKc7+ub7qIQA8XuZafK8Xj9Om PT5H7M7URW/PsMtO9CvTx6nhOkekEOv8yR/tD80wg1mcK3uSYKQCdnIyp+uxjq32 pXa/zjYrKI+rlnIaPJMnfLKGDjQskao76Mt90zRLEVqkaHrR7884VTVmxpmzAmv0 TJ7EJkmrxFepHi8MwxTm4EXLwbH229chN2Bi3mN239lw3K2p8/GEUjYpqj5aE9c9 VmpLXeLAs6C21sclCmY9e/firfeJow17BJGJvof1h1tEz47FbC8GY5afsI4WUCBB oX45ZQ== Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4fas6n0k78-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Fri, 10 Jul 2026 06:37:11 +0000 (GMT) Received: by mail-pl1-f199.google.com with SMTP id d9443c01a7336-2cca3673560so9521735ad.1 for ; Thu, 09 Jul 2026 23:37:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1783665426; x=1784270226; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=b0Nr6OZmag1QtQ05vPgvrW7VieRyDOuUjbEvIh1Jvgc=; b=IWd19biU3T+3VucLmqJqwAKYsrrc6Axjy2k35DwL/hOJIvZ2kDIOD/ScC515WU4BuY hA4lX+r+uXVunfkFu8wdIPWQ35NQTEaa7XSavx/UPyVUzPRYJAKn9G2gf9JXGvF32vm3 mcC/3RjLxIfD9lz/eedsgh5mRaB1t4XcHQ+PRdGq4TIAjcChethC+aeMos4gN8x1P16r kauX7GaN61leRKhKbXcE316myRRvg4bPo5yd5tBPROI3gp6Qh4PqRZIxLpSK0PaP0/pz txVM0MM1HSskAg6yXhjbIQtRDiLPMoX6eDjAms0TxNjhquHfDP0Igpt1ixmRhPq3HN2e vwEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783665426; x=1784270226; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=b0Nr6OZmag1QtQ05vPgvrW7VieRyDOuUjbEvIh1Jvgc=; b=AIQs/HITJjrKdy16INmtJkGkgtinH2Ydf+IXqDM+xuD047dkYKt51NnAOVRYfZiBjw 7OxgxaMkEmDcgE7vfyLFiCS2M+vW2X5OK1SqJf/4RMSnByM5f/Z4kMT2VpXXrAi+l77e CjX+rtG2wrajsekUK+9D6VOXj/i462dBpO+oVz786DEnJ9RMoRPW0FmUBO6nh6qt0F0l AFlspwS/PjLsC3NkbPSWpS5HsMdH7F5TASarRTRSoBrCra1rO9ugia372S67tuKlplzs 1kQEcJYqML8bcv9BeV1UvZMNBnpl9uukv7DabDukmA4/Q01JWUYuPrNL1RW9TMqsAYVq 2Xdw== X-Forwarded-Encrypted: i=1; AHgh+Ro0OLwQCbDkYNiSfU1qzIiinVHHxDC4DHLccGG18UeYr+4JsfDcaFTBbqTpZeL5KMqQt3YhrSQmgZvAzKk=@vger.kernel.org X-Gm-Message-State: AOJu0YxmgGW3Rj0+uH8Qa3M5IWYzDwr6SOxuAyAD64jl0o5nBSSozt9f Fo11Y8eJu4gpbeqmU5tkgVGG4vspzo1M3vj/fX/udbKqnF94fTqhCy6aHAZaXnl5WiWSgxxvEyK DX4/rm++1bG7Osnnrhvv4+ymLgv5QgSYE/OOXlSv+ZpnXdwSuw7perO+deeQkDU/Xgb4= X-Gm-Gg: AfdE7ckF0gvFtkp0QlYoj8THApm5NtGNi0U8jWLNG3QRNivp6IzCBqxJrtpm3Rch/R0 kgZt/574LGdfLQvkuT0e1uatu6/IEur9qIU1fGv/pXiQS/EqVgpe13pqbPZf6rG03IgXkDBj05T E5sJFiKomMZMOTESE0uHlvLiag1Ls6roKh0uMvrYgAQL0I/khZrfDXg6kY42NyBol8KiM3XoOPe AiRI6pGLoXkRto8t0BocUURnHXH4f2eBfby4g9dAhjIuQlCeZ+UeD7Cgwp1ZtPYR8fjQCoCNVv7 8ejRFFheQv8/5Q3bsTWTBL5E2YjXERe9TC/ervtvVkSrV8B94JRyVEUZZkGTKMyzqCH4MIrau9n HNikiLJIPXynXh04OcTqB8S3FnnZ3ASgYwtiF6XcA X-Received: by 2002:a17:902:e54e:b0:2c9:e86e:aa0a with SMTP id d9443c01a7336-2ccea274c6amr101741165ad.0.1783665425617; Thu, 09 Jul 2026 23:37:05 -0700 (PDT) X-Received: by 2002:a17:902:e54e:b0:2c9:e86e:aa0a with SMTP id d9443c01a7336-2ccea274c6amr101740955ad.0.1783665425017; Thu, 09 Jul 2026 23:37:05 -0700 (PDT) Received: from [10.217.223.121] ([202.46.22.19]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ccc9d5bdddsm54257415ad.77.2026.07.09.23.37.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 09 Jul 2026 23:37:04 -0700 (PDT) Message-ID: Date: Fri, 10 Jul 2026 12:07:00 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/6] tee: qcomtee: Track the object invocation context To: Amirreza Zarrabi Cc: Basant Kumar , Apurupa Pattapu , Arun Kumar Neelakantam , op-tee@lists.trustedfirmware.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Konrad Dybcio , Bjorn Andersson , Sumit Garg , jenswi@kernel.org References: <20260707-qcom_uefisecapp_migrate_qcomtee-v1-0-f659cbd5d04c@oss.qualcomm.com> <20260707-qcom_uefisecapp_migrate_qcomtee-v1-1-f659cbd5d04c@oss.qualcomm.com> Content-Language: en-US From: Harshal Dev In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Proofpoint-Spam-Info: AW1haW4tMjYwNzEwMDA2MSBTYWx0ZWRfX7gcRfoNsvZ4O tOfQrqS1oIhQ90EQt996sLDob5oUZVMb/LWEo82/XJr9JN7YLRsViAk1b6KKI7MUYDtmdm82x/k shIYEXPt7MJZ1ZDcXajN0yN1mirPXjk= X-Authority-Analysis: v=2.4 cv=DYgnbPtW c=1 sm=1 tr=0 ts=6a509317 cx=c_pps a=JL+w9abYAAE89/QcEU+0QA==:117 a=fChuTYTh2wq5r3m49p7fHw==:17 a=IkcTkHD0fZMA:10 a=RAioF0-LDSMA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=3WHJM1ZQz_JShphwDgj5:22 a=NEAV23lmAAAA:8 a=EUspDBNiAAAA:8 a=-b72njiGIdzoQt0YrOEA:9 a=QEXdDO2ut3YA:10 a=324X-CrmTo6CU4MGRt3R:22 X-Proofpoint-ORIG-GUID: fviv0iBk68fcruQkMLCMHq6W33PvgQnR X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNzEwMDA2MSBTYWx0ZWRfXxHSombPPSnP3 DhRckWWF9thYexgzJhPl/HohoF6k5K3r/RPCZJsOIfdOqnVuema6DKoLe2uiGb6R3ZnIm4l+GDh cMTxB3bZDMvnnJTlaIYZQo61CC2N9e7gsZAHMdfOOdmXkez8Ummfy20J92LXkVSV/uVi2GcGyiN BKdz0r2au6s9nfSQ3G/jPrqOOPNkTUIU3dbBbF5tQGyOTkPbUR3+SYvhaCWEn7I8pm+fvZhLKTn g0GSCV2laaNZS40h6Atr5yjS3NewQhcICLZw0M2BOQyEB37Hzg8/TH0ziDvMBMZHwrzoDNUrWbQ 1OwisLnUi2UXy3/ob4qjHGW7mMaL++JnYl50kKqZP6L3/KodXUcQHNZUm77XVQQx5ECM5Al+5o/ 6FNUiBn/37pswvn4me5kNRWvYN2UkUS51bGSm1YqCxLa95tvJ0G9ZnHgjj9aIWxHcWGz1/frNIO T9owZCYt5oHFiGc578w== X-Proofpoint-GUID: fviv0iBk68fcruQkMLCMHq6W33PvgQnR X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-07-10_01,2026-07-09_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 lowpriorityscore=0 adultscore=0 suspectscore=0 bulkscore=0 clxscore=1015 phishscore=0 malwarescore=0 spamscore=0 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607100061 Hi Amir, On 7/8/2026 11:31 AM, Amirreza Zarrabi wrote: > Hi Harshal, > > On 7/7/2026 4:11 PM, Harshal Dev wrote: >> 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; > > Does it need to be MSB -- why bit 63? the object ID supported by QTEE is 32-bit anyway. > Let's mask the upper 32-bit and do something like kernel_ctx = !!upper_32_bits(id). > What do you think? I agree. Instead of checking for kernel-ctx by right shifting, I can use this approach. QTEE objects invoked from user-space (including NULL object) will always have their object-id constrained to lower 32 bits anyway as per PR: https://github.com/quic/quic-teec/pull/27 And for kernel-space invoked QTEE objects, upper 32-bits would be set for NULL object, and 63rd bit expected to be set as well. > >> + >> + /* 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; >> + > > This change belongs to tee SS, move it to a separate commit with appropriate message. Ack. Regards, Harshal > >> rc = ctx->teedev->desc->ops->object_invoke_func(ctx, &arg, params); >> if (rc) >> goto out; >> > > Regards, > Amir >