From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752422AbcFCK47 (ORCPT ); Fri, 3 Jun 2016 06:56:59 -0400 Received: from terminus.zytor.com ([198.137.202.10]:56610 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932570AbcFCK45 (ORCPT ); Fri, 3 Jun 2016 06:56:57 -0400 Date: Fri, 3 Jun 2016 03:56:18 -0700 From: tip-bot for Vitaly Kuznetsov Message-ID: Cc: torvalds@linux-foundation.org, peterz@infradead.org, msalter@redhat.com, mingo@kernel.org, hpa@zytor.com, vkuznets@redhat.com, ard.biesheuvel@linaro.org, matt@codeblueprint.co.uk, linux-kernel@vger.kernel.org, kys@microsoft.com, tglx@linutronix.de Reply-To: tglx@linutronix.de, kys@microsoft.com, vkuznets@redhat.com, ard.biesheuvel@linaro.org, linux-kernel@vger.kernel.org, matt@codeblueprint.co.uk, mingo@kernel.org, hpa@zytor.com, peterz@infradead.org, msalter@redhat.com, torvalds@linux-foundation.org In-Reply-To: <1464690224-4503-2-git-send-email-matt@codeblueprint.co.uk> References: <1464690224-4503-2-git-send-email-matt@codeblueprint.co.uk> To: linux-tip-commits@vger.kernel.org Subject: [tip:efi/urgent] efi: Fix for_each_efi_memory_desc_in_map() for empty memmaps Git-Commit-ID: 55f1ea15216a5a14c96738bd5284100a00ffa9dc X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 55f1ea15216a5a14c96738bd5284100a00ffa9dc Gitweb: http://git.kernel.org/tip/55f1ea15216a5a14c96738bd5284100a00ffa9dc Author: Vitaly Kuznetsov AuthorDate: Tue, 31 May 2016 11:23:43 +0100 Committer: Ingo Molnar CommitDate: Fri, 3 Jun 2016 09:57:35 +0200 efi: Fix for_each_efi_memory_desc_in_map() for empty memmaps Commit: 78ce248faa3c ("efi: Iterate over efi.memmap in for_each_efi_memory_desc()") introduced a regression for systems booted with the 'noefi' kernel option. In particular, I observed an early kernel hang in efi_find_mirror()'s for_each_efi_memory_desc() call. As we don't have efi memmap on this system we enter this iterator with the following parameters: efi.memmap.map = 0, efi.memmap.map_end = 0, efi.memmap.desc_size = 28 ... then for_each_efi_memory_desc_in_map() does the following comparison: (md) <= (efi_memory_desc_t *)((m)->map_end - (m)->desc_size); ... where md = 0, (m)->map_end = 0 and (m)->desc_size = 28 but when we subtract something from a NULL pointer wrap around happens and we end up returning invalid pointer and crash. Fix it by using the correct pointer arithmetics. Signed-off-by: Vitaly Kuznetsov Signed-off-by: Matt Fleming Cc: Ard Biesheuvel Cc: K. Y. Srinivasan Cc: Linus Torvalds Cc: Mark Salter Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: linux-efi@vger.kernel.org Fixes: 78ce248faa3c ("efi: Iterate over efi.memmap in for_each_efi_memory_desc()") Link: http://lkml.kernel.org/r/1464690224-4503-2-git-send-email-matt@codeblueprint.co.uk [ Made the changelog more readable. ] Signed-off-by: Ingo Molnar --- include/linux/efi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/efi.h b/include/linux/efi.h index c2db3ca..f196dd0 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -1005,7 +1005,7 @@ extern int efi_memattr_apply_permissions(struct mm_struct *mm, /* Iterate through an efi_memory_map */ #define for_each_efi_memory_desc_in_map(m, md) \ for ((md) = (m)->map; \ - (md) <= (efi_memory_desc_t *)((m)->map_end - (m)->desc_size); \ + ((void *)(md) + (m)->desc_size) <= (m)->map_end; \ (md) = (void *)(md) + (m)->desc_size) /**