From patchwork Wed Jul 12 14:44:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 9836883 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 30E2C60363 for ; Wed, 12 Jul 2017 14:46:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 21822204C1 for ; Wed, 12 Jul 2017 14:46:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 14168284FF; Wed, 12 Jul 2017 14:46:10 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 225BB204C1 for ; Wed, 12 Jul 2017 14:46:08 +0000 (UTC) Received: (qmail 3112 invoked by uid 550); 12 Jul 2017 14:45:25 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 1993 invoked from network); 12 Jul 2017 14:45:24 -0000 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=6t6pMbhX4pX7Yu5ZB9QOw4PYWBfSyG+8NlSPFUpn6+Y=; b=NGrUqMaylW7/6vXUPusu/jmFZmSLDIZvSzePczh2xrEbnDX22Qo+RI6Uy0aXuRupE7 K4TGv+4AmuUYJ7pWRr61NnZ8XCE/2rzHkg/9hPN/SsjYTSWJRDCqLwMbLCLBpki7o6TG BZuzkmRkhAoY4wZrE9okTudkJ+YdI3lMg5UG8= 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=6t6pMbhX4pX7Yu5ZB9QOw4PYWBfSyG+8NlSPFUpn6+Y=; b=GqgvHc6iOwoMJOJoPGyQwS2ibj5EvSrteWYCnW4j9HGM1lcJIjpFMbDFaIii8ERUuB 3qjZEnHf5O1OqY4W5AoQZuTO7XnCucD5zu7I+BWs9WnBQtO3NTEhqC15b694DOFBax07 xn/pdILIy6XQmP7mdm3CQE1jGHa5oQ4nIZDRKozKYLfnqdTXo07F5E4aUEsJAaWZ5PW6 vG4KqC0E9lTq0Ae8/oxXrw+2I4hkRw+4UnQyUQKDQcmXJlzbROlGw9JivGDu7oAv5qfv O1HGHq4bD0CCLE8EPKW4zGJ73dPXlLbiAWCKqSLk8XGvGpEbIRZldafKBb2dadcb9Dr7 mZCQ== X-Gm-Message-State: AIVw112FbLPiHhCKeNLLDhwtvmFlmxdBrLvlBp8PK+SC9w48HgkUs4uS lc26JGrjTgoPyJfQae4xlg== X-Received: by 10.223.180.88 with SMTP id v24mr2956076wrd.29.1499870713119; Wed, 12 Jul 2017 07:45:13 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, kernel-hardening@lists.openwall.com Cc: mark.rutland@arm.com, labbott@fedoraproject.org, will.deacon@arm.com, dave.martin@arm.com, catalin.marinas@arm.com, Ard Biesheuvel Date: Wed, 12 Jul 2017 15:44:22 +0100 Message-Id: <20170712144424.19528-10-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170712144424.19528-1-ard.biesheuvel@linaro.org> References: <20170712144424.19528-1-ard.biesheuvel@linaro.org> Subject: [kernel-hardening] [RFC PATCH 09/10] arm64: mm: add C level handling for stack overflows X-Virus-Scanned: ClamAV using ClamSMTP Add the code to __do_kernel_fault() to force a panic when the faulting address of a data abort points into the guard page below the current task's stack. Currently, we won't be able to make it all the way here under such a condition, but that will be addressed in a subsequent patch. Signed-off-by: Ard Biesheuvel --- arch/arm64/mm/fault.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index c7861c9864e6..b3317e5ff5dd 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -229,6 +229,21 @@ static void __do_kernel_fault(unsigned long addr, unsigned int esr, return; /* + * If we faulted on the guard page below this task's stack, + * we evidently overflowed + */ + if (addr >= (u64)current->stack - PAGE_SIZE && + addr < (u64)current->stack) { + printk(KERN_EMERG "BUG: stack guard page was hit at %p (stack is %p..%p)\n", + (void *)addr, current->stack, + (char *)current->stack + THREAD_SIZE - 1); + die("Oops", regs, esr); + + /* Be absolutely certain we don't return. */ + panic("Kernel stack overflow"); + } + + /* * No handler, we'll have to terminate things with extreme prejudice. */ bust_spinlocks(1);