Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3097815rwb; Mon, 15 Aug 2022 18:03:34 -0700 (PDT) X-Google-Smtp-Source: AA6agR6JJVFwtS5KokOaRxzu9MtUpW7fvg+3r6dXZAArH2y9d7PfZzSF7WobIp0Ry8PQRAblu0ha X-Received: by 2002:a17:907:8a09:b0:731:610:ff8d with SMTP id sc9-20020a1709078a0900b007310610ff8dmr11869909ejc.399.1660611814446; Mon, 15 Aug 2022 18:03:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660611814; cv=none; d=google.com; s=arc-20160816; b=t2kSpMH44DPpZHOYSFb9+xMvsrEaJpk9dyNutwpAFsEnbH7q5UwqD/ddTda/9JMYkW dfcitCzxIQKuF4xp7lahV2FxSBezkLm5z94JozqXGmMMn24iGfwWBLwfLDiIwycfbXNg HPyYqtoXueOWffdJGYykCmD/j48Mq4ojpAHty9rOSXwr6A1sC4+KgTov2l/tYHM+LV7N RhfMffmLqCHkLpQAFzB/jBqCWrxIP5bonauaWmBqbCJ6tKbvggLBxWXWLxFUQTFrDucz hDW3Jl5pCinu4wg0OlfzrpjYASu5bOPU3wmbhuCJsX+zBRRiwHP6mgjpNUi56XbMegpk eqpQ== 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=03q68DAs/DOa71EQt3y9BCSNG5ecKNhKSguNh4a5380=; b=tc72WCTF6WmkLsQVSEyHC1j+YhN9vgHEcQ200v2Ye+4hov6o2zJzFFCHfM3riNTEle yf1IWWbsr4SWjfpQp99mZq6UIz2fgLjk18rbImI4UkpzTmdC0WIoKkShqW372p4BT4AD /dnt/JUDFalR5k/YqfVcKcuVbfgYd+J/3ed/Brx60uD6Q9AIPLF5hXcqYaugTVu0FC9F Hu+DbBJxol+X3B6eQ1BdUzQ5GRdDExyJhq6G4p1200bQj1JU524GIpGSVMMQaXfPISXm 4hSkACs/P2B8EQpF3QobL3U7k55uctJE4sUtuaswUkKk8l8JZE4F91e+wI06mRHZk78v x4/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YCd+No0s; 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 hp36-20020a1709073e2400b0072b01ae9c69si8703828ejc.694.2022.08.15.18.03.07; Mon, 15 Aug 2022 18:03:34 -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=YCd+No0s; 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 S244023AbiHPA7s (ORCPT + 99 others); Mon, 15 Aug 2022 20:59:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348421AbiHPAwG (ORCPT ); Mon, 15 Aug 2022 20:52:06 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDF3C19B727; Mon, 15 Aug 2022 13:47:29 -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 ams.source.kernel.org (Postfix) with ESMTPS id 6E865B8113E; Mon, 15 Aug 2022 20:47:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B5009C433C1; Mon, 15 Aug 2022 20:47:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660596446; bh=ufwO8vqLDDu71bVtWRi8o3m8JUyw8NsgBLtUn+/druI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YCd+No0s3Md66P00O6xes+079qzFuRs0dg68l3tqJRkK9iveuWLM6uJDfJ1Z4sFAd XZPLnLkxKk7rq7/AIQj7Y+IvO0Z/hEg4ATILnAGg69OTtfRUEsqr9wj/yEo2BHhAQI BlPm7DDsHTFSPkp07+FcjGVQBR56afl0pEC3szXo= 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.19 1048/1157] x86/kprobes: Update kcb status flag after singlestepping Date: Mon, 15 Aug 2022 20:06:44 +0200 Message-Id: <20220815180521.971463783@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@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 @@ -814,16 +814,20 @@ set_current_kprobe(struct kprobe *p, str 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);