From nobody Sun Apr 5 13:11:12 2026 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (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 C144934575F; Fri, 20 Feb 2026 18:34:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771612484; cv=none; b=poY9eBpe47r/XOVGNdtGx1V6NBgBSpeGos20q+UapQQH4DzA1q8ht7jIGIMTLb/ag5mdkQsPp1ZijxgyQ1vb5VJR5wv7e6hr10the7ZQCWpoaYPZnnaABfPfRyhn1mgSKbVar7cYvXzveyvfP8HsdgG5nLzIabpFlZwvmnuFPFY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771612484; c=relaxed/simple; bh=H0cwYYtV4pBiRH4iKFq+Hz3gXsJSK0HMomrq9ILCgBI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jXbMUz3Hj4Emr8WGNYy+Kr5jk/RixMYHdLAPtkuXkHrE66i2OdxpDPfjELPrvv3wSYNHELh+XlevUpqyOorKpMlbY8sGOBEYRi0LsNoI0XDBDwB/E293J0/Rwx5ovMSarwkj30wqf1Lr41VrVmGbdXMVMVWgIMfyXXuag0ce0Go= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=otqZ8Rtn; arc=none smtp.client-ip=148.163.156.1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="otqZ8Rtn" Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 61KE9JU21273842; Fri, 20 Feb 2026 18:34:41 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=6jE2K5M6bzA64hhCN SjvCMGQBj/dtWws+p8yTqmzJg4=; b=otqZ8RtnGWXL7wW0T+yq3O1G970Rer8KN FGps44VMbItf+jTPYTji72P2A7fHI8onFFOZ0VKv5CnZnXcXfo9G+DOfnMRD/L+e u+eONUhacIdYSOhKxRZGxjM5zLQvMaLOEdWF9KroQxGl99ASs1cf7PhAxQdvXmK3 tdXAVZHS3ATKVrKOfMpNL66Y5ZATH/urkWX3uzLfBu3Jrsm9F+snzfCeyNN8TAPM X4CmVeHDsH0KsMSy37p/UhrY/Xi+Mseddq0nzydR8hhZXKcMaUTVebvYCQjrTzLA kRD8C+cSX8YAbSwCvxvq0CpOo6JT2vTAgKY5HpFHzfpA/QNJh3nRg== Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4caj6v4hxv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Feb 2026 18:34:40 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 61KEHtZg024324; Fri, 20 Feb 2026 18:34:40 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 4ccb45hjyg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Feb 2026 18:34:39 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 61KIYZ6V60883274 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Feb 2026 18:34:35 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C477820300; Fri, 20 Feb 2026 18:34:35 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4BBD1202F9; Fri, 20 Feb 2026 18:34:30 +0000 (GMT) Received: from li-fc74f8cc-3279-11b2-a85c-ef5828687581.ibm.com.com (unknown [9.39.26.213]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 20 Feb 2026 18:34:30 +0000 (GMT) From: Srish Srinivasan To: linux-integrity@vger.kernel.org, keyrings@vger.kernel.org Cc: James.Bottomley@HansenPartnership.com, jarkko@kernel.org, zohar@linux.ibm.com, stefanb@linux.ibm.com, nayna@linux.ibm.com, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, ssrish@linux.ibm.com Subject: [PATCH v2 1/2] keys/trusted_keys: clean up debug message logging in the tpm backend Date: Sat, 21 Feb 2026 00:04:25 +0530 Message-ID: <20260220183426.80446-2-ssrish@linux.ibm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260220183426.80446-1-ssrish@linux.ibm.com> References: <20260220183426.80446-1-ssrish@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Authority-Analysis: v=2.4 cv=E+/AZKdl c=1 sm=1 tr=0 ts=6998a940 cx=c_pps a=bLidbwmWQ0KltjZqbj+ezA==:117 a=bLidbwmWQ0KltjZqbj+ezA==:17 a=HzLeVaNsDn8A:10 a=VkNPw1HP01LnGYTKEx00:22 a=Mpw57Om8IfrbqaoTuvik:22 a=GgsMoib0sEa3-_RKJdDe:22 a=VnNF1IyMAAAA:8 a=MBxKtJUSPDA0k7jbNj0A:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMjIwMDE1MyBTYWx0ZWRfX3zv9Th8p8Wo0 8IrnknrXkeMe6rOTzOLoxd9h9YQbsSPbo2yv/KT2GWql0iHrp7C4GJwtETmZaAr8lDQ5mCp9z3A OqfrUTjb9szD3n8DX1/tmOXWuElohgmj9CD3UPMV6Hn7U/Llnji1XQfkJEpAx4nxYcQ+d3/369y FQy/uCiC7dnt1fhisE0fk92zsQwE0ohu+euCvxDYrvWZGMDrZkT5hc0X13m3c6Z/Y/srLMQxxJO 7WP3x7Qb0KqD0gEjD9YLsOsfiEe7fQQ2ruWf7l1aIuJNG9zi+rHHePjNefMeFqYJOsFIwDr22QP KOFtlrGBj/0WavBw9xjbzcAxPPM3Xh5bD26odO3tygkkfNmnM768e+Lls3N85M7qFYW2xRIGHJa mFUcfRDjMq0KxIXgqT4lY4o+fmBYIj69zC9EBt2mjZWPogAeyQ4T+2KmGxu2sZav6rj0WXr2+Ia R713iwxAsWHSPmMw5UQ== X-Proofpoint-ORIG-GUID: VpYtXAoQLdfpJDQoTNbdMnQyiTZHlJaV X-Proofpoint-GUID: VpYtXAoQLdfpJDQoTNbdMnQyiTZHlJaV X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-02-20_02,2026-02-20_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 priorityscore=1501 malwarescore=0 phishscore=0 bulkscore=0 suspectscore=0 spamscore=0 clxscore=1015 impostorscore=0 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2602200153 Content-Type: text/plain; charset="utf-8" The TPM trusted-keys backend uses a local TPM_DEBUG guard and pr_info() for logging debug information. Replace pr_info() with pr_debug(), and use KERN_DEBUG for print_hex_dump(). Remove TPM_DEBUG. No functional change intended. Signed-off-by: Srish Srinivasan Reviewed-by: Stefan Berger Reviewed-by: Jarkko Sakkinen --- security/keys/trusted-keys/trusted_tpm1.c | 40 +++++++---------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/security/keys/trusted-keys/trusted_tpm1.c b/security/keys/trus= ted-keys/trusted_tpm1.c index c865c97aa1b4..216caef97ffc 100644 --- a/security/keys/trusted-keys/trusted_tpm1.c +++ b/security/keys/trusted-keys/trusted_tpm1.c @@ -46,28 +46,25 @@ enum { SRK_keytype =3D 4 }; =20 -#define TPM_DEBUG 0 - -#if TPM_DEBUG static inline void dump_options(struct trusted_key_options *o) { - pr_info("sealing key type %d\n", o->keytype); - pr_info("sealing key handle %0X\n", o->keyhandle); - pr_info("pcrlock %d\n", o->pcrlock); - pr_info("pcrinfo %d\n", o->pcrinfo_len); - print_hex_dump(KERN_INFO, "pcrinfo ", DUMP_PREFIX_NONE, + pr_debug("sealing key type %d\n", o->keytype); + pr_debug("sealing key handle %0X\n", o->keyhandle); + pr_debug("pcrlock %d\n", o->pcrlock); + pr_debug("pcrinfo %d\n", o->pcrinfo_len); + print_hex_dump(KERN_DEBUG, "pcrinfo ", DUMP_PREFIX_NONE, 16, 1, o->pcrinfo, o->pcrinfo_len, 0); } =20 static inline void dump_sess(struct osapsess *s) { - print_hex_dump(KERN_INFO, "trusted-key: handle ", DUMP_PREFIX_NONE, + print_hex_dump(KERN_DEBUG, "trusted-key: handle ", DUMP_PREFIX_NONE, 16, 1, &s->handle, 4, 0); - pr_info("secret:\n"); - print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE, + pr_debug("secret:\n"); + print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_NONE, 16, 1, &s->secret, SHA1_DIGEST_SIZE, 0); - pr_info("trusted-key: enonce:\n"); - print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE, + pr_debug("trusted-key: enonce:\n"); + print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_NONE, 16, 1, &s->enonce, SHA1_DIGEST_SIZE, 0); } =20 @@ -75,23 +72,10 @@ static inline void dump_tpm_buf(unsigned char *buf) { int len; =20 - pr_info("\ntpm buffer\n"); + pr_debug("\ntpm buffer\n"); len =3D LOAD32(buf, TPM_SIZE_OFFSET); - print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE, 16, 1, buf, len, 0); -} -#else -static inline void dump_options(struct trusted_key_options *o) -{ -} - -static inline void dump_sess(struct osapsess *s) -{ -} - -static inline void dump_tpm_buf(unsigned char *buf) -{ + print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_NONE, 16, 1, buf, len, 0); } -#endif =20 static int TSS_rawhmac(unsigned char *digest, const unsigned char *key, unsigned int keylen, ...) --=20 2.43.0 From nobody Sun Apr 5 13:11:12 2026 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 B7FD436680C; Fri, 20 Feb 2026 18:34:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771612489; cv=none; b=NPwpK87BGTczhmwW3TQHl64uP5BLkFG0Bq4X0VE/dBFvh4QJZQRjh90K/nL4k7Gjl6BNntjFu+fuAkSM5pC6iTjzboGnNpdgjsQ+pLeGMt7FvWFbRvyHpG1qbBR7Si0b6p9CS7iCXII+u2nAOorRxbgCqim3g92xxJ23vXdfDbM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771612489; c=relaxed/simple; bh=Y/uR169HEfHE4T/s2n4IaC0XZxqzTy5HB8XBwjfIn5E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KCpETJYP5t4ntBCLwZS2KAV7+M/gkf7ctjJcio5dtoVk2b3I+FckJimHhS9S8U2tdLpcmvmtl2AIKMWJ82CTXtdXaSz039Q1hapWPGTxQHlLvjN+j1zKmsOpU45f8IRBOjc0VgcIW+e0YxqL4TPAcydl1SkWluhheJNEs7j91HM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=WmQrputN; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="WmQrputN" Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 61KEvON81296147; Fri, 20 Feb 2026 18:34:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=EyEQf2xGL70GiAdGq RMb7xyTB21HSDFi6aO9Csu8eMo=; b=WmQrputNkpByJHFIWLozBP4Spkkiyot2s hA79uEIPIj87AJ1QtuzzXBDoVuRKytQ++LOSPB/liWWuAf9j+TpptyNDXxa5T9YU 6SsSdM53RVn3hekfugfm9j0wLvDl/I4/hK0Lqws+Ch8HYzqJlxhH606uUo1jBsfY 5NhYN+YNmZ+azRK/JyZIc7kGelMu0SQoR4dXla+gdazSQ7bf0WKiWRd1xISgsu9j W7ZX7J6nZCSrTAIcoPsHHM6WNDZIVKle9DwMPNcKB/RVnEwGmy5kWsv9tfnmUgAH s6ybn+iHRO/tWuDOEJ67zVVeYC6uZKu4ieKyhC+eJiVJm+HWsdZpA== Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4caj64k0du-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Feb 2026 18:34:43 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 61KEQxe7001375; Fri, 20 Feb 2026 18:34:42 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 4ccb2bshxx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Feb 2026 18:34:42 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 61KIYc3446399878 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Feb 2026 18:34:38 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9DD88202F9; Fri, 20 Feb 2026 18:34:38 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3D8C920301; Fri, 20 Feb 2026 18:34:36 +0000 (GMT) Received: from li-fc74f8cc-3279-11b2-a85c-ef5828687581.ibm.com.com (unknown [9.39.26.213]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 20 Feb 2026 18:34:36 +0000 (GMT) From: Srish Srinivasan To: linux-integrity@vger.kernel.org, keyrings@vger.kernel.org Cc: James.Bottomley@HansenPartnership.com, jarkko@kernel.org, zohar@linux.ibm.com, stefanb@linux.ibm.com, nayna@linux.ibm.com, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, ssrish@linux.ibm.com Subject: [PATCH v2 2/2] keys/trusted_keys: move TPM-specific fields into trusted_tpm_options Date: Sat, 21 Feb 2026 00:04:26 +0530 Message-ID: <20260220183426.80446-3-ssrish@linux.ibm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260220183426.80446-1-ssrish@linux.ibm.com> References: <20260220183426.80446-1-ssrish@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 3FBsKpOl1eqszax_Z8G0yEBf2nU2ejSf X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMjIwMDE1MyBTYWx0ZWRfXyAKCOU7Az/q/ aC6mD++zO8jpy7TrO9xykSM9O9+vjnCHOavfEXEsOTe+4aHy3mTGoSCdBw0WaWCPi0vlgqQop85 oqCtehbmkopI36gI8RoD2cDOEMXCOhBhMzwE6tJh5vLijQfnCK7FbdPjpxS5GCyQoRKfRy3ycG0 +S79Kz41bDiPzSH8L3aBI+4Ba47iODM7iD2aQnLpWlYxKkLUFYMCz927mTBPbRdhmIps8Clca5i sCP53gJ6aSje/nofQ/PMzm56CyVziM8BEKtdPEBf389X7wwmQeBqucHw4+1+kzNXJa7yAzzROgW aaTQNdsFOOXfvTBIgPsiyJr6q4abeqwmrGguihKRVhOmeCWA1A20Z7DW/ZBFLTZdO6lo0WPXWBI +J6uSAvXKcQe9LP3KYDoK9Pbz2rBp1is2RPzqAt/rK1roSd/WYtEPnlD0LoI0bGLRHIvi7xl7rt D63zbitiacDl7hFzbRw== X-Proofpoint-GUID: 3FBsKpOl1eqszax_Z8G0yEBf2nU2ejSf X-Authority-Analysis: v=2.4 cv=U+mfzOru c=1 sm=1 tr=0 ts=6998a943 cx=c_pps a=AfN7/Ok6k8XGzOShvHwTGQ==:117 a=AfN7/Ok6k8XGzOShvHwTGQ==:17 a=HzLeVaNsDn8A:10 a=VkNPw1HP01LnGYTKEx00:22 a=Mpw57Om8IfrbqaoTuvik:22 a=GgsMoib0sEa3-_RKJdDe:22 a=VnNF1IyMAAAA:8 a=Jts-3Rt90Sf2m4vj4rUA:9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-02-20_02,2026-02-20_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 bulkscore=0 impostorscore=0 malwarescore=0 spamscore=0 adultscore=0 phishscore=0 lowpriorityscore=0 priorityscore=1501 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2602200153 Content-Type: text/plain; charset="utf-8" The trusted_key_options struct contains TPM-specific fields (keyhandle, keyauth, blobauth_len, blobauth, pcrinfo_len, pcrinfo, pcrlock, hash, policydigest_len, policydigest, and policyhandle). This leads to the accumulation of backend-specific fields in the generic options structure. Define trusted_tpm_options structure and move the TPM-specific fields there. Store a pointer to trusted_tpm_options in trusted_key_options's private. No functional change intended. Signed-off-by: Srish Srinivasan Reviewed-by: Stefan Berger Reviewed-by: Jarkko Sakkinen --- include/keys/trusted-type.h | 11 --- include/keys/trusted_tpm.h | 14 ++++ security/keys/trusted-keys/trusted_tpm1.c | 95 ++++++++++++++--------- security/keys/trusted-keys/trusted_tpm2.c | 51 ++++++------ 4 files changed, 102 insertions(+), 69 deletions(-) diff --git a/include/keys/trusted-type.h b/include/keys/trusted-type.h index 03527162613f..b80f250305b8 100644 --- a/include/keys/trusted-type.h +++ b/include/keys/trusted-type.h @@ -39,17 +39,6 @@ struct trusted_key_payload { =20 struct trusted_key_options { uint16_t keytype; - uint32_t keyhandle; - unsigned char keyauth[TPM_DIGEST_SIZE]; - uint32_t blobauth_len; - unsigned char blobauth[TPM_DIGEST_SIZE]; - uint32_t pcrinfo_len; - unsigned char pcrinfo[MAX_PCRINFO_SIZE]; - int pcrlock; - uint32_t hash; - uint32_t policydigest_len; - unsigned char policydigest[MAX_DIGEST_SIZE]; - uint32_t policyhandle; void *private; }; =20 diff --git a/include/keys/trusted_tpm.h b/include/keys/trusted_tpm.h index 0fadc6a4f166..355ebd36cbfd 100644 --- a/include/keys/trusted_tpm.h +++ b/include/keys/trusted_tpm.h @@ -7,6 +7,20 @@ =20 extern struct trusted_key_ops trusted_key_tpm_ops; =20 +struct trusted_tpm_options { + uint32_t keyhandle; + unsigned char keyauth[TPM_DIGEST_SIZE]; + uint32_t blobauth_len; + unsigned char blobauth[TPM_DIGEST_SIZE]; + uint32_t pcrinfo_len; + unsigned char pcrinfo[MAX_PCRINFO_SIZE]; + int pcrlock; + uint32_t hash; + uint32_t policydigest_len; + unsigned char policydigest[MAX_DIGEST_SIZE]; + uint32_t policyhandle; +}; + int tpm2_seal_trusted(struct tpm_chip *chip, struct trusted_key_payload *payload, struct trusted_key_options *options); diff --git a/security/keys/trusted-keys/trusted_tpm1.c b/security/keys/trus= ted-keys/trusted_tpm1.c index 216caef97ffc..741b1d47d9f8 100644 --- a/security/keys/trusted-keys/trusted_tpm1.c +++ b/security/keys/trusted-keys/trusted_tpm1.c @@ -48,12 +48,14 @@ enum { =20 static inline void dump_options(struct trusted_key_options *o) { + struct trusted_tpm_options *private =3D o->private; + pr_debug("sealing key type %d\n", o->keytype); - pr_debug("sealing key handle %0X\n", o->keyhandle); - pr_debug("pcrlock %d\n", o->pcrlock); - pr_debug("pcrinfo %d\n", o->pcrinfo_len); + pr_debug("sealing key handle %0X\n", private->keyhandle); + pr_debug("pcrlock %d\n", private->pcrlock); + pr_debug("pcrinfo %d\n", private->pcrinfo_len); print_hex_dump(KERN_DEBUG, "pcrinfo ", DUMP_PREFIX_NONE, - 16, 1, o->pcrinfo, o->pcrinfo_len, 0); + 16, 1, private->pcrinfo, private->pcrinfo_len, 0); } =20 static inline void dump_sess(struct osapsess *s) @@ -609,6 +611,7 @@ static int tpm_unseal(struct tpm_buf *tb, static int key_seal(struct trusted_key_payload *p, struct trusted_key_options *o) { + struct trusted_tpm_options *private =3D o->private; struct tpm_buf tb; int ret; =20 @@ -619,9 +622,10 @@ static int key_seal(struct trusted_key_payload *p, /* include migratable flag at end of sealed key */ p->key[p->key_len] =3D p->migratable; =20 - ret =3D tpm_seal(&tb, o->keytype, o->keyhandle, o->keyauth, + ret =3D tpm_seal(&tb, o->keytype, private->keyhandle, private->keyauth, p->key, p->key_len + 1, p->blob, &p->blob_len, - o->blobauth, o->pcrinfo, o->pcrinfo_len); + private->blobauth, private->pcrinfo, + private->pcrinfo_len); if (ret < 0) pr_info("srkseal failed (%d)\n", ret); =20 @@ -635,6 +639,7 @@ static int key_seal(struct trusted_key_payload *p, static int key_unseal(struct trusted_key_payload *p, struct trusted_key_options *o) { + struct trusted_tpm_options *private =3D o->private; struct tpm_buf tb; int ret; =20 @@ -642,8 +647,8 @@ static int key_unseal(struct trusted_key_payload *p, if (ret) return ret; =20 - ret =3D tpm_unseal(&tb, o->keyhandle, o->keyauth, p->blob, p->blob_len, - o->blobauth, p->key, &p->key_len); + ret =3D tpm_unseal(&tb, private->keyhandle, private->keyauth, p->blob, + p->blob_len, private->blobauth, p->key, &p->key_len); if (ret < 0) pr_info("srkunseal failed (%d)\n", ret); else @@ -680,6 +685,7 @@ static const match_table_t key_tokens =3D { static int getoptions(char *c, struct trusted_key_payload *pay, struct trusted_key_options *opt) { + struct trusted_tpm_options *private =3D opt->private; substring_t args[MAX_OPT_ARGS]; char *p =3D c; int token; @@ -695,7 +701,7 @@ static int getoptions(char *c, struct trusted_key_paylo= ad *pay, if (tpm2 < 0) return tpm2; =20 - opt->hash =3D tpm2 ? HASH_ALGO_SHA256 : HASH_ALGO_SHA1; + private->hash =3D tpm2 ? HASH_ALGO_SHA256 : HASH_ALGO_SHA1; =20 if (!c) return 0; @@ -709,11 +715,11 @@ static int getoptions(char *c, struct trusted_key_pay= load *pay, =20 switch (token) { case Opt_pcrinfo: - opt->pcrinfo_len =3D strlen(args[0].from) / 2; - if (opt->pcrinfo_len > MAX_PCRINFO_SIZE) + private->pcrinfo_len =3D strlen(args[0].from) / 2; + if (private->pcrinfo_len > MAX_PCRINFO_SIZE) return -EINVAL; - res =3D hex2bin(opt->pcrinfo, args[0].from, - opt->pcrinfo_len); + res =3D hex2bin(private->pcrinfo, args[0].from, + private->pcrinfo_len); if (res < 0) return -EINVAL; break; @@ -722,12 +728,12 @@ static int getoptions(char *c, struct trusted_key_pay= load *pay, if (res < 0) return -EINVAL; opt->keytype =3D SEAL_keytype; - opt->keyhandle =3D handle; + private->keyhandle =3D handle; break; case Opt_keyauth: if (strlen(args[0].from) !=3D 2 * SHA1_DIGEST_SIZE) return -EINVAL; - res =3D hex2bin(opt->keyauth, args[0].from, + res =3D hex2bin(private->keyauth, args[0].from, SHA1_DIGEST_SIZE); if (res < 0) return -EINVAL; @@ -738,21 +744,23 @@ static int getoptions(char *c, struct trusted_key_pay= load *pay, * hex strings. TPM 2.0 authorizations are simple * passwords (although it can take a hash as well) */ - opt->blobauth_len =3D strlen(args[0].from); + private->blobauth_len =3D strlen(args[0].from); =20 - if (opt->blobauth_len =3D=3D 2 * TPM_DIGEST_SIZE) { - res =3D hex2bin(opt->blobauth, args[0].from, + if (private->blobauth_len =3D=3D 2 * TPM_DIGEST_SIZE) { + res =3D hex2bin(private->blobauth, args[0].from, TPM_DIGEST_SIZE); if (res < 0) return -EINVAL; =20 - opt->blobauth_len =3D TPM_DIGEST_SIZE; + private->blobauth_len =3D TPM_DIGEST_SIZE; break; } =20 - if (tpm2 && opt->blobauth_len <=3D sizeof(opt->blobauth)) { - memcpy(opt->blobauth, args[0].from, - opt->blobauth_len); + if (tpm2 && + private->blobauth_len <=3D + sizeof(private->blobauth)) { + memcpy(private->blobauth, args[0].from, + private->blobauth_len); break; } =20 @@ -770,14 +778,14 @@ static int getoptions(char *c, struct trusted_key_pay= load *pay, res =3D kstrtoul(args[0].from, 10, &lock); if (res < 0) return -EINVAL; - opt->pcrlock =3D lock; + private->pcrlock =3D lock; break; case Opt_hash: if (test_bit(Opt_policydigest, &token_mask)) return -EINVAL; for (i =3D 0; i < HASH_ALGO__LAST; i++) { if (!strcmp(args[0].from, hash_algo_name[i])) { - opt->hash =3D i; + private->hash =3D i; break; } } @@ -789,14 +797,14 @@ static int getoptions(char *c, struct trusted_key_pay= load *pay, } break; case Opt_policydigest: - digest_len =3D hash_digest_size[opt->hash]; + digest_len =3D hash_digest_size[private->hash]; if (!tpm2 || strlen(args[0].from) !=3D (2 * digest_len)) return -EINVAL; - res =3D hex2bin(opt->policydigest, args[0].from, + res =3D hex2bin(private->policydigest, args[0].from, digest_len); if (res < 0) return -EINVAL; - opt->policydigest_len =3D digest_len; + private->policydigest_len =3D digest_len; break; case Opt_policyhandle: if (!tpm2) @@ -804,7 +812,7 @@ static int getoptions(char *c, struct trusted_key_paylo= ad *pay, res =3D kstrtoul(args[0].from, 16, &handle); if (res < 0) return -EINVAL; - opt->policyhandle =3D handle; + private->policyhandle =3D handle; break; default: return -EINVAL; @@ -815,6 +823,7 @@ static int getoptions(char *c, struct trusted_key_paylo= ad *pay, =20 static struct trusted_key_options *trusted_options_alloc(void) { + struct trusted_tpm_options *private; struct trusted_key_options *options; int tpm2; =20 @@ -827,14 +836,23 @@ static struct trusted_key_options *trusted_options_al= loc(void) /* set any non-zero defaults */ options->keytype =3D SRK_keytype; =20 - if (!tpm2) - options->keyhandle =3D SRKHANDLE; + private =3D kzalloc(sizeof(*private), GFP_KERNEL); + if (!private) { + kfree_sensitive(options); + options =3D NULL; + } else { + if (!tpm2) + private->keyhandle =3D SRKHANDLE; + + options->private =3D private; + } } return options; } =20 static int trusted_tpm_seal(struct trusted_key_payload *p, char *datablob) { + struct trusted_tpm_options *private =3D NULL; struct trusted_key_options *options =3D NULL; int ret =3D 0; int tpm2; @@ -852,7 +870,8 @@ static int trusted_tpm_seal(struct trusted_key_payload = *p, char *datablob) goto out; dump_options(options); =20 - if (!options->keyhandle && !tpm2) { + private =3D options->private; + if (!private->keyhandle && !tpm2) { ret =3D -EINVAL; goto out; } @@ -866,20 +885,22 @@ static int trusted_tpm_seal(struct trusted_key_payloa= d *p, char *datablob) goto out; } =20 - if (options->pcrlock) { - ret =3D pcrlock(options->pcrlock); + if (private->pcrlock) { + ret =3D pcrlock(private->pcrlock); if (ret < 0) { pr_info("pcrlock failed (%d)\n", ret); goto out; } } out: + kfree_sensitive(options->private); kfree_sensitive(options); return ret; } =20 static int trusted_tpm_unseal(struct trusted_key_payload *p, char *datablo= b) { + struct trusted_tpm_options *private =3D NULL; struct trusted_key_options *options =3D NULL; int ret =3D 0; int tpm2; @@ -897,7 +918,8 @@ static int trusted_tpm_unseal(struct trusted_key_payloa= d *p, char *datablob) goto out; dump_options(options); =20 - if (!options->keyhandle && !tpm2) { + private =3D options->private; + if (!private->keyhandle && !tpm2) { ret =3D -EINVAL; goto out; } @@ -909,14 +931,15 @@ static int trusted_tpm_unseal(struct trusted_key_payl= oad *p, char *datablob) if (ret < 0) pr_info("key_unseal failed (%d)\n", ret); =20 - if (options->pcrlock) { - ret =3D pcrlock(options->pcrlock); + if (private->pcrlock) { + ret =3D pcrlock(private->pcrlock); if (ret < 0) { pr_info("pcrlock failed (%d)\n", ret); goto out; } } out: + kfree_sensitive(options->private); kfree_sensitive(options); return ret; } diff --git a/security/keys/trusted-keys/trusted_tpm2.c b/security/keys/trus= ted-keys/trusted_tpm2.c index 6340823f8b53..94e01249b921 100644 --- a/security/keys/trusted-keys/trusted_tpm2.c +++ b/security/keys/trusted-keys/trusted_tpm2.c @@ -24,6 +24,7 @@ static int tpm2_key_encode(struct trusted_key_payload *pa= yload, struct trusted_key_options *options, u8 *src, u32 len) { + struct trusted_tpm_options *private =3D options->private; const int SCRATCH_SIZE =3D PAGE_SIZE; u8 *scratch =3D kmalloc(SCRATCH_SIZE, GFP_KERNEL); u8 *work =3D scratch, *work1; @@ -46,7 +47,7 @@ static int tpm2_key_encode(struct trusted_key_payload *pa= yload, work =3D asn1_encode_oid(work, end_work, tpm2key_oid, asn1_oid_len(tpm2key_oid)); =20 - if (options->blobauth_len =3D=3D 0) { + if (private->blobauth_len =3D=3D 0) { unsigned char bool[3], *w =3D bool; /* tag 0 is emptyAuth */ w =3D asn1_encode_boolean(w, w + sizeof(bool), true); @@ -69,7 +70,7 @@ static int tpm2_key_encode(struct trusted_key_payload *pa= yload, goto err; } =20 - work =3D asn1_encode_integer(work, end_work, options->keyhandle); + work =3D asn1_encode_integer(work, end_work, private->keyhandle); work =3D asn1_encode_octet_string(work, end_work, pub, pub_len); work =3D asn1_encode_octet_string(work, end_work, priv, priv_len); =20 @@ -102,6 +103,7 @@ static int tpm2_key_decode(struct trusted_key_payload *= payload, struct trusted_key_options *options, u8 **buf) { + struct trusted_tpm_options *private =3D options->private; int ret; struct tpm2_key_context ctx; u8 *blob; @@ -121,7 +123,7 @@ static int tpm2_key_decode(struct trusted_key_payload *= payload, return -ENOMEM; =20 *buf =3D blob; - options->keyhandle =3D ctx.parent; + private->keyhandle =3D ctx.parent; =20 memcpy(blob, ctx.priv, ctx.priv_len); blob +=3D ctx.priv_len; @@ -233,6 +235,7 @@ int tpm2_seal_trusted(struct tpm_chip *chip, struct trusted_key_payload *payload, struct trusted_key_options *options) { + struct trusted_tpm_options *private =3D options->private; off_t offset =3D TPM_HEADER_SIZE; struct tpm_buf buf, sized; int blob_len =3D 0; @@ -240,11 +243,11 @@ int tpm2_seal_trusted(struct tpm_chip *chip, u32 flags; int rc; =20 - hash =3D tpm2_find_hash_alg(options->hash); + hash =3D tpm2_find_hash_alg(private->hash); if (hash < 0) return hash; =20 - if (!options->keyhandle) + if (!private->keyhandle) return -EINVAL; =20 rc =3D tpm_try_get_ops(chip); @@ -268,18 +271,19 @@ int tpm2_seal_trusted(struct tpm_chip *chip, goto out_put; } =20 - rc =3D tpm_buf_append_name(chip, &buf, options->keyhandle, NULL); + rc =3D tpm_buf_append_name(chip, &buf, private->keyhandle, NULL); if (rc) goto out; =20 tpm_buf_append_hmac_session(chip, &buf, TPM2_SA_DECRYPT, - options->keyauth, TPM_DIGEST_SIZE); + private->keyauth, TPM_DIGEST_SIZE); =20 /* sensitive */ - tpm_buf_append_u16(&sized, options->blobauth_len); + tpm_buf_append_u16(&sized, private->blobauth_len); =20 - if (options->blobauth_len) - tpm_buf_append(&sized, options->blobauth, options->blobauth_len); + if (private->blobauth_len) + tpm_buf_append(&sized, private->blobauth, + private->blobauth_len); =20 tpm_buf_append_u16(&sized, payload->key_len); tpm_buf_append(&sized, payload->key, payload->key_len); @@ -292,14 +296,15 @@ int tpm2_seal_trusted(struct tpm_chip *chip, =20 /* key properties */ flags =3D 0; - flags |=3D options->policydigest_len ? 0 : TPM2_OA_USER_WITH_AUTH; + flags |=3D private->policydigest_len ? 0 : TPM2_OA_USER_WITH_AUTH; flags |=3D payload->migratable ? 0 : (TPM2_OA_FIXED_TPM | TPM2_OA_FIXED_P= ARENT); tpm_buf_append_u32(&sized, flags); =20 /* policy */ - tpm_buf_append_u16(&sized, options->policydigest_len); - if (options->policydigest_len) - tpm_buf_append(&sized, options->policydigest, options->policydigest_len); + tpm_buf_append_u16(&sized, private->policydigest_len); + if (private->policydigest_len) + tpm_buf_append(&sized, private->policydigest, + private->policydigest_len); =20 /* public parameters */ tpm_buf_append_u16(&sized, TPM_ALG_NULL); @@ -373,6 +378,7 @@ static int tpm2_load_cmd(struct tpm_chip *chip, u32 *blob_handle) { u8 *blob_ref __free(kfree) =3D NULL; + struct trusted_tpm_options *private =3D options->private; struct tpm_buf buf; unsigned int private_len; unsigned int public_len; @@ -392,7 +398,7 @@ static int tpm2_load_cmd(struct tpm_chip *chip, } =20 /* new format carries keyhandle but old format doesn't */ - if (!options->keyhandle) + if (!private->keyhandle) return -EINVAL; =20 /* must be big enough for at least the two be16 size counts */ @@ -433,11 +439,11 @@ static int tpm2_load_cmd(struct tpm_chip *chip, return rc; } =20 - rc =3D tpm_buf_append_name(chip, &buf, options->keyhandle, NULL); + rc =3D tpm_buf_append_name(chip, &buf, private->keyhandle, NULL); if (rc) goto out; =20 - tpm_buf_append_hmac_session(chip, &buf, 0, options->keyauth, + tpm_buf_append_hmac_session(chip, &buf, 0, private->keyauth, TPM_DIGEST_SIZE); =20 tpm_buf_append(&buf, blob, blob_len); @@ -481,6 +487,7 @@ static int tpm2_unseal_cmd(struct tpm_chip *chip, struct trusted_key_options *options, u32 blob_handle) { + struct trusted_tpm_options *private =3D options->private; struct tpm_header *head; struct tpm_buf buf; u16 data_len; @@ -502,10 +509,10 @@ static int tpm2_unseal_cmd(struct tpm_chip *chip, if (rc) goto out; =20 - if (!options->policyhandle) { + if (!private->policyhandle) { tpm_buf_append_hmac_session(chip, &buf, TPM2_SA_ENCRYPT, - options->blobauth, - options->blobauth_len); + private->blobauth, + private->blobauth_len); } else { /* * FIXME: The policy session was generated outside the @@ -518,9 +525,9 @@ static int tpm2_unseal_cmd(struct tpm_chip *chip, * could repeat our actions with the exfiltrated * password. */ - tpm2_buf_append_auth(&buf, options->policyhandle, + tpm2_buf_append_auth(&buf, private->policyhandle, NULL /* nonce */, 0, 0, - options->blobauth, options->blobauth_len); + private->blobauth, private->blobauth_len); if (tpm2_chip_auth(chip)) { tpm_buf_append_hmac_session(chip, &buf, TPM2_SA_ENCRYPT, NULL, 0); } else { --=20 2.43.0