Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1194940pxa; Thu, 20 Aug 2020 05:19:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjVz3nkD+vYRuJxHxZae2jQSv6II8rJAhmAmPUFYvgN427UVWjqBa8KgO/c9CEw0Y/pL6Y X-Received: by 2002:a17:906:a1cf:: with SMTP id bx15mr2793276ejb.231.1597925957189; Thu, 20 Aug 2020 05:19:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597925957; cv=none; d=google.com; s=arc-20160816; b=jbQ6A4CnhArw0d1hoin442br7bLuQtK/QZrMgCspUa9VULrsqhFwOnm+i/IZOhzDSf R2J1exEbqR46SC+wd5t4DoLBDRwn5naKzuhQUJyHgbtkxpErshUmiIOxnv5a9iQcUVPT z/O5+M3ULWDmr8tY77zsFQvw9MaecoYFYHx1MYwEWxTkgkq1z6GUg8Rh0bcnDcY1OhVf s6mmOGiRfHyDO3OSZok8cLZ0picKX3vof5j0Ppf5xWeoIXCrS53Xx/4WDMJxTYszQK+5 O22FE0tipZ3Bcg+P7C/PWTA94w7uaT1zD2Uc705VMGzChJwBllsIeCjkvoOASxp8Mryd bATg== 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=vQeT9b8i+1pp63otzQPpj6RmsW8oJiBgMLtVVl6mswo=; b=nzdpEYwmcZPTl0UgCXeUZUtHJWjJzTUG7jNq0UC+SksubBzOepYkxMfjOiGJ3/LFls R2cWkSE4RNPCMUwhdETcKj1aUi+fFLIjm0Bfb2bhklu6g28U9ErQVi1Mil9UcyTi5XVc lBzidy9WbeM/8gSoTEwlIu8+3NVKtCOJprDbeIEqbLqetIe/yUb2rjH7+8DUy+YEYT9H dYjNcAufuoZ21i7z2GIfa7A2p0+GMMKO7ypC4VNs4JYulHishNRyrk/m4Tf67IP4asi4 WZz5ZWHIbsxyL1Sy2jxCdj0LyyuXAMe5zL9VhbteGMy5+Q9bjHASSvhCq/P1tQ3Ghg8k aLBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xz4drtEc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ch2si1348471edb.244.2020.08.20.05.18.53; Thu, 20 Aug 2020 05:19:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xz4drtEc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729889AbgHTJ43 (ORCPT + 99 others); Thu, 20 Aug 2020 05:56:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:39678 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730252AbgHTJ4R (ORCPT ); Thu, 20 Aug 2020 05:56:17 -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 CA69B20855; Thu, 20 Aug 2020 09:56:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597917375; bh=O2RC+e43R6W2CMNZ/EhI3/kEAnaUQ/baPfNH/UmDZLw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xz4drtEcMfYwKchdz4gA0zTBpq6RrZK9PKGIHi9LAkNNSqy2PTFiLzin84H/w+98g frwZqdnTIz3Z3pL/RrMebtRnJlw2h+fr6uUy8/CA1zcC7PQuYV313yYfLfEQ/Mgr9s 9j3etatKf7JG6ivBBop06HnN/5eoP7aARQCNXyW8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Luis Machado , Will Deacon , Russell King Subject: [PATCH 4.9 010/212] ARM: 8986/1: hw_breakpoint: Dont invoke overflow handler on uaccess watchpoints Date: Thu, 20 Aug 2020 11:19:43 +0200 Message-Id: <20200820091602.847078012@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091602.251285210@linuxfoundation.org> References: <20200820091602.251285210@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 eec13b42d41b0f3339dcf0c4da43734427c68620 upstream. Unprivileged memory accesses generated by the so-called "translated" instructions (e.g. LDRT) in kernel mode can cause user watchpoints to fire unexpectedly. In such cases, the hw_breakpoint logic will invoke the user overflow handler which will typically raise a SIGTRAP back to the current task. This is futile when returning back to the kernel because (a) the signal won't have been delivered and (b) userspace can't handle the thing anyway. Avoid invoking the user overflow handler for watchpoints triggered by kernel uaccess routines, and instead single-step over the faulting instruction as we would if no overflow handler had been installed. Cc: Fixes: f81ef4a920c8 ("ARM: 6356/1: hw-breakpoint: add ARM backend for the hw-breakpoint framework") Reported-by: Luis Machado Tested-by: Luis Machado Signed-off-by: Will Deacon Signed-off-by: Russell King Signed-off-by: Greg Kroah-Hartman --- arch/arm/kernel/hw_breakpoint.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) --- a/arch/arm/kernel/hw_breakpoint.c +++ b/arch/arm/kernel/hw_breakpoint.c @@ -688,6 +688,12 @@ static void disable_single_step(struct p arch_install_hw_breakpoint(bp); } +static int watchpoint_fault_on_uaccess(struct pt_regs *regs, + struct arch_hw_breakpoint *info) +{ + return !user_mode(regs) && info->ctrl.privilege == ARM_BREAKPOINT_USER; +} + static void watchpoint_handler(unsigned long addr, unsigned int fsr, struct pt_regs *regs) { @@ -747,16 +753,27 @@ static void watchpoint_handler(unsigned } pr_debug("watchpoint fired: address = 0x%x\n", info->trigger); + + /* + * If we triggered a user watchpoint from a uaccess routine, + * then handle the stepping ourselves since userspace really + * can't help us with this. + */ + if (watchpoint_fault_on_uaccess(regs, info)) + goto step; + perf_bp_event(wp, regs); /* - * If no overflow handler is present, insert a temporary - * mismatch breakpoint so we can single-step over the - * watchpoint trigger. + * Defer stepping to the overflow handler if one is installed. + * Otherwise, insert a temporary mismatch breakpoint so that + * we can single-step over the watchpoint trigger. */ - if (is_default_overflow_handler(wp)) - enable_single_step(wp, instruction_pointer(regs)); + if (!is_default_overflow_handler(wp)) + goto unlock; +step: + enable_single_step(wp, instruction_pointer(regs)); unlock: rcu_read_unlock(); }