Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp487262pxb; Wed, 3 Nov 2021 07:29:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5SM7bufAEwtlpPJeyutA3A7U4CHT6Plh0xBbgFHEmCl89ywfc3Ss1SeiK6tbr7XOVJZGK X-Received: by 2002:a50:d802:: with SMTP id o2mr58315761edj.331.1635949784141; Wed, 03 Nov 2021 07:29:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635949784; cv=none; d=google.com; s=arc-20160816; b=L0juK+Tx0VzxjziPhHPembW+Lt19lB3ItxggMxrFvuV3SHTrhQJK52+7mLZtjEHpQJ yVVFRPUiwRCvlHdcGuNXaihEF8+588d1+P4zQR44NWRRRIuYgrVopKvHr/t/fL72Uxu1 h/RcGNQZG8xsUpLEbyAAo4PRrW80j9AmfYCEL6zSR5hm9k7fQ0FueJg+s7GeTRVEMZd5 rs48trElyYTiwWlMmni6T1FWHcsyUTv4fE6wgQKTOXH6Qb7gd504S0/Pg8TFabUc30xt wk9d2TyJehBJuwGZ8YKJ1JaAtyNnIhouNmNYp53GDcfHnJAwUX8XPY50JYIfNwsFtzzx +fYA== 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:dkim-signature; bh=WjVRAY/znLnXw9klPTASWRvUFX89s7VJBB58DLKxfUQ=; b=xdRN/MBcHIIujFgG9IXETwjH2NWpLf3Y+cTgoFDx/sst5XP4ZHV2bsrHBMdfkPopNm 74VX6YWz7g3avcFSMw/DeDBQASZt8aQMcKydsvdlLTSqFf4S9ANRgMYecyeS0i9LNDZN YIT3s/1gTYP/pasW3El2SuYQ7DKjUGr8Jz/LDcJ15piyT5feQqk+NuzV62oKi8GL0piR 1mUzD7VfV5jMxEwUZe5KZ2hTanENWpTmh93BeBn3IxHxGia/MI669E1C4boXdggUAjk5 2vftYhfBLZA1p8h4VvC8LBg923a9Pa0IBYB7nHwIP3Z9BbJQMQFuF14NKoe9kB6Rzbzp Neqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=hPdDISF7; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dp5si3983140ejc.155.2021.11.03.07.29.19; Wed, 03 Nov 2021 07:29:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=hPdDISF7; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232112AbhKCO3x (ORCPT + 99 others); Wed, 3 Nov 2021 10:29:53 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:52468 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231679AbhKCO3u (ORCPT ); Wed, 3 Nov 2021 10:29:50 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 005D21FD39; Wed, 3 Nov 2021 14:27:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1635949633; 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=WjVRAY/znLnXw9klPTASWRvUFX89s7VJBB58DLKxfUQ=; b=hPdDISF7zAFlR3D1VghEwmjLHCyJzAEZGI0T8s7i9kBvzyNFjrw+frUJBJfEZeC8Ip0b2k 9CYntkKVcibvtIt4bOiDd2rt7wfUJMSf6sMOczsmStyf+tPif9oe5fW8uRhLvXi6kodmy2 B8ic5OKRxc3H7Yhx3sv/wI4gfMCqG1w= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1635949633; 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=WjVRAY/znLnXw9klPTASWRvUFX89s7VJBB58DLKxfUQ=; b=M/L7iHHfkmz+2rw50TnNglTComYCUk4dpfnWf3iG+LhOoQW3W2vt25Q5xGT8rHAr1z6NTC faUcUhialZOVm3AQ== Received: from kitsune.suse.cz (kitsune.suse.cz [10.100.12.127]) by relay2.suse.de (Postfix) with ESMTP id D155AA3B92; Wed, 3 Nov 2021 14:27:12 +0000 (UTC) From: Michal Suchanek To: keyrings@vger.kernel.org Cc: Michal Suchanek , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Alexander Gordeev , David Howells , Luis Chamberlain , Jessica Yu , Rob Herring , Lakshmi Ramasubramanian , Thiago Jung Bauermann , Hari Bathini , Frank van der Linden , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org Subject: [PATCH 3/3] powerpc/kexec_file: Add KEXEC_SIG support. Date: Wed, 3 Nov 2021 15:27:08 +0100 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use the module verifier for the kernel image verification. Signed-off-by: Michal Suchanek --- arch/powerpc/Kconfig | 11 +++++++++++ arch/powerpc/kexec/elf_64.c | 14 ++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index 743c9783c64f..27bffafa9e79 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -558,6 +558,17 @@ config KEXEC_FILE config ARCH_HAS_KEXEC_PURGATORY def_bool KEXEC_FILE +config KEXEC_SIG + bool "Verify kernel signature during kexec_file_load() syscall" + depends on KEXEC_FILE && MODULE_SIG_FORMAT + help + This option makes kernel signature verification mandatory for + the kexec_file_load() syscall. + + In addition to that option, you need to enable signature + verification for the corresponding kernel image type being + loaded in order for this to work. + config PPC64_BUILD_ELF_V2_ABI bool diff --git a/arch/powerpc/kexec/elf_64.c b/arch/powerpc/kexec/elf_64.c index eeb258002d1e..e8dff6b23ac5 100644 --- a/arch/powerpc/kexec/elf_64.c +++ b/arch/powerpc/kexec/elf_64.c @@ -23,6 +23,7 @@ #include #include #include +#include static void *elf64_load(struct kimage *image, char *kernel_buf, unsigned long kernel_len, char *initrd, @@ -151,7 +152,20 @@ static void *elf64_load(struct kimage *image, char *kernel_buf, return ret ? ERR_PTR(ret) : NULL; } +#ifdef CONFIG_KEXEC_SIG +int elf64_verify_sig(const char *kernel, unsigned long length) +{ + size_t kernel_len = length; + + return verify_appended_signature(kernel, &kernel_len, VERIFY_USE_PLATFORM_KEYRING, + "kexec_file"); +} +#endif /* CONFIG_KEXEC_SIG */ + const struct kexec_file_ops kexec_elf64_ops = { .probe = kexec_elf_probe, .load = elf64_load, +#ifdef CONFIG_KEXEC_SIG + .verify_sig = elf64_verify_sig, +#endif }; -- 2.31.1