Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp31802pxb; Tue, 23 Feb 2021 17:06:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJyo2TMLWeOtw+FRqkUuHfQbGiNdRtDpV8MPKYokXExTiW8Xryxw5qAsUd3+6Quo46qc3Y/y X-Received: by 2002:a17:906:b042:: with SMTP id bj2mr28239154ejb.261.1614128797546; Tue, 23 Feb 2021 17:06:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614128797; cv=none; d=google.com; s=arc-20160816; b=ZL31bKBAgvJU/BpKch1jVi/k4uu9ZrVB4RsN3gwev+XC+VlNmeflvuh7C/s528YBHa N0PmbfzqM+H7IfstSMBEIA5t9olQ7wAZH9VtIVlqD6SCMvgzXxRG5jVkWfZARee7jn1J xnTPx+EJvgDaddFsWM45hWqQhonvzBK7M0RfAPLPivLC6Kn3wCuLOidY8YjM/4b/bqOa 64NvrkAeGxpRPrvycXWTFLlpPjZpWH2iT4eCc/5XhgqruyNG7cK0G99S65EW5WXUP4eQ 6lHXu3iI0aKLgiE9JigOJfZmG4pRA4oYrNq6IDSKA5/Vz39hlCowxLi8l+C8CFHf91o7 1buQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:subject:message-id:date:from:mime-version :dkim-signature; bh=N2/kfrdkiVUYdZ7nOdcyVOerhag6mcvHp1YkRqp3d0Y=; b=Rhc4XCD/YwlS4AcqAfQA1NL+DhWix9vRlWCHdxmNYv2ANA1tAuV767z6pdjidKiwFQ U482cHXLUj43MdMmDpU4fRdtViZA+M+pUBpgrBeOa0eITt70CG9ZFZMnJ82zKKwd78zp VfUGjBRKsov5EQ3xNOAk1SlYAfJgL0VSXdg43J09EfyyVp7lra5I0veCx9EVNaNI8n28 v1QT9R7y38pyptGFcNdV5PEFr45bzgLXJW6NyQkq70AMfG7STKvBvSii08zUDC1q7Wp0 50X93fPD7Cz6V7rzblDJPLRmBYF9VmK1vYB1WC/J47+BCTxv9mOHn65ttOBDQtJtiI3p D2mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FMCHZcvn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l20si271000ejn.375.2021.02.23.17.05.46; Tue, 23 Feb 2021 17:06:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FMCHZcvn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S232549AbhBWXgN (ORCPT + 99 others); Tue, 23 Feb 2021 18:36:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:50876 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233725AbhBWXZY (ORCPT ); Tue, 23 Feb 2021 18:25:24 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id AE84E64E7C for ; Tue, 23 Feb 2021 23:24:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1614122672; bh=KP288goND8M4n+LhyazQ7ab4gsFaGAFzzE584UPD1iM=; h=From:Date:Subject:To:From; b=FMCHZcvnzRhWfLWiDCxJvKlBYnB30wJTSuwjs6oSUdZvwyiC/ZvFLYNLqDgtZkQy6 mhrekxItrf0QBCzKI05JXFwbzBkxrk+sgAAaXpE2r42tfVnYkl8ELIUtaevGNNY7pm GaRyoihatR5Sgq2PGXixvajShiy9NjiORv9uFuNHChV9wnwuyM+lBrvyqpIsyozyms e6YiFJIvTDn8SAq1keDZSpPJbslxQDEWx0epSpgAauvzJBKWmj58FzhES/0Gb5DWXy k+Js8h9qbXAd7rH2WYSAsRaQdlGr6OMYGHPoJm/Wrno3vwsBpxlhdkovmtVgnT3a4V pga1Aa+pm03pA== Received: by mail-lf1-f41.google.com with SMTP id j19so192514lfr.12 for ; Tue, 23 Feb 2021 15:24:31 -0800 (PST) X-Gm-Message-State: AOAM533YRau7MuAQ63SPjDhmnr7aWsDrdyWSPjHEfvc4nxRB6cfk2WQu zsQgPt7SQ8Zfi5+4cUAbJjqzSMHyIGn2ijW7r2hT6g== X-Received: by 2002:a19:810c:: with SMTP id c12mr18485404lfd.244.1614122669974; Tue, 23 Feb 2021 15:24:29 -0800 (PST) MIME-Version: 1.0 From: Andy Lutomirski Date: Tue, 23 Feb 2021 15:24:19 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Why do kprobes and uprobes singlestep? To: Oleg Nesterov , Masami Hiramatsu , Peter Zijlstra , LKML , Anil S Keshavamurthy , "David S. Miller" , X86 ML , Andrew Cooper Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A while back, I let myself be convinced that kprobes genuinely need to single-step the kernel on occasion, and I decided that this sucked but I could live with it. it would, however, be Really Really Nice (tm) if we could have a rule that anyone running x86 Linux who single-steps the kernel (e.g. kgdb and nothing else) gets to keep all the pieces when the system falls apart around them. Specifically, if we don't allow kernel single-stepping and if we suitably limit kernel instruction breakpoints (the latter isn't actually a major problem), then we don't really really need to use IRET to return to the kernel, and that means we can avoid some massive NMI nastiness. But I was contemplating the code, and I'm no longer convinced. Uprobes seem to single-step user code for no discernable reason. (They want to trap after executing an out of line instruction, AFAICT. Surely INT3 or even CALL after the out-of-line insn would work as well or better.) Why does kprobe single-step? I spend a while staring at the code, and it was entirely unclear to me what the purpose of the single-step is. --Andy