From patchwork Wed Mar 22 14:50:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Martin X-Patchwork-Id: 9639099 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 C3511601E9 for ; Wed, 22 Mar 2017 14:53:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B495C27FA8 for ; Wed, 22 Mar 2017 14:53:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A97CC28475; Wed, 22 Mar 2017 14:53:17 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.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 2733C27FA8 for ; Wed, 22 Mar 2017 14:53:17 +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=crSJj97OyP5+z2ne5C0W4agNfW/1CbO4kQDf4rjGl+A=; b=GCRfm8dAioCtBHyCNm4Ee507WI A4I6J9CgXAfbBU88wIBnmgSYFN5tJKzhPatOVrogEd75W3UyGbJZNetxDjZK1VNbXi0xTHM1J1VMW 1s7I3rVnsnS8lEuqXeeKGjB5QYoqwzHgkhiHcHIGP3cSqfvov9vCbj+TpBMg4c9zOHy+7OGcdFMic 8yoInAlv5AkqUL5yV4Dvu3Ad0HGf4pP0DCYhRs66CreOnvc89fAw0wb7t0TQyemNwjyj3X98Ylq+L RBNe6B0GoDpy+KNy5uVgsEgiU1b+PkdwYtBpzHoA9bWWOF+Icf7xAxGwMFM+yMXo304F2xCQ5NXFr dJz6Wi9A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cqhdM-00005L-Nu; Wed, 22 Mar 2017 14:53:08 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cqhcN-00076y-45 for linux-arm-kernel@lists.infradead.org; Wed, 22 Mar 2017 14:52:10 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DC0B51477; Wed, 22 Mar 2017 07:51:49 -0700 (PDT) Received: from e103592.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 7BDEC3F575; Wed, 22 Mar 2017 07:51:48 -0700 (PDT) From: Dave Martin To: linux-arm-kernel@lists.infradead.org Subject: [RFC PATCH v2 05/41] arm64: signal: Parse extra_context during sigreturn Date: Wed, 22 Mar 2017 14:50:35 +0000 Message-Id: <1490194274-30569-6-git-send-email-Dave.Martin@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1490194274-30569-1-git-send-email-Dave.Martin@arm.com> References: <1490194274-30569-1-git-send-email-Dave.Martin@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170322_075207_652290_575BED66 X-CRM114-Status: GOOD ( 12.18 ) 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: Florian Weimer , Ard Biesheuvel , Marc Zyngier , Catalin Marinas , Will Deacon , Szabolcs Nagy , Joseph Myers 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 If extra_context is present, parse it. To avoid abuse by userspace, this patch attempts to ensure that: * that no more than one extra_context is accepted; * that the extra_context is a sensible size; * that the extra context data is properly aligned. This patch relies on the user accessors in order to ensure that the user-supplied extra context data pointer is an honest userspace address. Other than that, the kernel doesn't care specially whether the pointer supplied is sensible (e.g., not garbage, doesn't overlap sigcontext.__reserved[], etc.) since this cannot harm the kernel. More checks may be added later in order to aid debugging of botched sigreturns from userspace. Signed-off-by: Dave Martin --- arch/arm64/kernel/signal.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c index 223bd52..49c30df 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -221,6 +221,7 @@ static int parse_user_sigframe(struct user_ctxs *user, char __user *base = (char __user *)&sc->__reserved; size_t offset = 0; size_t limit = sizeof(sc->__reserved); + bool have_extra_context = false; user->fpsimd = NULL; @@ -230,6 +231,9 @@ static int parse_user_sigframe(struct user_ctxs *user, while (1) { int err = 0; u32 magic, size; + struct extra_context const __user *extra; + void __user *extra_data; + u32 extra_size; if (limit - offset < sizeof(*head)) goto invalid; @@ -267,6 +271,42 @@ static int parse_user_sigframe(struct user_ctxs *user, /* ignore */ break; + case EXTRA_MAGIC: + if (have_extra_context) + goto invalid; + + if (size < sizeof(*extra)) + goto invalid; + + extra = (struct extra_context const __user *)head; + __get_user_error(extra_data, &extra->data, err); + __get_user_error(extra_size, &extra->size, err); + if (err) + return err; + + /* Prevent looping/repeated parsing of extra_conext */ + have_extra_context = true; + + /* + * Rely on the __user accessors to reject bogus + * pointers. + */ + base = extra_data; + if (!IS_ALIGNED((unsigned long)base, 16)) + goto invalid; + + /* Reject "unreasonably large" frames: */ + limit = extra_size; + if (limit > SIGFRAME_MAXSZ - sizeof(sc->__reserved)) + goto invalid; + + /* + * Ignore trailing terminator in __reserved[] + * and start parsing extra_data: + */ + offset = 0; + continue; + default: goto invalid; }