Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2101571pxb; Sun, 31 Oct 2021 07:48:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJoeBazI8dD2GOpJ9tfuzxzUAMknd94o8nho393NW7wes0mqDhb6y4EsVJduoQY4wgPoxJ X-Received: by 2002:a17:906:6a0a:: with SMTP id qw10mr1117183ejc.547.1635691680126; Sun, 31 Oct 2021 07:48:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635691680; cv=none; d=google.com; s=arc-20160816; b=St7Q0/ofhUCdQeY04Q/bAK7U1ur4lJb10b1Mu90ks9uy4r6ZOdds36DmlmMz3yUKfH AnnYCt+HvEHodHzq1PQF8xYe/kHktLUKDzZ5qy5hP40nFp6GrQ2MPvEKDNMg1BoWOsjd NKWq8X0W9BgZRRmIMDc1Uk2OfEKRJ1OKi4vpnvYCh7CEXOzYnddnwCFG743FsmKp2Nj5 VsrFdN4YxwNk6hDOaLr9D6207Hvo333H0B2Uqd2XjlEM74J2aJ8y1yJVDokM2/Nc/hhg xEOn8eO9nzW9ykRMW1CvPeyBKUlAcx5eODZFFbASypnngs8scdtljyPQSszPM+z48/Cf 3x6A== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=beclhWZk3zZOlcCh3M65MSbbbJkA4NCrMmRNtUJzgjw=; b=TOptb0r9kWmsxDbTZ0qCeTUPAbdsZHjcvtgEnuPePPOzG8ZQ3DTpXkT2TnFUMPerqE fIMBuT3yDhM5eSxT6iCHeyo9br4f4AJjtzg+V84fP5XIW3PuPZtJPIq1P+PHmjh4Ca+8 FTis/JEsBFkvcLD64WP3TE3dkIKGEffjnxF4gab2U8zt5ygivMtYhuUfjJaipK4B5F0Q crQnq1qu/MIvbX5hz3NBETW/2kjz8bmNxumWid0noO/A0bc95x7oGoTVELg3wKWuH/BM gBQ3kUTaDMZfqwSf7qxgaaTyG6Rxcctjmy2qQBx+vbZGCQwa88h/JNbauvE4wyVATUMM A39A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cPa3TvRt; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z5si3439138edd.266.2021.10.31.07.47.36; Sun, 31 Oct 2021 07:48:00 -0700 (PDT) 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=@linaro.org header.s=google header.b=cPa3TvRt; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230075AbhJaOpN (ORCPT + 99 others); Sun, 31 Oct 2021 10:45:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230054AbhJaOpM (ORCPT ); Sun, 31 Oct 2021 10:45:12 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16D59C061570 for ; Sun, 31 Oct 2021 07:42:41 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id na16-20020a17090b4c1000b0019f5bb661f9so10744219pjb.0 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=h9YVX9LNuC7LWLrjGKkA05x4Xx1LRm7FGZNzwyNdcIlUoYz2S8G+ra1IwpOSaMVCC/ GoZx1uT5mVTq3Y/SNc4TBaFpx7WVobSLG4FwlMbrzDKzZ0QfpY0elzpGEe0mWd94A6rJ b0bRN/unwoOnLmbErHRw+izl87hkVdOTNHteOAFKIpyv1lClPDuEEFVDFirJ5IFmp/Dh /ab5Jsro0zzuXilclJM2M8LyB0mwnfnnMPfG7mVvcqzB4ljrTftg9RsITend81h1PgK7 /73j5WHzws1ujfE7fKN81BPoMkn6YrVAR9KKeFoZFNeptuf5ExeqeXt6UsZjK2pH2oI5 DICg== X-Gm-Message-State: AOAM53041jzaEK4FZGZ7vdDVp2lQPbZpxtRtGYSSKAOCiVEV2GOCtmGm 2b7UPOpWufwPyJc7WZYIWbCwNA== 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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 -- 2.25.1