Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp166558rwn; Wed, 7 Sep 2022 22:42:08 -0700 (PDT) X-Google-Smtp-Source: AA6agR60/qBvn8Tik5COyWaN7CxPAANqUx3XWkHQgtCCV/9a9nyCBiTqQ3lQnbbFVMi6O2qDuDcw X-Received: by 2002:a17:907:3da9:b0:772:79c9:88de with SMTP id he41-20020a1709073da900b0077279c988demr2204616ejc.766.1662615728467; Wed, 07 Sep 2022 22:42:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662615728; cv=none; d=google.com; s=arc-20160816; b=hRa95MaTR4/l86ad4wMYB92+MEt/nPbLrfzW9Hp22iqu3PUnUI+WGbaPY9/FM5diHg LTMTxPggb7TtY3K1AvSHLURGHOYsQ57Y1ygKj2C+mMEGw6KjzXG+Iy1vxsxrw/U2YNAO n7e9bfBPhqwnxqqvpKBIOewBxv3NxtvkQx1dZ3z0qGdI1JVGuAo/6d0dgdoF93fZb86v IOiNJOZubCc6bGyWnD9WEtlyPd7YYo4ZZqnJwT7znFIoKsw9JK/MJyKtrRTBGs0m6CQJ 5nC+SOOSA297d1tSvuow9crb4MDXNeZ2MZ19gUVuzdrvr7pJ6yMRKI6MU4DU6rkmWHJA Zp6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=AaqM60IEpusmibr/lWtbkp1uO2x9uJriZcuuDTblxjQ=; b=CMMwlCpKeQo1WSG5gjDtcbi3wCtRN8JmWWZ5+Pgl1A8qPSjsIK2JqZ8XS1nSkDlNB/ gX3+hrvXriHuySOh4BfpaeBhOQiVAeWJ5rT3TzTE7zDzkZ2ODAp+LL/Yw42yfurCnc+5 6xlh4auytYzwffYA/OXn0+B8wYA7Tvjao9ukne4D6cFMaEvGnUCBOrP12Wkvgw4XWufB 5dkOns+wwW9gWvlA73s4FhdTUBqEPxtIZh0w1UORM1aK5q2ZXU/MNLh73InUJFRvEm3k QDh2MR82my3ugQP4UsC4gpdr+UALRmbdsLqrobAYZJaZszV4N4qmuBF2P+L1QCHippM9 RYEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HpROFulE; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hq9-20020a1709073f0900b0073ced0e9bb1si1419697ejc.189.2022.09.07.22.41.44; Wed, 07 Sep 2022 22:42:08 -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=@kernel.org header.s=k20201202 header.b=HpROFulE; 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 S229674AbiIHFJI (ORCPT + 99 others); Thu, 8 Sep 2022 01:09:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229668AbiIHFJB (ORCPT ); Thu, 8 Sep 2022 01:09:01 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF98C92F55; Wed, 7 Sep 2022 22:09:00 -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 93595B81F74; Thu, 8 Sep 2022 05:08:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 00C59C433D7; Thu, 8 Sep 2022 05:08:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1662613738; bh=dg8wftGIvmW8f8CxANQmVU9WzgpbVESeuK33TzXQNuE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=HpROFulEeTkGHTFH1WQZcXr5tmSa3vWhKhn99/2aXSWhe7QrS/o92XogewYtQT75M yXKmuFb9SBJ5x/+C+/h+NtIrwvrwU4Lmi7b93zmj9yPltoOSHkdNkXKrzxSFfL04wD ie5mjahJpvZyqGTWpRYxS343ak7RJJEuS34xcFGU4sN/T18prCGq4AUEIegR6o3o+3 kI4c8F8nbSIxHhku1MkNhYnpIZ8RhwHKdPGk/eK+TEOg/CS1HU0aBKmHFAsDwM2uD0 BpmwwmQ0Xj1Qzlrjor1fu74rWCJ1C6H18rqdNu0t/jrCmMfFZEpGaqRp15XE80mHg2 7L1sMat+zGXBg== Date: Wed, 7 Sep 2022 22:08:55 -0700 From: Josh Poimboeuf To: "Masami Hiramatsu (Google)" Cc: Steven Rostedt , Peter Zijlstra , Ingo Molnar , Suleiman Souhlal , bpf , linux-kernel@vger.kernel.org, Borislav Petkov , x86@kernel.org Subject: Re: [PATCH v2 1/2] x86/kprobes: Fix kprobes instruction boudary check with CONFIG_RETHUNK Message-ID: <20220908050855.w77mimzznrlp6pwe@treble> References: <166260087224.759381.4170102827490658262.stgit@devnote2> <166260088298.759381.11727280480035568118.stgit@devnote2> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <166260088298.759381.11727280480035568118.stgit@devnote2> 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 On Thu, Sep 08, 2022 at 10:34:43AM +0900, Masami Hiramatsu (Google) wrote: > From: Masami Hiramatsu (Google) > > Since the CONFIG_RETHUNK and CONFIG_SLS will use INT3 for stopping > speculative execution after RET instruction, kprobes always failes to > check the probed instruction boundary by decoding the function body if > the probed address is after such sequence. (Note that some conditional > code blocks will be placed after function return, if compiler decides > it is not on the hot path.) > > This is because kprobes expects someone (e.g. kgdb) puts the INT3 as > a software breakpoint and it will replace the original instruction. > But these INT3 are not such purpose, it doesn't need to recover the > original instruction. > > To avoid this issue, memorize the branch target address during decoding > and if there is INT3, restart decoding from unchecked target address. Hm, is kprobes conflicting with kgdb actually a realistic concern? Seems like a dangerous combination Either way, this feels overengineered. Sort of like implementing objtool in the kernel. And it's incomplete: for a switch statement jump table (or C goto jump table like in BPF), you can't detect the potential targets of the indirect branch. Wouldn't it be much simpler to just encode the knowledge that if (CONFIG_RETHUNK && !X86_FEATURE_RETHUNK) // all rets are followed by four INT3s else if (CONFIG_SLS) // all rets are followed by one INT3 ? -- Josh