From patchwork Mon Jan 10 13:49:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Suchanek X-Patchwork-Id: 12708838 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00698C43217 for ; Mon, 10 Jan 2022 13:50:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233979AbiAJNuJ (ORCPT ); Mon, 10 Jan 2022 08:50:09 -0500 Received: from smtp-out1.suse.de ([195.135.220.28]:36562 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230451AbiAJNuI (ORCPT ); Mon, 10 Jan 2022 08:50:08 -0500 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 84BB52113D; Mon, 10 Jan 2022 13:50:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1641822606; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IrWBD7TI68EgG0wGR5MEbMvcsfaxaq2AlRDdyvro99A=; b=ER1Ig+kbKfqELKLQrCGR4puUWqX6nCfeVapfUC/iwt8mKZSH5Eb5QxJkzoCz349hh+vda3 ND0UIkio8l1y074bT+8Cx3bcYBYAk/3A9t5OBSZcuoTb9iY1d9oxCMN+ZWXhQ7ucYrmOrT Susl5as4RKjIOsQf356SIK5FmFphnc4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1641822606; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IrWBD7TI68EgG0wGR5MEbMvcsfaxaq2AlRDdyvro99A=; b=kfcNRT7fN0cSjMRFNOlh5Fuwd3Ka9aRohhgvnb0dWnDJZ7eLXBC64pNyypsWLev+JfRBMo jw9CVIqrPigKGuDQ== Received: from kitsune.suse.cz (kitsune.suse.cz [10.100.12.127]) by relay2.suse.de (Postfix) with ESMTP id 40348A3B81; Mon, 10 Jan 2022 13:50:06 +0000 (UTC) From: Michal Suchanek To: keyrings@vger.kernel.org, linux-crypto@vger.kernel.org, linux-integrity@vger.kernel.org Cc: Michal Suchanek , kexec@lists.infradead.org, Philipp Rudo , Mimi Zohar , Nayna , Rob Herring , linux-s390@vger.kernel.org, Vasily Gorbik , Lakshmi Ramasubramanian , Heiko Carstens , Jessica Yu , linux-kernel@vger.kernel.org, David Howells , Christian Borntraeger , Luis Chamberlain , Paul Mackerras , Hari Bathini , Alexander Gordeev , linuxppc-dev@lists.ozlabs.org, Frank van der Linden , Thiago Jung Bauermann , Daniel Axtens , buendgen@de.ibm.com, Michael Ellerman , Benjamin Herrenschmidt , Christian Borntraeger , Herbert Xu , "David S. Miller" , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" , Sven Schnelle , Baoquan He , linux-security-module@vger.kernel.org Subject: [PATCH v4 1/6] s390/kexec_file: Don't opencode appended signature check. Date: Mon, 10 Jan 2022 14:49:53 +0100 Message-Id: <940cd6a0e88793060cdf5ddb7880c03564b38bdd.1641822505.git.msuchanek@suse.de> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: keyrings@vger.kernel.org Module verification already implements appeded signature check. Reuse it for kexec_file. The kexec_file implementation uses EKEYREJECTED error in some cases when there is no key and the common implementation uses ENOPKG or EBADMSG instead. Signed-off-by: Michal Suchanek Acked-by: Heiko Carstens Reviewed-by: Luis Chamberlain --- v3: Philipp Rudo : Update the commit with note about change of return value --- arch/s390/kernel/machine_kexec_file.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/arch/s390/kernel/machine_kexec_file.c b/arch/s390/kernel/machine_kexec_file.c index 8f43575a4dd3..c944d71316c7 100644 --- a/arch/s390/kernel/machine_kexec_file.c +++ b/arch/s390/kernel/machine_kexec_file.c @@ -31,6 +31,7 @@ int s390_verify_sig(const char *kernel, unsigned long kernel_len) const unsigned long marker_len = sizeof(MODULE_SIG_STRING) - 1; struct module_signature *ms; unsigned long sig_len; + int ret; /* Skip signature verification when not secure IPLed. */ if (!ipl_secure_flag) @@ -45,25 +46,12 @@ int s390_verify_sig(const char *kernel, unsigned long kernel_len) kernel_len -= marker_len; ms = (void *)kernel + kernel_len - sizeof(*ms); - kernel_len -= sizeof(*ms); + ret = mod_check_sig(ms, kernel_len, "kexec"); + if (ret) + return ret; sig_len = be32_to_cpu(ms->sig_len); - if (sig_len >= kernel_len) - return -EKEYREJECTED; - kernel_len -= sig_len; - - if (ms->id_type != PKEY_ID_PKCS7) - return -EKEYREJECTED; - - if (ms->algo != 0 || - ms->hash != 0 || - ms->signer_len != 0 || - ms->key_id_len != 0 || - ms->__pad[0] != 0 || - ms->__pad[1] != 0 || - ms->__pad[2] != 0) { - return -EBADMSG; - } + kernel_len -= sizeof(*ms) + sig_len; return verify_pkcs7_signature(kernel, kernel_len, kernel + kernel_len, sig_len,