From patchwork Sun Oct 31 14:42:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12595165 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CDCC9C433F5 for ; Sun, 31 Oct 2021 14:44:14 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9BAB860F46 for ; Sun, 31 Oct 2021 14:44:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9BAB860F46 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=hWOyRr/mRTqaJ3KpxuDlmRGFgDvhLMlgJaIxh74j2Ac=; b=Ku9o0zudvLlkWw ccu1EgL+VDBBdKDFrtHqx/3CXp78EhjOXIHdJuyW0tGRY23Lm3RAJFcKj7nYULYC6MIKfNIYGfHZk N5AFHrUCq3FbHVQYEehL8zDMnTnNvL1lJ5jISbmZrTXKh7FO4R58eF6UaZAUuHjlWmYI5UPBumy+A MWBrqOTy7RWAiZeB9K0NPFJIbhCfCd6ukTPPdnVFznPe/m0xm+kj+5cKBFF8TSMarg89A/tgutziB PhrYFF0BI7nfa/XDsXbCaT0pGQ7mHonwSjQ47a2trTd7+sxrMnAoIBdKclogCtDdYC7RjGilJg04X TVpLjAm91t/cLNxSkSNQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mhC33-00ECVA-Tq; Sun, 31 Oct 2021 14:43:02 +0000 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mhC2j-00ECSz-C9 for linux-arm-kernel@lists.infradead.org; Sun, 31 Oct 2021 14:42:42 +0000 Received: by mail-pj1-x102d.google.com with SMTP id o6-20020a17090a0a0600b001a64b9a11aeso3423817pjo.3 for ; Sun, 31 Oct 2021 07:42:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=beclhWZk3zZOlcCh3M65MSbbbJkA4NCrMmRNtUJzgjw=; b=cPa3TvRtndC9F08ijkVxCIcA9hfQyiCNSmc+5tGVOEvSPq6DeO5449Oc6KSo4drY3W 2ji9igIaQ3yYPLSLsh7zyZks9JvsZ6+vDEh7pwYpF+syP6JFrUnAmTaFqA299xrBfCqQ 6ifE52tv6uUQQqoAisDng1ckQ4ZoAzKR+HgvTM5LDdWSrI9vgUjnEplU9ABQALT33R/E zDWrTgveSPBVFnT9buDbEjAJcmoKIzekEfdrjVvMsRpTZYGnuH+etosUGIPf3NcJJRnH zs5x1OAmDwtEaCpDx0zuokdgg97AWZzm9qGfaCfT70HwTP7XuTr/7+tJMKYlJprusiGa Dqkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=beclhWZk3zZOlcCh3M65MSbbbJkA4NCrMmRNtUJzgjw=; b=fqRCMubbdITPyfk1p9MCzuozn7wBUXI1tI+Klog42UJ+pHbBG39xxTQA2qVhJJchqR +6u274S/MI4H4aJC+eo8AyDAivFeLrWPx45VT42yxeUy2LR894O+DjLa+zgBPRbyPFum V1wuhpRZW2iCRmKUGGxoqAqJXKsc8HNB3zaVN/08Va2DLXUfg2SfZtzG1Mqe0WjlLEe4 VYM/RdWF0i6PlwrgVwDHZn7Js2KDWLsVJbT9wCuT7j1iwUgJsA+wQc8KjI2m202pbODX i+qDTwB2kmQI6K6V1nmZv0Bu9zk/d6Nge+KJWl0lIZTxzeeENkfBBOD3az5bglYztg00 glZQ== X-Gm-Message-State: AOAM530xV7tdfRExiAErObzxNJzJLwtvtSvQEST6i7tdMtnKtVPCodpX 0r8QB8DSB9MVrH/Mp4yMvIYXZQ== X-Google-Smtp-Source: ABdhPJxxP8iviH2KsSwwMEIFD9QUMKimBYb9VpD3xn3ySaU04zl0IWmXoiK1P75a8LNwY/iJAgCpVg== X-Received: by 2002:a17:902:a70e:b0:141:a01d:9d6c with SMTP id w14-20020a170902a70e00b00141a01d9d6cmr17132607plq.84.1635691360562; Sun, 31 Oct 2021 07:42:40 -0700 (PDT) Received: from localhost ([134.195.101.46]) by smtp.gmail.com with ESMTPSA id o13sm14332316pfu.90.2021.10.31.07.42.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Oct 2021 07:42:40 -0700 (PDT) From: Leo Yan To: Mathieu Poirier , Suzuki K Poulose , Mike Leach , Alexander Shishkin , James Clark , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH v1 2/4] coresight: etm4x: Don't use virtual contextID for non-root PID namespace Date: Sun, 31 Oct 2021 22:42:12 +0800 Message-Id: <20211031144214.237879-3-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211031144214.237879-1-leo.yan@linaro.org> References: <20211031144214.237879-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211031_074241_442678_813C1B19 X-CRM114-Status: GOOD ( 15.78 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org As commented in the function ctxid_pid_store(), it can cause the PID values mismatching between context ID tracing and PID allocated in a non-root namespace, and it can leak kernel information. For this reason, when a process runs in non-root PID namespace, the driver doesn't allow contextID tracing and returns failure when access contextID related sysfs nodes. VMID works for virtual contextID when the kernel runs in EL2 mode with VHE; on the other hand, the driver doesn't prevent users from accessing it when programs run in the non-root namespace. Thus this can lead to same issues with contextID described above. This patch imposes the checking on VMID related sysfs knobs, it returns failure if current process runs in non-root PID namespace. Signed-off-by: Leo Yan --- .../coresight/coresight-etm4x-sysfs.c | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c b/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c index e4c8c44d04ef..e218281703b0 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c +++ b/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c @@ -2111,6 +2111,13 @@ static ssize_t vmid_val_show(struct device *dev, struct etmv4_drvdata *drvdata = dev_get_drvdata(dev->parent); struct etmv4_config *config = &drvdata->config; + /* + * Don't use virtual contextID tracing if coming from a PID namespace. + * See comment in ctxid_pid_store(). + */ + if (task_active_pid_ns(current) != &init_pid_ns) + return -EINVAL; + spin_lock(&drvdata->spinlock); val = (unsigned long)config->vmid_val[config->vmid_idx]; spin_unlock(&drvdata->spinlock); @@ -2125,6 +2132,13 @@ static ssize_t vmid_val_store(struct device *dev, struct etmv4_drvdata *drvdata = dev_get_drvdata(dev->parent); struct etmv4_config *config = &drvdata->config; + /* + * Don't use virtual contextID tracing if coming from a PID namespace. + * See comment in ctxid_pid_store(). + */ + if (task_active_pid_ns(current) != &init_pid_ns) + return -EINVAL; + /* * only implemented when vmid tracing is enabled, i.e. at least one * vmid comparator is implemented and at least 8 bit vmid size @@ -2148,6 +2162,13 @@ static ssize_t vmid_masks_show(struct device *dev, struct etmv4_drvdata *drvdata = dev_get_drvdata(dev->parent); struct etmv4_config *config = &drvdata->config; + /* + * Don't use virtual contextID tracing if coming from a PID namespace. + * See comment in ctxid_pid_store(). + */ + if (task_active_pid_ns(current) != &init_pid_ns) + return -EINVAL; + spin_lock(&drvdata->spinlock); val1 = config->vmid_mask0; val2 = config->vmid_mask1; @@ -2165,6 +2186,13 @@ static ssize_t vmid_masks_store(struct device *dev, struct etmv4_config *config = &drvdata->config; int nr_inputs; + /* + * Don't use virtual contextID tracing if coming from a PID namespace. + * See comment in ctxid_pid_store(). + */ + if (task_active_pid_ns(current) != &init_pid_ns) + return -EINVAL; + /* * only implemented when vmid tracing is enabled, i.e. at least one * vmid comparator is implemented and at least 8 bit vmid size