Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3409175rwa; Tue, 23 Aug 2022 04:25:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR4XYXIWjhcw473mviPBSTPXfSqH4ECeJ6CvjwHsOQtCZa9ngCz9MYO79W2GJLx7znIsigjH X-Received: by 2002:a17:902:ca01:b0:172:bc42:be8e with SMTP id w1-20020a170902ca0100b00172bc42be8emr21476479pld.47.1661253901549; Tue, 23 Aug 2022 04:25:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661253901; cv=none; d=google.com; s=arc-20160816; b=mjz3QCZUayXZagHTTXD5Tl67de6hxbFLuptlrF5h0gJ3SvCJnP6zTd+v7AZKPVHaEm 0uvJRieXWhh32WXIiq2uUiKIymSdg33xg/4tCyIcQXtclMIV0KCRZGIRPOCG3VWsTOAW FaUS1q4CK37FYO6oRJdjqwzVql8tqv1fM5NridJpd5/MSOz8RVo7SrixGDDc0LztZuXz 9zoA5jNk3EQQrA8AKd7Xzo4bpre2/PH6NNL5h6Svjgy8hcOBVuEGSZav/S46ivoeu5td qDBvj+ZtK3MXc+7X+WFdNvLDKba7ChdCo6cY+EYFDeUVcZMp2ZFhEHPNPT4X1n2JBB2f CPIQ== 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=I1+iB5PP9UYgakRS7G6cVliR7+tvHO/wCVEb7nj97pg=; b=01mRgue3O2XjVR4V7l1evFLNlq4FSd+vDmlHUDnU62VT6vJp+m8NoNUDVblDUcQ9aC RNd7B83hvSk4RYEWnzqewAso7V+EvUaNy7QDRlpHALUzy30fSQR2WDrDhRbqbJQ2mKZx wqNP7yt0mj8apOK2wH2FPqlevbPDzrNJAozaV5QxXfXJCzu4zqiZkufM2m2evSJcLOem nul0uBmXYs5TCDiSoCL5P+ZyeoH/EeeD+pufYLmtlkE/cbCzRkVgo33BN74olFE3ka6J F3akJi955IwHOgjyUYApZvFB4jfH/b+paPRgEJFFvY5hXBlwKZq1oUFut4FrkhkAV9hQ sUQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fa144yv2; 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 f3-20020aa78b03000000b00535fd435cf6si12624782pfd.208.2022.08.23.04.24.50; Tue, 23 Aug 2022 04:25:01 -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=fa144yv2; 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 S1351617AbiHWJiE (ORCPT + 99 others); Tue, 23 Aug 2022 05:38:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352013AbiHWJgO (ORCPT ); Tue, 23 Aug 2022 05:36:14 -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 D9AEA2FFDD; Tue, 23 Aug 2022 01:40:33 -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 5538661485; Tue, 23 Aug 2022 08:40:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 595BDC433D6; Tue, 23 Aug 2022 08:40:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661244032; bh=4Cb4EScxWu5uEnn14G8m0os0jWAhkF8wAszG1ZWvLFw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fa144yv2zYtV7wh5sBf9hmej8dGqLGdLAj79QRo1BnPF6MBgvte3YJj0tR2RkhnMS n09lmtIVX5fWuKGBxhPHYhC9zhsNBX1MDjbUy0eOoQfuIaV0KxYtV5kof+ARNs2G1I ULxalASQbNyGRZjKNuA2kP5FgK/smTB3PbxpB/7Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nadav Amit , Ingo Molnar Subject: [PATCH 5.15 018/244] x86/kprobes: Fix JNG/JNLE emulation Date: Tue, 23 Aug 2022 10:22:57 +0200 Message-Id: <20220823080059.681664163@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080059.091088642@linuxfoundation.org> References: <20220823080059.091088642@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: Nadav Amit commit 8924779df820c53875abaeb10c648e9cb75b46d4 upstream. When kprobes emulates JNG/JNLE instructions on x86 it uses the wrong condition. For JNG (opcode: 0F 8E), according to Intel SDM, the jump is performed if (ZF == 1 or SF != OF). However the kernel emulation currently uses 'and' instead of 'or'. As a result, setting a kprobe on JNG/JNLE might cause the kernel to behave incorrectly whenever the kprobe is hit. Fix by changing the 'and' to 'or'. Fixes: 6256e668b7af ("x86/kprobes: Use int3 instead of debug trap for single-step") Signed-off-by: Nadav Amit Signed-off-by: Ingo Molnar Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20220813225943.143767-1-namit@vmware.com Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/kprobes/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/arch/x86/kernel/kprobes/core.c +++ b/arch/x86/kernel/kprobes/core.c @@ -495,7 +495,7 @@ static void kprobe_emulate_jcc(struct kp match = ((regs->flags & X86_EFLAGS_SF) >> X86_EFLAGS_SF_BIT) ^ ((regs->flags & X86_EFLAGS_OF) >> X86_EFLAGS_OF_BIT); if (p->ainsn.jcc.type >= 0xe) - match = match && (regs->flags & X86_EFLAGS_ZF); + match = match || (regs->flags & X86_EFLAGS_ZF); } __kprobe_emulate_jmp(p, regs, (match && !invert) || (!match && invert)); }