Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3803869ybi; Mon, 29 Jul 2019 12:58:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqznyd5jQjPMbxe0Jn4B7zo1akZa7Epa3x82bl8bMLwdHnGUkj/zLj63aeydNEcWDNd9FvW4 X-Received: by 2002:a17:902:145:: with SMTP id 63mr115083957plb.55.1564430284639; Mon, 29 Jul 2019 12:58:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564430284; cv=none; d=google.com; s=arc-20160816; b=m38+uTHDiV/vco1PLOdgsyiVQL3O+E6Q/fWyrYw+EnnfbIB4XfTjp7GGJF7Zm51X8J 7WOwQ5l2nR+LOKd0LrZcvwqxD9uc9PoFj6SA3+WH2VHsyen/tBhPOl43jSBo0ZOfWhjG e0jtU8TcIs96qeXzOomF76XBkMMikVNcF/L3Ng89miZDx0z4ImF8SJ3cRxZHhuhljY4Z o5fP8hbNM6hmyJssjXV8LDzj/ty+ALZdi2cCAnGWT8jJlpgSo0Ig0Ushj+Rk1JCSYfTs ObFM8pns1ait7cAUxf2HOFDf2LfAtURqvMCH2BVmzwWd8nP8algbv/EoCakKpqYryEp7 hOYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VpkSlq2bpRrnX740WlvmOypzp+C2NmKriWC3QasDx8E=; b=GDDuqEuthK7HuXsrkAd/LdbDOdMiYZIe3A7s5FciR7BtMTs/Y1WXz6nWOOzYO1vbnp e6cqLUSXJ9mjT7kQ7GlVkRuHIQmKEReDysfFw5LnhEX/H2zWqrpQCSSHBOL3ZCEFDhjK vDSdEBAWdqo8/1ym57WfXNbf6ahp0VNpbqvSbX0THw5M3AONxFt1NT84GddlENSozECU PV17/9GlLQ8l0Id0HybrvIBc1DUgUpVtv13XkMqDIrsY9Hpvv9PhnjYX1Q9/m7onoCvX QijXD0+fJzg1+9gp+FSIgM9XGxePGve0LnRaNkHRjayMtWW02IFbjPQ0CeYRMPrxrB72 XKfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="2H/iHirP"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i97si32152523plb.50.2019.07.29.12.57.49; Mon, 29 Jul 2019 12:58:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="2H/iHirP"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404216AbfG2Tz2 (ORCPT + 99 others); Mon, 29 Jul 2019 15:55:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:48222 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403997AbfG2TzZ (ORCPT ); Mon, 29 Jul 2019 15:55:25 -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 564F721655; Mon, 29 Jul 2019 19:55:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564430124; bh=lRxTkn5ni5yFAnlGU5me0IUymEJm74FXaiFGQ5FWTWQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2H/iHirPzYkcIkDFhI449nYPgbyF9Iv9AbF6q31OOnO2IdD7Co9fAFHNKBGh4hx1d dXr+xS7zSbcrtjcC84jdnImlnkeKhjK6sMu4SzVDicoVE/HFYhH3i3F+P5e80EeAb5 pay/+r+645PFPQFQZXj6A51R6T0h2g/Y85vUS+gI= 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 5.2 154/215] mm/gup.c: remove some BUG_ONs from get_gate_page() Date: Mon, 29 Jul 2019 21:22:30 +0200 Message-Id: <20190729190806.462204986@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190739.971253303@linuxfoundation.org> References: <20190729190739.971253303@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 22855ff0b448..d2c14fc4b5d4 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -585,11 +585,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