From patchwork Fri Jan 13 16:10:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eddie James X-Patchwork-Id: 43415 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp362524wrt; Fri, 13 Jan 2023 08:27:39 -0800 (PST) X-Google-Smtp-Source: AMrXdXuU020vtIws0qL2Vl+GE4MpkvFtjTQbe44RzYsqkLY0DlNMBrf2KSrI6TGMVTZwsQdmwa/6 X-Received: by 2002:a05:6a21:8cca:b0:a9:fddb:9eab with SMTP id ta10-20020a056a218cca00b000a9fddb9eabmr14016997pzb.41.1673627259667; Fri, 13 Jan 2023 08:27:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673627259; cv=none; d=google.com; s=arc-20160816; b=KrRnFHcvd4Hy5OitFkPzOppVDjBP045LaNpLJpiqeNupleIXXgpluDU9GoVuoF/cCw 5AHQh8EGZ6Zxh4cplTQvYc0CS6WRlsLiyanNwWR1Gz+vYekgIIs2GhpwELmPK6pf9jmW Ahj736vzljd+0MkUoAQUdKNG6qkQzJESv4hgK6J+rSSp9z2+Pe2Fmqe/FiTqF1K7UWyh z1k40CSrJcoqZ7LeeiZQrGlZrsqYOXX6tzo+WdTwMYaoerlzIfoli1A0sZcCBGzSeD7f 7DYsCRb/u7BQypKjMu1xCe6HNEnjjgXngEl2RdKL7VEowzz9lE2aDggBkyg1GESUcejk ewbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MCA785kWBXhTrXwJ6eVYTY5/yNgfBkb57o0LJH0dY9A=; b=XDw109ZdEhA70tWOGisrh4r0ZuNaQYPGHQfWtHXihXM0gPFo2/deofOwTHOqUWWKuS s73pbLcabztZKScEAAOR2cl8iAtrUT1QPh2G50g1S86fxmNruyEyv5BvCSadByO0JfZ5 IkXi/cBq5shjHYVcPPZy0tZJMBO+IQ5HxQGppmHf65CAvRN5wkhM0jy1+MbGATqZySRN kXqPmhBxqaaSNNSaVdlpIxTtDV/jv5dE0RB+sEEkA1Qe/wu7AhvMH43LbDPRmF7Q/Nzr KGig45LAEu4899xmP5a5heD4GM/urmeGq+KGWFa5p5TOJZGFScgtt0iWz5l1SG5Ez86H 5xVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=nxGRs6vf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v8-20020a63bf08000000b0044cce26fa32si21818900pgf.632.2023.01.13.08.27.27; Fri, 13 Jan 2023 08:27:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=nxGRs6vf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230384AbjAMQSD (ORCPT + 99 others); Fri, 13 Jan 2023 11:18:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229461AbjAMQRV (ORCPT ); Fri, 13 Jan 2023 11:17:21 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D280C8CD2C; Fri, 13 Jan 2023 08:10:36 -0800 (PST) Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 30DEdU6h011808; Fri, 13 Jan 2023 16:10:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=MCA785kWBXhTrXwJ6eVYTY5/yNgfBkb57o0LJH0dY9A=; b=nxGRs6vflBgqeafYJe0QVHV5KyuYMagBZec0Tvo+RctM9oY3Z58UhupTZpSxIp7sLte1 CIWQK5n4QQ3yoOBk7FaEVnOCeEIRS80gFMtTmIVUK1MDizrloRUqFcrllAOASAPGFgdl L08ZoDHiNgsCQtiz49iv+RyKaW0xAL/rKAvKoLo9qDu3EEUarms40iz2hrgtrrkmoeIE ia5KJMK0q3GLfNS9aim9a/R34992HbNKHYy5fcKhdFE9FmYee/D69Q7hiwf08YGMMJZ8 W53BIrIauokylBeQ0s39OzB1Jww4cWzyNROb8gpwwX6QWnyGMV2SO524gWrfNA4jiPm3 gA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3n38uh2vwp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Jan 2023 16:10:28 +0000 Received: from m0098410.ppops.net (m0098410.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 30DEhFnR021842; Fri, 13 Jan 2023 16:10:28 GMT Received: from ppma02wdc.us.ibm.com (aa.5b.37a9.ip4.static.sl-reverse.com [169.55.91.170]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3n38uh2vvx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Jan 2023 16:10:28 +0000 Received: from pps.filterd (ppma02wdc.us.ibm.com [127.0.0.1]) by ppma02wdc.us.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 30DDYKrO019012; Fri, 13 Jan 2023 16:10:27 GMT Received: from smtprelay06.wdc07v.mail.ibm.com ([9.208.129.118]) by ppma02wdc.us.ibm.com (PPS) with ESMTPS id 3n1knv8jvm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Jan 2023 16:10:27 +0000 Received: from smtpav04.wdc07v.mail.ibm.com (smtpav04.wdc07v.mail.ibm.com [10.39.53.231]) by smtprelay06.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 30DGAQ2G56361366 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Jan 2023 16:10:26 GMT Received: from smtpav04.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E40B958061; Fri, 13 Jan 2023 16:10:25 +0000 (GMT) Received: from smtpav04.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E997D58045; Fri, 13 Jan 2023 16:10:24 +0000 (GMT) Received: from slate16.aus.stglabs.ibm.com (unknown [9.77.137.189]) by smtpav04.wdc07v.mail.ibm.com (Postfix) with ESMTP; Fri, 13 Jan 2023 16:10:24 +0000 (GMT) From: Eddie James To: linux-integrity@vger.kernel.org Cc: linux-kernel@vger.kernel.org, jgg@ziepe.ca, jarkko@kernel.org, peterhuewe@gmx.de, Eddie James Subject: [PATCH v2 1/2] tpm: Use managed allocation for bios event log Date: Fri, 13 Jan 2023 10:10:16 -0600 Message-Id: <20230113161017.1079299-2-eajames@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230113161017.1079299-1-eajames@linux.ibm.com> References: <20230113161017.1079299-1-eajames@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: v9EIH36wdkK4rvURnBuFOuV6IArU728m X-Proofpoint-ORIG-GUID: JtZJf8Qb-xRXW1AQKjLBjQGQVRw7F6wn X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.923,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-01-13_07,2023-01-13_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 spamscore=0 mlxlogscore=999 impostorscore=0 malwarescore=0 clxscore=1015 mlxscore=0 lowpriorityscore=0 bulkscore=0 adultscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301130107 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754925377327134412?= X-GMAIL-MSGID: =?utf-8?q?1754925377327134412?= Since the bios event log is freed in the device release function, let devres handle the deallocation. This will allow other memory allocation/mapping functions to be used for the bios event log. Signed-off-by: Eddie James Tested-by: Jarkko Sakkinen Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/eventlog/acpi.c | 5 +++-- drivers/char/tpm/eventlog/efi.c | 13 +++++++------ drivers/char/tpm/eventlog/of.c | 3 ++- drivers/char/tpm/tpm-chip.c | 1 - 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/drivers/char/tpm/eventlog/acpi.c b/drivers/char/tpm/eventlog/acpi.c index 0913d3eb8d51..40360e599bc3 100644 --- a/drivers/char/tpm/eventlog/acpi.c +++ b/drivers/char/tpm/eventlog/acpi.c @@ -14,6 +14,7 @@ * Access to the event log extended by the TCG BIOS of PC platform */ +#include #include #include #include @@ -135,7 +136,7 @@ int tpm_read_log_acpi(struct tpm_chip *chip) } /* malloc EventLog space */ - log->bios_event_log = kmalloc(len, GFP_KERNEL); + log->bios_event_log = devm_kmalloc(&chip->dev, len, GFP_KERNEL); if (!log->bios_event_log) return -ENOMEM; @@ -160,7 +161,7 @@ int tpm_read_log_acpi(struct tpm_chip *chip) return format; err: - kfree(log->bios_event_log); + devm_kfree(&chip->dev, log->bios_event_log); log->bios_event_log = NULL; return ret; } diff --git a/drivers/char/tpm/eventlog/efi.c b/drivers/char/tpm/eventlog/efi.c index e6cb9d525e30..4e9d7c2bf32e 100644 --- a/drivers/char/tpm/eventlog/efi.c +++ b/drivers/char/tpm/eventlog/efi.c @@ -6,6 +6,7 @@ * Thiebaud Weksteen */ +#include #include #include @@ -55,7 +56,7 @@ int tpm_read_log_efi(struct tpm_chip *chip) } /* malloc EventLog space */ - log->bios_event_log = kmemdup(log_tbl->log, log_size, GFP_KERNEL); + log->bios_event_log = devm_kmemdup(&chip->dev, log_tbl->log, log_size, GFP_KERNEL); if (!log->bios_event_log) { ret = -ENOMEM; goto out; @@ -76,7 +77,7 @@ int tpm_read_log_efi(struct tpm_chip *chip) MEMREMAP_WB); if (!final_tbl) { pr_err("Could not map UEFI TPM final log\n"); - kfree(log->bios_event_log); + devm_kfree(&chip->dev, log->bios_event_log); ret = -ENOMEM; goto out; } @@ -91,11 +92,11 @@ int tpm_read_log_efi(struct tpm_chip *chip) * Allocate memory for the 'combined log' where we will append the * 'final events log' to. */ - tmp = krealloc(log->bios_event_log, - log_size + final_events_log_size, - GFP_KERNEL); + tmp = devm_krealloc(&chip->dev, log->bios_event_log, + log_size + final_events_log_size, + GFP_KERNEL); if (!tmp) { - kfree(log->bios_event_log); + devm_kfree(&chip->dev, log->bios_event_log); ret = -ENOMEM; goto out; } diff --git a/drivers/char/tpm/eventlog/of.c b/drivers/char/tpm/eventlog/of.c index a9ce66d09a75..741ab2204b11 100644 --- a/drivers/char/tpm/eventlog/of.c +++ b/drivers/char/tpm/eventlog/of.c @@ -10,6 +10,7 @@ * Read the event log created by the firmware on PPC64 */ +#include #include #include #include @@ -65,7 +66,7 @@ int tpm_read_log_of(struct tpm_chip *chip) return -EIO; } - log->bios_event_log = kmemdup(__va(base), size, GFP_KERNEL); + log->bios_event_log = devm_kmemdup(&chip->dev, __va(base), size, GFP_KERNEL); if (!log->bios_event_log) return -ENOMEM; diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index 741d8f3e8fb3..b99f55f2d4fd 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -267,7 +267,6 @@ static void tpm_dev_release(struct device *dev) idr_remove(&dev_nums_idr, chip->dev_num); mutex_unlock(&idr_lock); - kfree(chip->log.bios_event_log); kfree(chip->work_space.context_buf); kfree(chip->work_space.session_buf); kfree(chip->allocated_banks); From patchwork Fri Jan 13 16:10:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eddie James X-Patchwork-Id: 43414 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp362516wrt; Fri, 13 Jan 2023 08:27:38 -0800 (PST) X-Google-Smtp-Source: AMrXdXutx9BSPiWInPXi3BQYpToNsfcFW7nA2WA0U96/9+hKdCGgJvXKq9vG/xbCL7svJTfxVYea X-Received: by 2002:a17:90b:1d0a:b0:226:e466:9e9b with SMTP id on10-20020a17090b1d0a00b00226e4669e9bmr27032312pjb.4.1673627258138; Fri, 13 Jan 2023 08:27:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673627258; cv=none; d=google.com; s=arc-20160816; b=g6zmmN2hYU8CS3bOyyDwodAEkI3Exi2/7G4cwT74HBg0L2Ai4N1fOcIj8F6UNHfbfR e3osE3KVn0iwtNrjy9P3FffZJWB1jgiD6olkuh3EHKrG4lyQhNAoS+yOZhh+Kp2r+61H QK8k0yLLEZtnvFPPLa57LH8+PzjqAw1mBBW+RvjvyZAjh2aCx36Jn+iWqJSHx6z8tCVk WCnqF18dJydKJJRfHuHou3B7KfKDJz1GUaEGMJsZqeMU8Kz8yL+LSwXdBwzWyAamIBrV qrsxqSzxikw0gugzBCl4Il57TiWCmYWcV06KVHTeWL6sKdcBLUDAGFV4q2GEIpe857ju WiwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ln93bccdgNzFEICgGiX/7Ramezk+x3HjkrqS2NuE3WU=; b=iKIp4RA0ohhiiBTqF6Ac2Xx/f8pGodB5gO21I05+huBqsR2JdoCpWTRaX6DM3TRyVs pxMhuDtEuGLF5Oxq5/oh4PU7pzwydcUK9azxmnoQ+TeCCIKzPYPxzQWeTi4Pvu7yplae fytE/EAop3RS/vvJzEtDdYu7w1pejcJxn/gKrD305+6QSmR4iisK2/59HVLsi+Ems/q5 Zbi5YV9z6kcPrKlxgYdAVrfLMfHOo710WpZQjKn973OEF8o/KQWs2EALzhILObGfU6nG /QwXVi43qamr9EeYfcFMyC1xJ/tyPclGm3IpjqnvV6EhZey2NjT6j5/GHx6vX7V36pHf i3sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=k9rr3l4i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id li12-20020a17090b48cc00b00210d1aeabc1si13603455pjb.188.2023.01.13.08.27.25; Fri, 13 Jan 2023 08:27:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=k9rr3l4i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229476AbjAMQR4 (ORCPT + 99 others); Fri, 13 Jan 2023 11:17:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230314AbjAMQRS (ORCPT ); Fri, 13 Jan 2023 11:17:18 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BD8F96139; Fri, 13 Jan 2023 08:10:35 -0800 (PST) Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 30DFgS2k029121; Fri, 13 Jan 2023 16:10:33 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=ln93bccdgNzFEICgGiX/7Ramezk+x3HjkrqS2NuE3WU=; b=k9rr3l4icRSIXPa+1MPmP1osmVr37wrOBCyoa8FBOrgBFwEnwpuKmNqzv6t9YMjUr7je 3wY85f4rqV/WPsQf+CBv1ZMGwEo0h4Eb9XyAffaenVdxWpBvqo+Jx4uUHcTChjlO4ss4 SCMoehemR6ax/T/zjdbDSVxDksAd5+nMRAAhfmSE022P+mDIrzEUPJNtZoUSOhvTFjDs q1y1EmvL9bO3JzfdVk/XQ+41wIojTgxMqwrRikLJ2KQoUsKmbRD2QP0Ea7TW+OFrTfrt OVM2S5JytvueTR+8J+BCrfFrr0Ej3Azl2JywZnpXEdweP7MiQxPhJ/8wU7hVgnoY8N5U CA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3n3a60gp9f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Jan 2023 16:10:33 +0000 Received: from m0098404.ppops.net (m0098404.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 30DFl63j024687; Fri, 13 Jan 2023 16:10:32 GMT Received: from ppma01dal.us.ibm.com (83.d6.3fa9.ip4.static.sl-reverse.com [169.63.214.131]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3n3a60gp8u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Jan 2023 16:10:32 +0000 Received: from pps.filterd (ppma01dal.us.ibm.com [127.0.0.1]) by ppma01dal.us.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 30DEh0Lj014476; Fri, 13 Jan 2023 16:10:31 GMT Received: from smtprelay03.dal12v.mail.ibm.com ([9.208.130.98]) by ppma01dal.us.ibm.com (PPS) with ESMTPS id 3n1kv5mmus-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Jan 2023 16:10:31 +0000 Received: from smtpav04.wdc07v.mail.ibm.com (smtpav04.wdc07v.mail.ibm.com [10.39.53.231]) by smtprelay03.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 30DGAT1K9175726 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Jan 2023 16:10:29 GMT Received: from smtpav04.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0FFCA58054; Fri, 13 Jan 2023 16:10:28 +0000 (GMT) Received: from smtpav04.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 146C358045; Fri, 13 Jan 2023 16:10:27 +0000 (GMT) Received: from slate16.aus.stglabs.ibm.com (unknown [9.77.137.189]) by smtpav04.wdc07v.mail.ibm.com (Postfix) with ESMTP; Fri, 13 Jan 2023 16:10:26 +0000 (GMT) From: Eddie James To: linux-integrity@vger.kernel.org Cc: linux-kernel@vger.kernel.org, jgg@ziepe.ca, jarkko@kernel.org, peterhuewe@gmx.de, Eddie James Subject: [PATCH v2 2/2] tpm: Add reserved memory event log Date: Fri, 13 Jan 2023 10:10:17 -0600 Message-Id: <20230113161017.1079299-3-eajames@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230113161017.1079299-1-eajames@linux.ibm.com> References: <20230113161017.1079299-1-eajames@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 9p6qPd3AXBWLpQhChDZQnHeCN1hJKZr2 X-Proofpoint-GUID: 6nsl0VfiKurJL0GwwHUe7wccLZp6ptzj X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.923,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-01-13_07,2023-01-13_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 priorityscore=1501 mlxscore=0 suspectscore=0 clxscore=1015 mlxlogscore=999 spamscore=0 adultscore=0 lowpriorityscore=0 phishscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301130107 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754925370850260529?= X-GMAIL-MSGID: =?utf-8?q?1754925376009879117?= Some platforms may desire to pass the event log up to linux in the form of a reserved memory region. Add support for this in the TPM core to find the reserved memory region and map it. Signed-off-by: Eddie James --- drivers/char/tpm/eventlog/of.c | 38 +++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/drivers/char/tpm/eventlog/of.c b/drivers/char/tpm/eventlog/of.c index 741ab2204b11..c815cadf00a4 100644 --- a/drivers/char/tpm/eventlog/of.c +++ b/drivers/char/tpm/eventlog/of.c @@ -12,12 +12,48 @@ #include #include +#include +#include #include +#include +#include #include #include "../tpm.h" #include "common.h" +static int tpm_read_log_memory_region(struct tpm_chip *chip) +{ + struct device_node *node; + struct resource res; + int rc; + + node = of_parse_phandle(chip->dev.parent->of_node, "memory-region", 0); + if (!node) { + dev_info(&chip->dev, "no phandle\n"); + return -ENODEV; + } + + rc = of_address_to_resource(node, 0, &res); + of_node_put(node); + if (rc) { + dev_info(&chip->dev, "no mem\n"); + return rc; + } + + chip->log.bios_event_log = devm_memremap(&chip->dev, res.start, resource_size(&res), + MEMREMAP_WB); + if (!chip->log.bios_event_log) { + dev_info(&chip->dev, "err memremap\n"); + return -ENOMEM; + } + + chip->log.bios_event_log_end = chip->log.bios_event_log + resource_size(&res); + + return chip->flags & TPM_CHIP_FLAG_TPM2 ? EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 : + EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2; +} + int tpm_read_log_of(struct tpm_chip *chip) { struct device_node *np; @@ -39,7 +75,7 @@ int tpm_read_log_of(struct tpm_chip *chip) sizep = of_get_property(np, "linux,sml-size", NULL); basep = of_get_property(np, "linux,sml-base", NULL); if (sizep == NULL && basep == NULL) - return -ENODEV; + return tpm_read_log_memory_region(chip); if (sizep == NULL || basep == NULL) return -EIO;