From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8C4BC76186 for ; Mon, 29 Jul 2019 20:05:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 728AE2064C for ; Mon, 29 Jul 2019 20:05:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564430727; bh=yoXFw4w5Ok6I0XoUXDoUqkCp6bzkdn6jThrMB3TdmIo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Jldh3Xhy0w1AgSu6zNiG8x+BdWn+oJn/YmgdH2Plm/5samWiZtJOJt8kAeyK5hz9s IOw6RhRgySVnz7d6hyc/ju+vZ4m+7/ybDRkXyckt2AnzK3sYmBkz5HPCbViKeqssE6 r35l0Vg17LLyJuT6MLA7KVsSbqg0WYCIWpf6SoLM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389321AbfG2TnV (ORCPT ); Mon, 29 Jul 2019 15:43:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:59542 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729489AbfG2TnU (ORCPT ); Mon, 29 Jul 2019 15:43:20 -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 08B142054F; Mon, 29 Jul 2019 19:43:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564429399; bh=yoXFw4w5Ok6I0XoUXDoUqkCp6bzkdn6jThrMB3TdmIo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Arf1nEc9OpFTIUC4XPH5O8AVbP8c1nfEIIZH8PSa+N2glPl7DG7TfYHRjTAB10Vs7 W+12o242Y6oGe/gO34o9EYQNK/W+4yyIqZRq7xD1Z9/9NC8lA1dkGRThZc1upK7Cpp isBM16iUZi2s/K9hGE7lANTVkzSXAGnY44Mjp+0o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andy Lutomirski , Kees Cook , Andrew Morton , Florian Weimer , Jann Horn , Linus Torvalds , Sasha Levin Subject: [PATCH 4.19 086/113] mm/gup.c: remove some BUG_ONs from get_gate_page() Date: Mon, 29 Jul 2019 21:22:53 +0200 Message-Id: <20190729190716.083411142@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190655.455345569@linuxfoundation.org> References: <20190729190655.455345569@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org [ Upstream commit b5d1c39f34d1c9bca0c4b9ae2e339fbbe264a9c7 ] If we end up without a PGD or PUD entry backing the gate area, don't BUG -- just fail gracefully. It's not entirely implausible that this could happen some day on x86. It doesn't right now even with an execute-only emulated vsyscall page because the fixmap shares the PUD, but the core mm code shouldn't rely on that particular detail to avoid OOPSing. Link: http://lkml.kernel.org/r/a1d9f4efb75b9d464e59fd6af00104b21c58f6f7.1561610798.git.luto@kernel.org Signed-off-by: Andy Lutomirski Reviewed-by: Kees Cook Reviewed-by: Andrew Morton Cc: Florian Weimer Cc: Jann Horn Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/gup.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 43c71397c7ca..f3088d25bd92 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -458,11 +458,14 @@ static int get_gate_page(struct mm_struct *mm, unsigned long address, pgd = pgd_offset_k(address); else pgd = pgd_offset_gate(mm, address); - BUG_ON(pgd_none(*pgd)); + if (pgd_none(*pgd)) + return -EFAULT; p4d = p4d_offset(pgd, address); - BUG_ON(p4d_none(*p4d)); + if (p4d_none(*p4d)) + return -EFAULT; pud = pud_offset(p4d, address); - BUG_ON(pud_none(*pud)); + if (pud_none(*pud)) + return -EFAULT; pmd = pmd_offset(pud, address); if (!pmd_present(*pmd)) return -EFAULT; -- 2.20.1