From patchwork Wed Apr 24 17:07:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 162809 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp966469jan; Wed, 24 Apr 2019 11:08:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqzTP/KKbRqNW/MnvbPWnHrW1e8f1WGS60fB/XqpC9FsvnPQ1FM79V2baNjGkl3W6EzZiavt X-Received: by 2002:a17:902:b10c:: with SMTP id q12mr34654229plr.254.1556129293109; Wed, 24 Apr 2019 11:08:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556129293; cv=none; d=google.com; s=arc-20160816; b=MhS8hlLhb1ep7UipO3urtPW652MJCFG3Lo1wSo5bIGMfmUBakK3diTs1wROSVT3xEp VotJX9438kykCZQDfjHKP/GX5a8b3HP/Gh7gXiJ+kc4nJ5msQDAZCai3wvt3feAm5n4X 7jQlPLLys9hAdpph9bNFV8ff9/fbESAQApZXrbpG5Gpj3j1jGB/Tp1MspCYRkzer5p1K 0+6RXKXaQbtUztCDKowXQBb7kW12KvaHBapPjSgYQjsZMpyORh/5RT04t2FsHMJp1bvb 7bSfLL8FQqidK0Pko1GoTA2EoxLbtadUSVqxSL8HA/qMvhbRiQg5NgTOAIdekwa2BLPe DYkQ== 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=WOwcyA3IFlDiKWczpY/ry687WnCIJ+Umt0HtKWqN7/c=; b=TKegtYPSeWQR7if+ufBfzMviIa95jDWloP41SNx7msEod9uWRx5KIx5eR/r4hpxKB7 fAUqIeiQjwd0T7wjaEFF8Z9X23qSKQYthO+MBxIRp24Z3+cjmVq+lo+3KgbkuoqJhfOm Pcj8uYC0BCGEOejRiaPNZn2Zox+Rs5wNBkcHpaHE4XJ4tXX1ew8/aPfIDQzexFpCtcNO h0aD7I6Qk/6oPY06W2EJltp3sBsDIzSA4vdm0VtrUxhpCynnQSaL+MF/rHrwEZ0LsMls G6YU7loUiif33Cr6CugCrNbUfebT9L2YI7of9ZJRvd4MYKMuOGVjt36y5o0SzpUYGLQt cmEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=L8ZWsX6T; 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 j91si19688701pld.199.2019.04.24.11.08.12; Wed, 24 Apr 2019 11:08:13 -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=L8ZWsX6T; 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 S2388966AbfDXSIL (ORCPT + 30 others); Wed, 24 Apr 2019 14:08:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:40922 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387605AbfDXRQW (ORCPT ); Wed, 24 Apr 2019 13:16:22 -0400 Received: from localhost (62-193-50-229.as16211.net [62.193.50.229]) (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 6A606218B0; Wed, 24 Apr 2019 17:16:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556126181; bh=LnsFNpBJfXYxyAUMjNXpdCuzjQApJdVUskscUBhvFzM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L8ZWsX6Ti6ymQXzKQtbs9PKXtjUttEQyYe53vmqElhyTB57a0gAbK0YWx315eKR4w gEvw0OtzDkX3e+XSgHZAjNSr+GSUaXuz8/vhCJl+Gkom4ATotGfLPKM5WMyKb+hUiB BmNWzyRPik8ZoRlubjW73P3VGtPB/hInXcNUE4oA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mark Rutland , Will Deacon , Catalin Marinas Subject: [PATCH 4.4 002/168] arm64: debug: Ensure debug handlers check triggering exception level Date: Wed, 24 Apr 2019 19:07:26 +0200 Message-Id: <20190424170923.593936482@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190424170923.452349382@linuxfoundation.org> References: <20190424170923.452349382@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Will Deacon commit 6bd288569b50bc89fa5513031086746968f585cb upstream. Debug exception handlers may be called for exceptions generated both by user and kernel code. In many cases, this is checked explicitly, but in other cases things either happen to work by happy accident or they go slightly wrong. For example, executing 'brk #4' from userspace will enter the kprobes code and be ignored, but the instruction will be retried forever in userspace instead of delivering a SIGTRAP. Fix this issue in the most stable-friendly fashion by simply adding explicit checks of the triggering exception level to all of our debug exception handlers. Cc: Reviewed-by: Mark Rutland Signed-off-by: Will Deacon Signed-off-by: Catalin Marinas Signed-off-by: Greg Kroah-Hartman --- arch/arm64/kernel/kgdb.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) --- a/arch/arm64/kernel/kgdb.c +++ b/arch/arm64/kernel/kgdb.c @@ -215,22 +215,31 @@ int kgdb_arch_handle_exception(int excep static int kgdb_brk_fn(struct pt_regs *regs, unsigned int esr) { + if (user_mode(regs)) + return DBG_HOOK_ERROR; + kgdb_handle_exception(1, SIGTRAP, 0, regs); - return 0; + return DBG_HOOK_HANDLED; } static int kgdb_compiled_brk_fn(struct pt_regs *regs, unsigned int esr) { + if (user_mode(regs)) + return DBG_HOOK_ERROR; + compiled_break = 1; kgdb_handle_exception(1, SIGTRAP, 0, regs); - return 0; + return DBG_HOOK_HANDLED; } static int kgdb_step_brk_fn(struct pt_regs *regs, unsigned int esr) { + if (user_mode(regs)) + return DBG_HOOK_ERROR; + kgdb_handle_exception(1, SIGTRAP, 0, regs); - return 0; + return DBG_HOOK_HANDLED; } static struct break_hook kgdb_brkpt_hook = {