Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1048334imm; Fri, 15 Jun 2018 10:18:51 -0700 (PDT) X-Google-Smtp-Source: ADUXVKI6pWie01om+w/z25sJLvz5FPifZ2LKIO5/EQm8/JiqnI66OrZqfzAfRNRJ6QNeHeW0Hkoz X-Received: by 2002:a62:1358:: with SMTP id b85-v6mr2924580pfj.238.1529083131679; Fri, 15 Jun 2018 10:18:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529083131; cv=none; d=google.com; s=arc-20160816; b=rnwWONvpGAlmi4aVg6g60mKuF92Nk79pRtrHcieyS3nCEDF/G7xbSrC0NkNHmRRS+t npQhhv08tSotSahs0pTNZgoL3hnxmlozjEolsbVy8VJfoQr4VwibdiPhUMISTHe8dW4w zN3XQ7kvegPWNf0fWZgyltMeoKuR8XyFUuouMbEgrnnsFnIDYstfGzBjdffgVeiMp8iB 69tfqYHo2eS1JXWhzW0D02/z7jeM7r/HLfEgFoySK2OoP4sJ+gJFony71ae9t3EHBbpK 1AcNxXo8Du8/PRFb5knSPkikiO5Vs+rNVYLZncQkyIi7oROHV+s5TVbguAW7+q49pauv 2xRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=QYIzPrjeiyNxAK55dmln+/7Ms6ycCLA5IMAYzGHiFog=; b=1BgrbB636PAY+DppOKSXb3l8VM66ZWox3hMpVB6ZUvMLMADX/01GFo/law75/LuCUT WJxJ23FVXR3nwVr/hPq/X1OBgGvcMya1o33FqC2SolIxhzs3zqjx8GnF295GoivYIi1u n+xwUrm2k27i68Y9+eZcb6GALetQJLaEs9pASj/fuLZkr9bqK8cQbXDOaf7AX3ZGgDZV OdSjNlNohg/C6e0bEd+om9dwT/1kXtFJ0Ehw4AvWdRg7hf1YKnt5E2OEADG14LFXOAcC JvviOzYcvZoT17tE2QOPEa0Npqq2ICBk8olMpT4XT1TX5aWyxX1PtgRKLK7nl6dIbxrg Q/Ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kylehuey.com header.s=google header.b=UyvDaBgU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l12-v6si8156932plc.215.2018.06.15.10.18.36; Fri, 15 Jun 2018 10:18:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kylehuey.com header.s=google header.b=UyvDaBgU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936364AbeFORQp (ORCPT + 99 others); Fri, 15 Jun 2018 13:16:45 -0400 Received: from mail-ua0-f193.google.com ([209.85.217.193]:40134 "EHLO mail-ua0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936136AbeFORQo (ORCPT ); Fri, 15 Jun 2018 13:16:44 -0400 Received: by mail-ua0-f193.google.com with SMTP id l11-v6so6874315uak.7 for ; Fri, 15 Jun 2018 10:16:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kylehuey.com; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=QYIzPrjeiyNxAK55dmln+/7Ms6ycCLA5IMAYzGHiFog=; b=UyvDaBgUVttfGcxEymF8uxasqYv1TanudnixRDSncDaYfOdQNzHc3agPbyjshSzfvi 5yxSl0ovaSu0oXyalwxv//ZR+JnefFit4ziltMTaeSaVZgW/SeCELSr/5U0k3qY8x44p aVujdvcqLiRp0ry7UWxEeeEiaWU2/oP5CaWElx0D9ejbONDHLXsMytjQc10crma6nUwu ZaYfTOzo1s/0bdlzLD6JOoR8fiMMPuTyO/+4Rrry5nRGdE3FeQrvmFkNjaAyfYh+ZzCQ Zu7aIuLrexVdT+vNEFBEnYPXzocBrvzrIXtYKx9TW/bEVUbNkeo68K72s5V3gOa1EeXx +FzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=QYIzPrjeiyNxAK55dmln+/7Ms6ycCLA5IMAYzGHiFog=; b=ssQkeRlWj8TgniFADV8F5yY6HHS4tImOy6dPQtxzA7jCkM2KY3IcjDvUsKPElJ7s4z JwC00doke9zcgzuCyvglWBfChEVQOSzQicePySHLpBd74YWV5nV4CiKwEc0xD3fXGmJx 8kfubK09bJJgq7FM75bg4TMoPO9lLX+QXdqO7vUWKGryjZnKwC5RoLIQMcHWliTJfk3Q EG0veTw+FrsVFHU8IqxBAufk7l95lVAoK8lD2+WdBSlN1cin46ZUCmRkS7D5PRV1TRfO KQer6oeK3lEv1mmfmnyiQjW+XHJzmUW1DLEtP61P6JujFnHDypYiH74Tx7AMY3ETt2k8 h2rw== X-Gm-Message-State: APt69E1+H1qUtDSMHisiE8Ho8sHUy9TaUGEJWW3ZfnxEHdxq7H4EmZvX 5EOs27PGYl+EYA5elI8Hb+uH02JWx4c2qyxtQi77SA== X-Received: by 2002:ab0:5dd0:: with SMTP id l16-v6mr1668074uag.115.1529083003456; Fri, 15 Jun 2018 10:16:43 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:ab0:11c9:0:0:0:0:0 with HTTP; Fri, 15 Jun 2018 10:16:42 -0700 (PDT) In-Reply-To: <1a442b37-7a97-86f0-11e3-58d940ecfbc9@linux.intel.com> References: <1529057003-2212-1-git-send-email-yao.jin@linux.intel.com> <1a442b37-7a97-86f0-11e3-58d940ecfbc9@linux.intel.com> From: Kyle Huey Date: Fri, 15 Jun 2018 10:16:42 -0700 Message-ID: Subject: Re: [PATCH v1 0/2] perf: Drop leaked kernel samples To: "Jin, Yao" Cc: acme@kernel.org, jolsa@kernel.org, "Peter Zijlstra (Intel)" , Ingo Molnar , Alexander Shishkin , open list , Vince Weaver , Will Deacon , Stephane Eranian , Namhyung Kim , ak@linux.intel.com, kan.liang@intel.com, yao.jin@intel.com, "Robert O'Callahan" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 14, 2018 at 10:11 PM, Jin, Yao wrote: > > > On 6/15/2018 11:35 AM, Kyle Huey wrote: >> >> I strongly object to this patch as written. As I said when I >> originally reported[0] the regression introduced by the previous >> version of this patch a year ago. >> >> "It seems like this change should, at a bare minimum, be limited to >> counters that actually perform sampling of register state when the >> interrupt fires. In our case, with the retired conditional branches >> counter restricted to counting userspace events only, it makes no >> difference that the PMU interrupt happened to be delivered in the >> kernel." >> >> This means identifying which values of `perf_event_attr::sample_type` >> are security concerns (presumably PERF_SAMPLE_IP is, and >> PERF_SAMPLE_TIME is not, and someone needs to go through and decide on >> all of them) and filtering on those values for this new behavior. >> >> And because rr sets its sample_type to 0, once you do that, the sysctl >> will not be necessary. >> >> - Kyle >> > > Since rr sets sample_type to 0, the easiest way is to add checking like: > > if (event->attr.sample_type) { > if (event->attr.exclude_kernel && !user_mode(regs)) > return false; > } > > So the rr doesn't need to be changed and for other use cases the leaked > kernel samples will be dropped. > > But I don't like this is because: > > 1. It's too specific for rr case. Keeping existing software working is the first rule of kernel development! There is no disclosure of kernel space state in the way rr uses this API, so there is no reason that this API should not keep working. > 2. If we create a new sample_type, e.g. PERF_SAMPLE_ALLOW_LEAKAGE, the code > will be: > > if !(event->attr.sample_type & PERF_SAMPLE_ALLOW_LEAKAGE) { > if (event->attr.exclude_kernel && !user_mode(regs)) > return false; > } > > But rr needs to add PERF_SAMPLE_ALLOW_LEAKAGE to sample_type since by > default the bit is not set. There's no reason to add a new PERF_SAMPLE flag. You need to audit the *existing* PERF_SAMPLE flags and figure out which ones are problems, and then do if (event->attr.exclude_kernel && !user_mode(regs) && sampling_discloses_kernel_information(event->attr.sample_type)) { return false; } > 3. Sysctl is a more flexible way. It provides us with an option when we want > to see if skid is existing, we can use sysctl to turn on that. If you want a sysctl for your own reasons that's fine. But we don't want a sysctl. We want to work without any further configuration. > Thanks > Jin Yao > - Kyle