From patchwork Tue Jul 24 06:57:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10541365 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 74A3014BC for ; Tue, 24 Jul 2018 07:00:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C6DE287D1 for ; Tue, 24 Jul 2018 07:00:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 50535286D9; Tue, 24 Jul 2018 07:00:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E0F242879B for ; Tue, 24 Jul 2018 07:00:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=hs8hsl7Xzfvxd7sxM3i3GEsCePRLjOu8uBeYi7geVw8=; b=lFsO9pBOxpxXRFIObNijqphZVf 05KswWoGmn08CBGY+NdpDRF8CXJHb0xdPORjsSS0/wsHaJsHZwh7h6QnOB22WGtq60I3wON0lEXAN Ciu9fYaQdLF3jQbsuvacxK3cMGQtTmfSAq1NroVJff50qImomALQQwASen+a4gQE4GI3La2GzTX9U z1NnoPsPK0Fp6uHP9UPUL11RmH07a9QV+3aQiYLLcOfFLt5G0Y7rA6EdeXpWL3NXELfgyS84rKfRB goT5CA7/qSU6NeN7pfHIorb7NWm2V+esqSpD35A0CN7XoM73mq/BfU2likoA/aD5ZTb2BXOsuvWRg JnLt0idQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fhrJV-0005HC-GV; Tue, 24 Jul 2018 07:00:53 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fhrIB-0002t3-7l for linux-arm-kernel@lists.infradead.org; Tue, 24 Jul 2018 06:59:41 +0000 Received: by mail-pg1-x543.google.com with SMTP id n7-v6so2192897pgq.4 for ; Mon, 23 Jul 2018 23:59:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DjZGq5WnpjvJN9iGuoJut9k6LjLfxTrv7tJcxElB2q4=; b=LOBGvQ46EyOi/qHw58fwmvardQ5MtYZdZsKI2bhd3NPyZ5Ngm05h1zVfpxB28HzYsy cC4OHjfFrWjqeyA6R50p272ExOYbm2fuM7josvLnYlfJCXoyHAdXS4h6od0vIP6qBJNY +HYqMAUASv9ZTXy+It/cFonObSZhmrKAg+Pqo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=DjZGq5WnpjvJN9iGuoJut9k6LjLfxTrv7tJcxElB2q4=; b=XoSCuM14aO3dEeH0apQ4Sb3su5QzK3TxxK31mva9nK/08fuUWZ6ZRS6HOuaa8L8gwB 0n3jey7JqogNbbrbmxm8k93lYnH93Zmq2QkhHgTkuOFynZ6IXhwumz0CdXbQzPePA2kl tuHyvu9Hfqib4+L7OwDtJXEk8hz0adjjumzxJT86RLir9A4FeGNphs3ACUl3YWQfE+0h Xe+gex0edvYsjLayMVJj7uUn7zlL0jPu1efK5ghJiFh0KnW4q4sbQRaklUv4NWlqlod1 n57c7DtASKTj1KI8CLJJxLqh4nrQ+d0AEgk8XZzFLOqnvOZmRmkP6JHSx4fMv5Fg6urc EU7Q== X-Gm-Message-State: AOUpUlH6hC2coFO0ap8tkAtF2Gw55eAzy74+s6szPuTE6KgVZcVQfp8b QQ03FfBkCZHFakIatpoyQ3sVEA== X-Google-Smtp-Source: AAOMgpeZJQX0AFXWrZnMLMf6ZKT19Qyca3w2nyk84CUXSpX7nVw5iYBL8EJwUB53Ymd+ne0tHPLXTA== X-Received: by 2002:a63:db05:: with SMTP id e5-v6mr15062646pgg.152.1532415560822; Mon, 23 Jul 2018 23:59:20 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id c6-v6sm2027520pfg.138.2018.07.23.23.59.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 23:59:20 -0700 (PDT) From: AKASHI Takahiro To: 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, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v12 16/16] arm64: kexec_file: add kaslr support Date: Tue, 24 Jul 2018 15:57:59 +0900 Message-Id: <20180724065759.19186-17-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180724065759.19186-1-takahiro.akashi@linaro.org> References: <20180724065759.19186-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180723_235931_857011_2F6C7EFB X-CRM114-Status: GOOD ( 13.92 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Adding "kaslr-seed" to dtb enables triggering kaslr, or kernel virtual address randomization, at secondary kernel boot. We always do this as it will have no harm on kaslr-incapable kernel. We don't have any "switch" to turn off this feature directly, but still can suppress it by passing "nokaslr" as a kernel boot argument. Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/kernel/machine_kexec_file.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index 7356da5a53d5..47a4fbd0dc34 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -46,6 +47,7 @@ static int setup_dtb(struct kimage *image, void *buf = NULL; size_t buf_size, range_size; int nodeoffset; + u64 value; int ret; /* check ranges against root's #address-cells and #size-cells */ @@ -158,6 +160,12 @@ static int setup_dtb(struct kimage *image, } } + /* add kaslr-seed */ + get_random_bytes(&value, sizeof(value)); + ret = fdt_setprop(buf, nodeoffset, "kaslr-seed", &value, sizeof(value)); + if (ret) + goto out_err; + /* trim a buffer */ fdt_pack(buf); *dtb_buf = buf;