From patchwork Mon Dec 19 14:35:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 3094 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp2424018wrn; Mon, 19 Dec 2022 06:35:44 -0800 (PST) X-Google-Smtp-Source: AA0mqf6+7YkGGy9eUjM9EiApjIWwLeNq0d+eW737BzrZElGUkvjZTMvAHqY6UURtJ4X0mJYkJx/U X-Received: by 2002:a05:6402:12d6:b0:46b:444b:ec40 with SMTP id k22-20020a05640212d600b0046b444bec40mr35733469edx.15.1671460544393; Mon, 19 Dec 2022 06:35:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671460544; cv=none; d=google.com; s=arc-20160816; b=Cf1qVeZTd5gcMtTRcFeg3WbBY9KCj4hj50ePJ24Teutub8u9yvwfAdrcvvWg5G++LP moGLv8Sjo19fHX8gOoxwBGRZuAaOURSu/dH2Qbo83CGTc4Ju4j7VlY1r7zLP2/tdPvcB KVfV2OMJPdQxmsesRfMSOHrv2QC+0ajvES4KZfa/QgY4SMCE/MZNLtRh8uTkJFHQMCvA lyPQI8+/1nk9GE06waVq7fxkEPXwZ4FMlr00MCPUFG0Jumv4c/grmT2cU0EHMlq7p5R0 +hiHQZeoO3y3rhVRwdK4xy6V4E640lhYBOA78HgbH2Fcbb496Y6VH7/0HzLyM4xwWkov 32TQ== 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:message-id:date:subject:cc:to:from:dkim-signature; bh=LleU7lh486EWpSCmP0/kjVWEuCyHnpkTuGz+n/GH7Uk=; b=BHMfJgZ/X5X8z6w3kdsOm+FNBPFYZNEt4JaCgHlehP7ykRdz9A2GBEXzQDQWbNXw7p Wczzmz7G8IudgI1thDdsH/o/hEvceADfoAUgADBtNAtg8xy8mNl+gCCNURDP3q9J9jbJ D9FNqrMFdlPMtvNtrjGW8A+zD6gEi4zU4FiWMtNSmd0SyVcMoSmXk9JVQEbll6XC0rmR q2yo4axEfYYvS5G9FPcRKTWJQvqkR055Kb5DJK44xI4fDSVUj9KCuMi0odf3YA4Mtb37 vCjYY5IwfbQOEb3P+12NHnbTHo4ef1oDOowv74dl+nmYcWRRHufOchIn/C8ERZWbTKAs Nkjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="q/YxNgFT"; 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=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s13-20020aa7d78d000000b0044e987f3a34si8362037edq.489.2022.12.19.06.35.21; Mon, 19 Dec 2022 06:35:44 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b="q/YxNgFT"; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232257AbiLSOfP (ORCPT + 99 others); Mon, 19 Dec 2022 09:35:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232249AbiLSOfI (ORCPT ); Mon, 19 Dec 2022 09:35:08 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E08AB07; Mon, 19 Dec 2022 06:35:07 -0800 (PST) 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 3356EB80D19; Mon, 19 Dec 2022 14:35:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4D60DC433EF; Mon, 19 Dec 2022 14:35:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1671460505; bh=ovmSOyXpdhZkVdvPTmi4MkzRm45TRy0WVB+TsJRSG+Y=; h=From:To:Cc:Subject:Date:From; b=q/YxNgFT996DZFPVp7bZFUV5THnnXuKC5RHDr7TDWh0gWkXV1UjCeq1a21/ejNk/a od/bJMmgWTabez6waaqfyOxkw+FjP15IhIYVKTuLzOxn9A8dynR77ilFq7FnCIZcuF QbzcU6+ylxTDNHHHJvMZOaHMPPN6Pgz8EgdDnR4yISA7wtULAH4ONxqSA88yQudSAd 9DRpULDwxQmI5E7HsSYps/OI2LQcOO738gLx0R/2ousxikLRaefswpQEuLqrngzCuA 3IYbNRxq3udkq2i4JkSkBOdQplOm03lnNREkP779jWIEm45euCocFDdwnpB/rZCey/ bwM6rNPC2iPAA== From: "Masami Hiramatsu (Google)" To: x86@kernel.org Cc: Steven Rostedt , Masami Hiramatsu , Ingo Molnar , Suleiman Souhlal , bpf , linux-kernel@vger.kernel.org, Borislav Petkov , Peter Zijlstra , Josh Poimboeuf , Nadav Amit Subject: [PATCH -tip v4 0/2] x86/kprobes: Fix to check not-kprobe's int3 correctly Date: Mon, 19 Dec 2022 23:35:00 +0900 Message-Id: <167146050052.1374301.10407562178447545337.stgit@devnote3> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog User-Agent: StGit/0.19 MIME-Version: 1.0 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752653411413526589?= X-GMAIL-MSGID: =?utf-8?q?1752653411413526589?= Hi, Here is 4th version of the patches to fix kprobes and optprobe with CONFIG_RETHUNK and CONFIG_SLS. Previous version is here; https://lore.kernel.org/all/166264927154.775585.16570756675363838701.stgit@devnote2/ I just ported the v3 on the latest -tip tree. With CONFIG_RETHUNK/CONFIG_SLS and after many efforts, the kernel functions may includes INT3 for stopping speculative execution in the function code block (body) in addition to the gaps between functions. Since kprobes on x86 has to ensure the probe address is an instruction bondary, it decodes the instructions in the function until the address. If it finds an INT3 which is not embedded by kprobe, it stops decoding because usually the INT3 is used for debugging as a software breakpoint and such INT3 will replace the first byte of an original instruction. Thus the kprobes returns -EILSEQ as below. # echo 'p:probe/resched_curr_L21 resched_curr+98' >> dynamic_events sh: write error: Invalid or incomplete multibyte or wide character Actually, such INT3 can be ignored except the INT3 installed dynamically by kgdb. To avoid this issue, just check whether the INT3 is owned by kgdb or not and if so, it just stopped and return failure. With thses fixes, kprobe and optprobe can probe the kernel again with CONFIG_RETHUNK=y. Thank you, --- Masami Hiramatsu (Google) (2): x86/kprobes: Fix kprobes instruction boudary check with CONFIG_RETHUNK x86/kprobes: Fix optprobe optimization check with CONFIG_RETHUNK arch/x86/kernel/kprobes/core.c | 10 +++++++--- arch/x86/kernel/kprobes/opt.c | 28 ++++++++-------------------- 2 files changed, 15 insertions(+), 23 deletions(-)