From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751810AbdJYLOe (ORCPT ); Wed, 25 Oct 2017 07:14:34 -0400 Received: from terminus.zytor.com ([65.50.211.136]:58783 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751696AbdJYLO3 (ORCPT ); Wed, 25 Oct 2017 07:14:29 -0400 Date: Wed, 25 Oct 2017 04:09:52 -0700 From: tip-bot for Dan Carpenter Message-ID: Cc: linux-kernel@vger.kernel.org, ard.biesheuvel@linaro.org, mingo@kernel.org, torvalds@linux-foundation.org, peterz@infradead.org, hpa@zytor.com, dan.carpenter@oracle.com, ivan.hu@canonical.com, matt@codeblueprint.co.uk, tglx@linutronix.de Reply-To: hpa@zytor.com, peterz@infradead.org, tglx@linutronix.de, ivan.hu@canonical.com, dan.carpenter@oracle.com, matt@codeblueprint.co.uk, linux-kernel@vger.kernel.org, ard.biesheuvel@linaro.org, mingo@kernel.org, torvalds@linux-foundation.org In-Reply-To: <20171025100448.26056-2-ard.biesheuvel@linaro.org> References: <20171025100448.26056-2-ard.biesheuvel@linaro.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:efi/urgent] efi/efi_test: Prevent an Oops in efi_runtime_query_capsulecaps() Git-Commit-ID: 092e72c9edab16d4d6ad10c683a95047d53b6db4 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: 092e72c9edab16d4d6ad10c683a95047d53b6db4 Gitweb: https://git.kernel.org/tip/092e72c9edab16d4d6ad10c683a95047d53b6db4 Author: Dan Carpenter AuthorDate: Wed, 25 Oct 2017 11:04:47 +0100 Committer: Ingo Molnar CommitDate: Wed, 25 Oct 2017 12:10:59 +0200 efi/efi_test: Prevent an Oops in efi_runtime_query_capsulecaps() If "qcaps.capsule_count" is ULONG_MAX then "qcaps.capsule_count + 1" will overflow to zero and kcalloc() will return the ZERO_SIZE_PTR. We try to dereference it inside the loop and crash. Signed-off-by: Dan Carpenter Signed-off-by: Matt Fleming Signed-off-by: Ard Biesheuvel Acked-by: Ivan Hu Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: linux-efi@vger.kernel.org Fixes: ff6301dabc3c ("efi: Add efi_test driver for exporting UEFI runtime service interfaces") Link: http://lkml.kernel.org/r/20171025100448.26056-2-ard.biesheuvel@linaro.org Signed-off-by: Ingo Molnar --- drivers/firmware/efi/test/efi_test.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/firmware/efi/test/efi_test.c b/drivers/firmware/efi/test/efi_test.c index 08129b7..41c48a1 100644 --- a/drivers/firmware/efi/test/efi_test.c +++ b/drivers/firmware/efi/test/efi_test.c @@ -593,6 +593,9 @@ static long efi_runtime_query_capsulecaps(unsigned long arg) if (copy_from_user(&qcaps, qcaps_user, sizeof(qcaps))) return -EFAULT; + if (qcaps.capsule_count == ULONG_MAX) + return -EINVAL; + capsules = kcalloc(qcaps.capsule_count + 1, sizeof(efi_capsule_header_t), GFP_KERNEL); if (!capsules)