Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2511198imm; Thu, 19 Jul 2018 23:15:12 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfRvD2z9nACaDINvofkhcBVTXsPQgnFIMt5MRDxuD1iyYUx8WTBim0y3A32He9Oihp+Xfid X-Received: by 2002:aa7:87d0:: with SMTP id i16-v6mr865375pfo.82.1532067312573; Thu, 19 Jul 2018 23:15:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532067312; cv=none; d=google.com; s=arc-20160816; b=MAe8L2wSYJyryJPvoTK3TpBdvdcBd18jRaPmu0L8h2EHpxkvVAP5MjNHrK0hO3Xb81 MzFCFN49BlzOJggcEpAGz7zxDBGbi5D3KPocn2zqsePqwxgrnNudAJ9C8ZXisZtSsQXI WrpVRiGqudPJDEITxW65FrrYjbeJMnXy0yzYX6Bw4r1EXzHRR4KbzDtK2/Zq8TFWj0Tz Q2jm0htXvGRA1CySEFqPPHtjZ5TOP0dWRi6cm3//ULAbaBJyPc6zUGIMez3+c9nFWuSB Q3ON9FGvawKc/Hoi3ELiEuGllh0AZa5vQhRkY0jMkx1BjxPlmMnyrSC1lUeD1wwKzcGb 98Ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:mail-followup-to :message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=62RNlA/AXthYMrggsGhdb3vhBaClUjFY4s/voIRvkho=; b=U+CfZiM6yLsP6LWh5nbhL7i4KcHRhZUMQBwj2unq/tjs/cZUCy6ljin4Ni+9Nl3wP4 tefrf4FnNG5ccs+cC+PztA0k9wkcsINH6XeIwazxE+7XLatAIDjmufNcJjWWYJgHHNQB CJ+N4of2/cXf8SJXkQ9FpRqndsQSvtvTK2uS8N/+lJWY+//ntayHmp4exIxFYWXLAPaa 2Qd7sGJ6DlSOm5kaY+QBN2iUohjvale2mCtXhFu5YT18V+b2SWZsr0pAm3t5wizI5E7a ej3OG1w95XFUpAFQXMK4XiKdMkmTA93GJqx0iFC+KcuSOrJDmjWZCTXOn1NkCM3XXiib 43Cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UEn6kDHj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o1-v6si1040038pge.572.2018.07.19.23.14.57; Thu, 19 Jul 2018 23:15:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UEn6kDHj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727984AbeGTG7w (ORCPT + 99 others); Fri, 20 Jul 2018 02:59:52 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:34276 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727545AbeGTG7w (ORCPT ); Fri, 20 Jul 2018 02:59:52 -0400 Received: by mail-pg1-f196.google.com with SMTP id y5-v6so5932703pgv.1 for ; Thu, 19 Jul 2018 23:13:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to:user-agent; bh=62RNlA/AXthYMrggsGhdb3vhBaClUjFY4s/voIRvkho=; b=UEn6kDHjq3tLdVd38q9B7lwrDDiTowfnwdUJVSPPS45lOs+dStqjRESP5JU+rUSXvy QlcQfUiwdGNnIf84QPct5+c89e0KRbrC0Lxa94XIH0WH0Ye2cMI0jRDyS3E8+P4a9U6S 1WmxwCn/MeFH8iZgEYZJBQsIdVaZdDvnoA1K4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to:user-agent; bh=62RNlA/AXthYMrggsGhdb3vhBaClUjFY4s/voIRvkho=; b=AxqL3w1vPoXnIYuFUiuEsTO6+vY0jv6jjYyxiL28gxdgEdLiEi6K41pBbvPWLJBSdT qx2VNFwG7No+yfXhA/vQZpzRD7H2zOOSL8y4HwRp6mzxp3ertX460zrIPl1sFXMvIwdC l5iP1DaNtll0BjLiNUPE7mWB5z5zAg9leXYi01dXKfZnxa7xV7ua+D+TL7IYORHZQGdV 6ZBUTifhuL0DV/scXT4r5cd41GlPu1kFfgs8goRuysRsUlpghME/nIO7G0RNM9II7pMJ JPqIo7uBlD7ezzCDn0IqVsgXARvTWDfwFjSqyQuSNIBBJ1grvteskD8b5dCdeaN/JkdD j13Q== X-Gm-Message-State: AOUpUlHRefR+deoGyCpKijKWuOxnxsu1KLvfj/Q5qsPmECvmY/G72lLZ uyIpLS4gI/W2yn98yYAHsf83QQ== X-Received: by 2002:a63:4811:: with SMTP id v17-v6mr738660pga.379.1532067196421; Thu, 19 Jul 2018 23:13:16 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id q140-v6sm1194936pgq.11.2018.07.19.23.13.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jul 2018 23:13:15 -0700 (PDT) Date: Fri, 20 Jul 2018 15:14:36 +0900 From: AKASHI Takahiro To: James Morse Cc: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v11 10/15] arm64: kexec_file: allow for loading Image-format kernel Message-ID: <20180720061434.GK11258@linaro.org> Mail-Followup-To: AKASHI Takahiro , James Morse , catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <20180711074203.3019-1-takahiro.akashi@linaro.org> <20180711074203.3019-11-takahiro.akashi@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 18, 2018 at 05:47:50PM +0100, James Morse wrote: > Hi Akashi, > > On 11/07/18 08:41, AKASHI Takahiro wrote: > > This patch provides kexec_file_ops for "Image"-format kernel. In this > > implementation, a binary is always loaded with a fixed offset identified > > in text_offset field of its header. > > > > Regarding signature verification for trusted boot, this patch doesn't > > contains CONFIG_KEXEC_VERIFY_SIG support, which is to be added later > > in this series, but file-attribute-based verification is still a viable > > option by enabling IMA security subsystem. > > > > You can sign(label) a to-be-kexec'ed kernel image on target file system > > with: > > $ evmctl ima_sign --key /path/to/private_key.pem Image > > > > On live system, you must have IMA enforced with, at least, the following > > security policy: > > "appraise func=KEXEC_KERNEL_CHECK appraise_type=imasig" > > > > See more details about IMA here: > > https://sourceforge.net/p/linux-ima/wiki/Home/ > > This looks useful to set a keys/signature/policy for a kernel that wasn't built > to enforce signatures at compile time, so its a good thing to have from a > single-image perspective. > > I haven't managed to get IMA working to test this, but its all done by the kexec > core code, so I don't think we're missing anything. > > > > diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c > > new file mode 100644 > > index 000000000000..a47cf9bc699e > > --- /dev/null > > +++ b/arch/arm64/kernel/kexec_image.c > > > +static int image_probe(const char *kernel_buf, unsigned long kernel_len) > > +{ > > + const struct arm64_image_header *h; > > + > > + h = (const struct arm64_image_header *)(kernel_buf); > > + > > + if (!h || (kernel_len < sizeof(*h)) || > > > + !memcmp(&h->magic, ARM64_MAGIC, sizeof(ARM64_MAGIC))) > > Doesn't memcmp() return 0 if the memory regions are the same? > This would always match the correct magic, rejecting the image. > > That's not whats happening, as kexec-file works, so this never matches anything. > > sizeof(ARM64_MAGIC) includes the null terminator, but this sequence is output in > head.S using '.ascii' which doesn't include the terminator, (otherwise it > wouldn't fit in the 4byte magic field). The memcmp() here is also consuming the > least significant bytes of the next field. > > I think this line should be: > | memcmp(&h->magic, ARM64_MAGIC, sizeof(h->magic))) Absolutely you're right! > > > +static void *image_load(struct kimage *image, > > + char *kernel, unsigned long kernel_len, > > + char *initrd, unsigned long initrd_len, > > + char *cmdline, unsigned long cmdline_len) > > > + kbuf.buffer = kernel; > > + kbuf.bufsz = kernel_len; > > + kbuf.memsz = le64_to_cpu(h->image_size); > > + text_offset = le64_to_cpu(h->text_offset); > > + kbuf.buf_align = SZ_2M; > > Nit: MIN_KIMG_ALIGN ? OK. > > > + /* Adjust kernel segment with TEXT_OFFSET */ > > + kbuf.memsz += text_offset; > > + > > + ret = kexec_add_buffer(&kbuf); > > + if (ret) > > + goto out; > > You just return in the error cases above but here you goto ... the return > statement at the end. Seems a bit odd. Will fix it. > > With the memcmp() thing fixed: > Reviewed-by: James Morse Always appreciate you reviewing. -Takahiro AKASHI > > Thanks, > > James