Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2877513rwb; Mon, 15 Aug 2022 13:08:26 -0700 (PDT) X-Google-Smtp-Source: AA6agR4oe+gLYnJxXgLkOulVLOtr8KWEIue3APcFwtEne8ysyXl61gGLS9ZKFRFBa9dWVL7H0/BY X-Received: by 2002:a17:907:272a:b0:731:4699:b375 with SMTP id d10-20020a170907272a00b007314699b375mr11411236ejl.633.1660594105980; Mon, 15 Aug 2022 13:08:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660594105; cv=none; d=google.com; s=arc-20160816; b=AB8RSBJxN8NU8DuzR2sCHXr4yrN9f9cSAoDm/MCpcN5YFc/UmioPNrWqT+3EqebnoY yexxAMvqjWFT2NfIa0BBbP+RWJZkTStfkCwBEBNKZImjlh6Hrwjj26fHxfxo6dNvwrHb AwTEDmttHWLB88uNEtDutVH4m5drVkabrvq4ghymia52KbwlkiIiOIKFhB+49KYiO3Zf lBQaxIZ1ESrBiSz9wXMSvCzbfZ+q4ps9Y0XpAzkf0+olWLJHpYx2hOmfjKaqIf+Dizv7 fbvlx3jvK7x4baNfBBRIzsvUR1Q+w0brYFGIEFqsUTbHanHhe6c4jkHeQw1Iuo1l5MbG Hfsw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=pVP2XG2azmuZIgEcaFAqVjv/xCwSM9sIFgB+yD/OEJA=; b=N0rgVwa4+mvb910I5MIiPg6zZ1AY3b13I4AxQyrgZ5G3i+AMpOQ2BQAj58I9PHj66B l2wO7lLaEJibNtSCP+iDw/7xc3GnWardkEUcJ4oYQ4l4xn1OFqYvnkXplOmVZobdmKxL fwX7o5UC656ga/vtsyecF3URL/fvMtfQ5vNmU9cNnKakywzm6WzG4SubVXW9PjwVzGoZ e+wXbkTQMLZzyMqHCLU6LdNBE/E3LJdE+mx95kP0ko5OYSe/VoqDpE11WdNpHKymMX4W Jklfs4D7adMiCKiwXaEeRVUWyEZax1/Y0FpAJaxhDJmbAM20qWeVr8qpjeIa8b0rtW41 cFpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="MwkJ/Mjs"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nb39-20020a1709071ca700b0072b0f6f1456si8286328ejc.612.2022.08.15.13.07.59; Mon, 15 Aug 2022 13:08:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="MwkJ/Mjs"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344824AbiHOTre (ORCPT + 99 others); Mon, 15 Aug 2022 15:47:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345039AbiHOTqC (ORCPT ); Mon, 15 Aug 2022 15:46:02 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF3116D9E0; Mon, 15 Aug 2022 11:48:49 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E1134611CA; Mon, 15 Aug 2022 18:48:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD66EC433D6; Mon, 15 Aug 2022 18:48:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660589327; bh=k0u/vGeggDbZwt1WBxF9FGs6XocuAMYXyNIzJIgT5zg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MwkJ/MjsuIQXQQMoNXPBeYW5Gy/V/2cPWsyzAKTuqbqTVERVAs9H8qlFsBns19vVP VmbjDtgmFTHc5/gCij2oTNcXtrgvi0XCfoZrhmfL11hmPzuGIw0jPLyVYnIRN/6L2P RXFlsDcJCGrkYrt3VujVS9rvsygtvGkaM7iQoZmo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Daniel=20M=C3=BCller?= , "Masami Hiramatsu (Google)" , Ingo Molnar Subject: [PATCH 5.15 683/779] x86/kprobes: Update kcb status flag after singlestepping Date: Mon, 15 Aug 2022 20:05:27 +0200 Message-Id: <20220815180406.548277051@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180337.130757997@linuxfoundation.org> References: <20220815180337.130757997@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Masami Hiramatsu (Google) commit dec8784c9088b131a1523f582c2194cfc8107dc0 upstream. Fix kprobes to update kcb (kprobes control block) status flag to KPROBE_HIT_SSDONE even if the kp->post_handler is not set. This bug may cause a kernel panic if another INT3 user runs right after kprobes because kprobe_int3_handler() misunderstands the INT3 is kprobe's single stepping INT3. Fixes: 6256e668b7af ("x86/kprobes: Use int3 instead of debug trap for single-step") Reported-by: Daniel Müller Signed-off-by: Masami Hiramatsu (Google) Signed-off-by: Ingo Molnar Tested-by: Daniel Müller Cc: stable@vger.kernel.org Link: https://lore.kernel.org/all/20220727210136.jjgc3lpqeq42yr3m@muellerd-fedora-PC2BDTX9 Link: https://lore.kernel.org/r/165942025658.342061.12452378391879093249.stgit@devnote2 Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/kprobes/core.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) --- a/arch/x86/kernel/kprobes/core.c +++ b/arch/x86/kernel/kprobes/core.c @@ -816,16 +816,20 @@ NOKPROBE_SYMBOL(arch_prepare_kretprobe); static void kprobe_post_process(struct kprobe *cur, struct pt_regs *regs, struct kprobe_ctlblk *kcb) { - if ((kcb->kprobe_status != KPROBE_REENTER) && cur->post_handler) { - kcb->kprobe_status = KPROBE_HIT_SSDONE; - cur->post_handler(cur, regs, 0); - } - /* Restore back the original saved kprobes variables and continue. */ - if (kcb->kprobe_status == KPROBE_REENTER) + if (kcb->kprobe_status == KPROBE_REENTER) { + /* This will restore both kcb and current_kprobe */ restore_previous_kprobe(kcb); - else + } else { + /* + * Always update the kcb status because + * reset_curent_kprobe() doesn't update kcb. + */ + kcb->kprobe_status = KPROBE_HIT_SSDONE; + if (cur->post_handler) + cur->post_handler(cur, regs, 0); reset_current_kprobe(); + } } NOKPROBE_SYMBOL(kprobe_post_process);