Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1669037yba; Thu, 25 Apr 2019 03:51:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqwNsERVJaYTkk0zBS7NThqlpTNuEzyAyV+uf6ClsORJWtKmRgFxSnRv6Uurx0YPWMzz/zf3 X-Received: by 2002:a17:902:8bca:: with SMTP id r10mr38797364plo.67.1556189507064; Thu, 25 Apr 2019 03:51:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556189507; cv=none; d=google.com; s=arc-20160816; b=yMdv3nfbXcKqQbkO8U8FVHPsr6rVPg2icG5xv/JoSL9ULL1BGmYwG8487+fY9RA1LF IO9oe//a3HdDUErCDe4zcXzql8wMLkrmGRMUvWZsK5daB2qlhN6+j6eog9KTk+P9/vYG CIIHrV1hN6rtPsfchUq8UBfcjKfXD/mrI1/UdrwXRb6ylXHrUbdDOer0xlpa/sq8f0Gs J5yyV2Ec2sniNMMNX1Y22SyysQk5Z2fCt92F6ATMab7Q49+jCOGzDfB3A1SofrCanIOl P+RcGjQ3cXWdnx2rapiXHwn5alabgvmfuSj62fWR9YkwesuLf855sNeYG+05MX3Kq1JD ZQhw== 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 m6si4945758pll.96.2019.04.25.03.51.31; Thu, 25 Apr 2019 03:51:47 -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 S2388956AbfDXSIK (ORCPT + 99 others); Wed, 24 Apr 2019 14:08:10 -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 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 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 = {