Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2829305pxb; Mon, 19 Apr 2021 15:21:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzU5xKqgbPVSLI3luExgNEbaIrRHi8MKSaSGhchr+kQG09BnNJVEF35qKZgHlcVJCTdtZ6T X-Received: by 2002:a63:f317:: with SMTP id l23mr13544156pgh.173.1618870875355; Mon, 19 Apr 2021 15:21:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618870875; cv=none; d=google.com; s=arc-20160816; b=dNpn5GZOhL07KLGpc/kFBpzYU0PayXLa1radJzZk6WBVi8UKxa34ZzzDH7LNeRnNuv 4XoNxWQ/+elyhGry+NYruotG+nMTgIUPRXbKX66G8fFf8m4eTK0BYc3btupCBdKrCq0o QbB/bwxvUkz0Sx3SpwlJ+tv7ZkkB7EIip6scurOfYLD6+c3S02QiUQQ3phsLeLUUinaT 27NL/+WTzQp5ny4MVt05wnGLuYC+aLBQ6Ce2mixx3+N4nb0/8Mzuv/v1/GSKqw8W3jg5 JMmY3GGl7qCzBZi3dk8KDafRAdDjmqOPS7Vtd2w8hZapP6R4DI0T7mDJ4X3YSafth0En s1Jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=l/ok6UaHBFVrcdQiW+maIK7Fx8e6fcT+lbEf9VHn4ww=; b=q4JXTbN+Odx2tzjb6UDl7kiXCzRYerwQ6v3OgEN27fUo2vHCzUJ2GB9plitcMWiLkQ 3oZCJ8SSQeUKLIfdP//gBual8MypQQCxA/euDE8r60qH9R3spehBEVPJ8S5WYB/ulE4m u534RhYrMus0n1boe9fwiv9tCigepGDF+hQvbmowzLCtChaWurNDGp3VKc6v7Qk1+8S/ d6rTUNdgQ1z8EoR9Cscm7SYmvmju5rVyabpzA2OuyRce9Lu8P0PRwvNFF0eF0ESwYMKe OxaXWl6bwB4zk5pUgGhkBWdrCKjerGF8EWTsXJGoPLOdzJgjYeN/swAUTQqPy1a7AEX/ BBMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WkJzcDtL; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t23si17078413pgk.263.2021.04.19.15.21.03; Mon, 19 Apr 2021 15:21:15 -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=k20201202 header.b=WkJzcDtL; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242693AbhDSUpQ (ORCPT + 99 others); Mon, 19 Apr 2021 16:45:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:54164 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242407AbhDSUoe (ORCPT ); Mon, 19 Apr 2021 16:44:34 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4F6C8613B0; Mon, 19 Apr 2021 20:44:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618865044; bh=nAmp5UIFdq9tgAD5cLuft77KrM6yGyF0GIa2ORZdBR0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WkJzcDtLRxIiUmY9hnVWEo+0Ymu1f0trLmbVbn62ZoSQ7CJjM9yKCrP+DlvOnVOsv CchRoJeW2ZsbJ02mstiAJC9E6/HTOEnFp0Ny/O2uXiMrwwHpI0U40EM61czb4xXrkf Yg5xvBHV92s1LBtMJ2luQLP14G9SPQWmRZDpCsO4V6onU5P5movtlSmYo1Lo5b4rKy WeMTJX2BbkVHIIzrnjD78FD6FJEz/DydRTwCRSE+rvM64aiunI5+RBLmw09V1eeBUO HQ8ql2W9MV5EWLAI69+T59W9uJlZhCOfYdj/MXG/Jvy76huHQuvC6f03VZlGAwto9X QDUlbGKqMzZKw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jisheng Zhang , Masami Hiramatsu , Will Deacon , Sasha Levin , linux-arm-kernel@lists.infradead.org, linux-riscv@lists.infradead.org Subject: [PATCH AUTOSEL 5.11 14/23] arm64: kprobes: Restore local irqflag if kprobes is cancelled Date: Mon, 19 Apr 2021 16:43:33 -0400 Message-Id: <20210419204343.6134-14-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210419204343.6134-1-sashal@kernel.org> References: <20210419204343.6134-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jisheng Zhang [ Upstream commit 738fa58ee1328481d1d7889e7c430b3401c571b9 ] If instruction being single stepped caused a page fault, the kprobes is cancelled to let the page fault handler continue as a normal page fault. But the local irqflags are disabled so cpu will restore pstate with DAIF masked. After pagefault is serviced, the kprobes is triggerred again, we overwrite the saved_irqflag by calling kprobes_save_local_irqflag(). NOTE, DAIF is masked in this new saved irqflag. After kprobes is serviced, the cpu pstate is retored with DAIF masked. This patch is inspired by one patch for riscv from Liao Chang. Signed-off-by: Jisheng Zhang Acked-by: Masami Hiramatsu Link: https://lore.kernel.org/r/20210412174101.6bfb0594@xhacker.debian Signed-off-by: Will Deacon Signed-off-by: Sasha Levin --- arch/arm64/kernel/probes/kprobes.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c index 66aac2881ba8..85645b2b0c7a 100644 --- a/arch/arm64/kernel/probes/kprobes.c +++ b/arch/arm64/kernel/probes/kprobes.c @@ -267,10 +267,12 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, unsigned int fsr) if (!instruction_pointer(regs)) BUG(); - if (kcb->kprobe_status == KPROBE_REENTER) + if (kcb->kprobe_status == KPROBE_REENTER) { restore_previous_kprobe(kcb); - else + } else { + kprobes_restore_local_irqflag(kcb, regs); reset_current_kprobe(); + } break; case KPROBE_HIT_ACTIVE: -- 2.30.2