From patchwork Tue Jul 2 08:01:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 168284 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp3929669ilk; Tue, 2 Jul 2019 01:03:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqz7BsY60MDcNmoBN7SdrFIKNXpm5wimr1MHu5NCaJz+BG2J8X6KafB9eEJMuEZzqATeVTbh X-Received: by 2002:a17:90a:360c:: with SMTP id s12mr4192952pjb.30.1562054609136; Tue, 02 Jul 2019 01:03:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562054609; cv=none; d=google.com; s=arc-20160816; b=utOvaC527SK5I/T5ShoU7MOO8OBl8jImdTeoDdPeb34Ph7cDoTJvR2JbdFv0sWqxPv lpFYr82fMnbeR/lz26PoS4PqB+SLnJbyknN0mzRp04xrILIqNV/lftgKqp0nUHtMu7Hv NvgvW/c9fKAI98pEbl2SObwIRAdAeRxj3t+gEnCj8tj7aUlq3gelYb+cyZOJQlfv7B16 C/NabGylVMGL8D0+SH0gdXPEcrVaB663iYCq0F95ujIrFHW7IuIKlpWmtV8ZSsFAofO/ vdq7hdgPKIW37T0keFEL2KamL4pMi36LdENpF4plRQ4Sbx/PbwHiLhRVo1OlixJ3b2Kd bGfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=f2TIye5OxmvH6guigi2fWArAqsikLWnXrCfG37V1RtY=; b=haQwMlLBHkazhXFrIpUKfm2zut36mBQ/+gU/kYXL5FsollUGGjDuUEeaTACzsaiqJo QOl5LWbgOPfh4JhW/LEn7CaNIKp66iRMrXoaPgBHusTps37znTO7a1XbR8H+xoasJCXr aW0eNmnC67BPFAwr2X/pU4bmAYqaAkpaBXnx7Wi5hbCiufKA+fwj3MuZJoDvpEr94Dzj gLTVkZ8fhn2FcPLt1pFqhw1rOLJFt5G5metZrAwMugckVQ91d3X7YdGils1EG1UGnB28 IphMRkTL5vdUysL6eF1zc4uH58MVGb7Rzyo9oM3tmhRnOiXzKDQ0arOS97sAevPe9Ryi T7FA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=byqQbkww; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e9si12153219pgc.321.2019.07.02.01.03.28; Tue, 02 Jul 2019 01:03:29 -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=@kernel.org header.s=default header.b=byqQbkww; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727420AbfGBIDY (ORCPT + 30 others); Tue, 2 Jul 2019 04:03:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:48338 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727399AbfGBIDW (ORCPT ); Tue, 2 Jul 2019 04:03:22 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B823C21841; Tue, 2 Jul 2019 08:03:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562054601; bh=FWX6yoUmqpeNc3UXbOoiOv73WGfgMq7r2DRCslZmUHM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=byqQbkwwIW/3aHxCXxjoOwLbGJXfJLjIz3/cvVLLYBsCHsAN86/XsDldBiPQ4KEjG 8TYZ9AHrJZlsUPb5gM+ffGy3g0G9ot08TZ7O9HZFk6GeuKQByro8y4ipxS3t3tZAdY Q73i9R2H2zrWMbEflzTgt/Kv8VDey8Ej51ZqJitQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jonathan Richardson , Ard Biesheuvel Subject: [PATCH 5.1 25/55] efi/memreserve: deal with memreserve entries in unmapped memory Date: Tue, 2 Jul 2019 10:01:33 +0200 Message-Id: <20190702080125.373828717@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190702080124.103022729@linuxfoundation.org> References: <20190702080124.103022729@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ard Biesheuvel commit 18df7577adae6c6c778bf774b3aebcacbc1fb439 upstream. Ensure that the EFI memreserve entries can be accessed, even if they are located in memory that the kernel (e.g., a crashkernel) omits from the linear map. Fixes: 80424b02d42b ("efi: Reduce the amount of memblock reservations ...") Cc: # 5.0+ Reported-by: Jonathan Richardson Reviewed-by: Jonathan Richardson Tested-by: Jonathan Richardson Signed-off-by: Ard Biesheuvel Signed-off-by: Greg Kroah-Hartman --- drivers/firmware/efi/efi.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -1007,14 +1007,16 @@ int __ref efi_mem_reserve_persistent(phy /* first try to find a slot in an existing linked list entry */ for (prsv = efi_memreserve_root->next; prsv; prsv = rsv->next) { - rsv = __va(prsv); + rsv = memremap(prsv, sizeof(*rsv), MEMREMAP_WB); index = atomic_fetch_add_unless(&rsv->count, 1, rsv->size); if (index < rsv->size) { rsv->entry[index].base = addr; rsv->entry[index].size = size; + memunmap(rsv); return 0; } + memunmap(rsv); } /* no slot found - allocate a new linked list entry */ @@ -1022,7 +1024,13 @@ int __ref efi_mem_reserve_persistent(phy if (!rsv) return -ENOMEM; - rsv->size = EFI_MEMRESERVE_COUNT(PAGE_SIZE); + /* + * The memremap() call above assumes that a linux_efi_memreserve entry + * never crosses a page boundary, so let's ensure that this remains true + * even when kexec'ing a 4k pages kernel from a >4k pages kernel, by + * using SZ_4K explicitly in the size calculation below. + */ + rsv->size = EFI_MEMRESERVE_COUNT(SZ_4K); atomic_set(&rsv->count, 1); rsv->entry[0].base = addr; rsv->entry[0].size = size; From patchwork Tue Jul 2 08:01:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 168285 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp3930847ilk; Tue, 2 Jul 2019 01:04:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqzZOfFcKLLY79nA6Ny1LLYfxNcY8Ep1Hjk/dPkTto56VZfhnyFkvIqushyspkXEqA0j9D8i X-Received: by 2002:a63:5c1c:: with SMTP id q28mr28737047pgb.288.1562054672847; Tue, 02 Jul 2019 01:04:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562054672; cv=none; d=google.com; s=arc-20160816; b=z8Yv1+ss5AkqshqARnverSMDMlvQmKLiRYJQlCmB9hboDkbeC0WgCwmd7hEea/7rwk QOhGONc8kxIjv1L75YxQ37nDuS9dl2uFFaf75S7Rm2CnoitacrIguLEdWGnQSC9en/tj Y/G33mY+A38r0PYXKmCXgrZcw3aW0Dpfcc9qPvS92oOrEErVkLlaZynA9piLneJUaojB GDiviANdyWPZxRCSIkS6gqGzI0NfKtUGvFPzTKWEKsGthnlLhvYhktgIUDDffv+nYEMT ppVmuit5GfVMib20ejF+Ffs8gK1GvIfpPTw9EQYxf9kZgLC0jsOf7UqQD3ngGcfiKYrK bmPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=smwADwmnPQHrDMAIex54M14jdc9d+yYb03vjNtzVKkE=; b=sYLK7w/Atr+6cR5q+GVDnVsMnHGZik8xUAK5XsWV7vBVIF5j9kwEKE1fVXJjdVokka srYdHIIls+xkDHkxyKOB+vQLzMO0KKXsC+lpt6QkBt9FhGXqBAWheat/rDy2n1xN4A5w wJJtnVPb/VG8qVtn9vL0mcIraR/2x9e7MGpQ4tA83JghLzBst9EoUtkkoCf3FP9Tfzm1 EqSGVGwbg5j8aUWnRHmOJeObLFXh1uA5Io8S4EYWk8oQY1W6TgFgcDvZ7Dr21g1woYJq FCSh9cI7zhRMtx02mzuXSHwLrbi+lqUdU4v0b/MoGSIaCSX9sngFrH+IPLxwyat7CVLw g2ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=eQNgn5Ie; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x1si1655199pju.84.2019.07.02.01.04.32; Tue, 02 Jul 2019 01:04:32 -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=@kernel.org header.s=default header.b=eQNgn5Ie; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727743AbfGBIEb (ORCPT + 30 others); Tue, 2 Jul 2019 04:04:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:49938 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727726AbfGBIE2 (ORCPT ); Tue, 2 Jul 2019 04:04:28 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B7C6A20659; Tue, 2 Jul 2019 08:04:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562054668; bh=emvwUdVW0+nZbV6MltQoEQlRpt9QAeRJY2O4pV29Klw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eQNgn5IeUXjFIM/aUxnKj4cU4jMlZtGVUB+NTxtdC9RS8NOj7z23+wmJBAOb8771R 1/IwbOHoz0EaNmF86cNFfwkrDLx2twgajJqa4Thr24NWdUYGciwTri29xuGoXp3znJ O2wYJBzcCcxNOuRLtqpBRVLHqOHlgHF6kO8SlWrg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Will Deacon Subject: [PATCH 5.1 50/55] arm64: futex: Avoid copying out uninitialised stack in failed cmpxchg() Date: Tue, 2 Jul 2019 10:01:58 +0200 Message-Id: <20190702080126.687857009@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190702080124.103022729@linuxfoundation.org> References: <20190702080124.103022729@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Will Deacon commit 8e4e0ac02b449297b86498ac24db5786ddd9f647 upstream. Returning an error code from futex_atomic_cmpxchg_inatomic() indicates that the caller should not make any use of *uval, and should instead act upon on the value of the error code. Although this is implemented correctly in our futex code, we needlessly copy uninitialised stack to *uval in the error case, which can easily be avoided. Signed-off-by: Will Deacon Signed-off-by: Greg Kroah-Hartman --- arch/arm64/include/asm/futex.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/arch/arm64/include/asm/futex.h +++ b/arch/arm64/include/asm/futex.h @@ -134,7 +134,9 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, : "memory"); uaccess_disable(); - *uval = val; + if (!ret) + *uval = val; + return ret; }