Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3027963rwb; Mon, 15 Aug 2022 16:26:23 -0700 (PDT) X-Google-Smtp-Source: AA6agR4vhghrWwbphkprUXeT3rPmA83It9lKalM6AQgKBTs6MWs3fdGGh+X+XTi4K8JejSxVOSiP X-Received: by 2002:a05:6402:3222:b0:43e:49f9:11e with SMTP id g34-20020a056402322200b0043e49f9011emr16614825eda.426.1660605983018; Mon, 15 Aug 2022 16:26:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660605983; cv=none; d=google.com; s=arc-20160816; b=hEuO1yqDHlQTcqyyPuy2SDO6zPGIQbT+MTuosrQi4lsG9vXiqWC5/IQeSodwJ8C3Gj mV1YodgB9WXBbkqm2m7H4lC78V6YFfCSxAHowUIOva15dAtagfeeV6ddeROkCi7Jnxim Oc80VzFf69+EYGFCwKS9hI+S/Ht/itqA6cP5nfN7ixosTbwRItqs9jF2J+69Ni2CRpDy ShN8jiGYoSkPDKXX5g9jwO2dE9vm0PVb0OP0CUHjvtkk1V9Gnm4dp0EanivrtF7SFlsI Mhj/ugCIvckfzMGjOOYrBlAmgIW7GPZl3wixXWW29QE+BQSXLQqqfNAr4e/ZrtbPqS3D MzyA== 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=SXT+vmkPcaIUSM/lmApYj1XGmFhaGWF/T5+tAY+JzdRsBbLi3oks+2K85zkPtrckD1 dKS/shwAMZVPziz7rmHsfiwWKv1JyTCRwfuhxQd+cPG6MiRloGJFJMRDP2RSOSBletD7 Y/+E1PivVxOWOsssgrm1hUzgiUldp+5cyBWaWX7/Bouo8Hwu5Vwx0kvQBXxwcMlerInc xHSsijnzUTEbo/KxsSVF9i7VUaqBIXEr/AyqYwtIUpfo+47wMgsEvqiWD7Bmz/Hevjog dFuRFlRmok6TFpOSL9nkulY/dRrohWL4QqLOgEVYhZLPsmX9XqKUauATu8KsQfcn62mR iqQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hUpRlrWA; 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 q28-20020a50c35c000000b0043cd18d34e1si7615507edb.177.2022.08.15.16.25.58; Mon, 15 Aug 2022 16:26:23 -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=hUpRlrWA; 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 S1344045AbiHOXLo (ORCPT + 99 others); Mon, 15 Aug 2022 19:11:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345864AbiHOXKJ (ORCPT ); Mon, 15 Aug 2022 19:10:09 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10F74870AE; Mon, 15 Aug 2022 12:59:56 -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 EF93061299; Mon, 15 Aug 2022 19:59:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 00E9EC433D7; Mon, 15 Aug 2022 19:59:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660593595; bh=ufwO8vqLDDu71bVtWRi8o3m8JUyw8NsgBLtUn+/druI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hUpRlrWAHORJJNauTBMIcUWzRhARgnSNnLWSXgveEaBzH6FyffpcI2WS4BE/c7qRL NiuuqN0H9Z1MJOFeUjgw2Re73ktcMt3fhbp/dfg3JnKBV3Z8t+eModbidrXMJ/5zeF 8MpPT+WSLu3SAslPmWziQdQkH6K2JdhrvB6S/K8E= 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.18 0973/1095] x86/kprobes: Update kcb status flag after singlestepping Date: Mon, 15 Aug 2022 20:06:12 +0200 Message-Id: <20220815180509.331090424@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@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);