From mboxrd@z Thu Jan 1 00:00:00 1970 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id A4C84C433EF for ; Fri, 4 Feb 2022 15:26:03 +0000 (UTC) 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=xB5yIoA7dpUY4ReOcRXZ0rq7HhN5Wpn+WtSEAeSwW/w=; b=rFqaeLST3UZIaJ 4yFUfh5lr5z8GicGWTK2RWqR1AuTI5NoCDO/3MIFtQRIs9CqfVYlJd5R5VE9yN3aDV5LEE8H9pFQ+ Qc5s2/HAJOFk14t37CQUs6NugS/tazCe7YLOjWYutc3bc0B5lUPCd9UVHae4RIqF4Yh5qO6fgYuvk x77CMLJAiIZXX1syV+J2LFPn9h123Jp36MciYk4XPld4Iw1yv8tW98J9yqS4P5cw132nwhMACl+Fc 6mfqdrrZuzFrwdR05d8kJafeFSqqFr64X7xqszDgjJrsa8RKjk0LqXDTD4PxtAL4uwDD9ICsk0vJp 4nl9BveEAwox0fzwCPcg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nG0SA-004iuM-Ei; Fri, 04 Feb 2022 15:24:50 +0000 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nG0Rq-004imn-Ra for linux-arm-kernel@lists.infradead.org; Fri, 04 Feb 2022 15:24:32 +0000 Received: by mail-pj1-x102f.google.com with SMTP id m7so5917860pjk.0 for ; Fri, 04 Feb 2022 07:24:30 -0800 (PST) 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=4/q5CQ3/q+2EJBhXdOxiiNn1t4GGrRS1OQ5Mkhf3Sec=; b=C5DCpREMlr88/fQU73s5wGn0GGcqkJJL31Xyv/kKL/IgA4KcFNddOz+ZuVlvL7O5VQ V+CqjAPPP6J5XvAoD9yi63Bq/ObHpUVSJm/2jMiFFSF0INWY/ePh4sHgUzpeLlEGbw71 bKoRSRle8ruV4QdF0bAdTRTYow4z4Yw+8cWF1MkobFg3jbs1Wb2DeUzWxx3KWX+aH48b a+Chi9XM8igLqLv6gRa8gW3bjLkB0ePtQG5CRESTLFoiQ+hxCD67L17pbzcnqsMi1KHK ghDYmPZYgqZABx6Yi6Qa4DUf6/9GpniToBuuInQnhAJsn/4J1L8FaRaQZinevEbHC5J3 684g== 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=4/q5CQ3/q+2EJBhXdOxiiNn1t4GGrRS1OQ5Mkhf3Sec=; b=bsIW1j8T40n+XK/Y/aBX1GHaLlPWQwNAdBiinXwV//ANQrPJN6yWstUXHGci5w9rtv 7oQKZKqoOH2+jRLXbp6CwC1dxtBJPkOHvBDtao9Rz3LlvtkAAw4lyMPgIUpvmU5AM+kI ymJDJrRykX8MGwAkfBSs8onwi8UaG4T0MFKYilhA2cddGSpP/DJ1In+o7EdiAzS20iDk qa4xNq2trSyXUXZmbJeLWLunWMabXzw6ghl70PE22z9kZP8U20fWOPYfXK6q5V3TNXe4 kAyxAkVFqzM+e5fjvJdF8tu0V0CGV08uJEsJrG17DG6aoAD8cbcL1vr80jn3LVTtpQJU H63g== X-Gm-Message-State: AOAM533YYtuGhfhoTQvDByTu4iVpU03+FNxH8yIoT1RhV9uFH5iJkeFW hRWYRs4l1zbBQbWGUhoHHmHLGA== X-Google-Smtp-Source: ABdhPJw6LeGmJXDi9zLXZTklPRv2RbP51RpKUOJu3zoaiPjk/3n6c0kFXnwZysSKkOOnpiLJ0OSkzA== X-Received: by 2002:a17:90b:3b52:: with SMTP id ot18mr3730813pjb.34.1643988269617; Fri, 04 Feb 2022 07:24:29 -0800 (PST) Received: from localhost.localdomain ([134.195.101.46]) by smtp.gmail.com with ESMTPSA id me4sm14237079pjb.26.2022.02.04.07.24.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Feb 2022 07:24:29 -0800 (PST) From: Leo Yan To: Mathieu Poirier , Suzuki K Poulose , Mike Leach , Alexander Shishkin , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH v2 RESEND 2/4] coresight: etm4x: Don't use virtual contextID for non-root PID namespace Date: Fri, 4 Feb 2022 23:24:01 +0800 Message-Id: <20220204152403.71775-3-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220204152403.71775-1-leo.yan@linaro.org> References: <20220204152403.71775-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-20220204_072430_918948_6B39B786 X-CRM114-Status: GOOD ( 15.76 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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. For this reason, when a process runs in non-root PID namespace, the driver doesn't allow PID 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 and 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 2f3b4eef8261..a00c0d1bbd85 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_is_in_init_pid_ns(current)) + 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_is_in_init_pid_ns(current)) + 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_is_in_init_pid_ns(current)) + 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_is_in_init_pid_ns(current)) + 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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel