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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34D3CC433EF for ; Thu, 4 Nov 2021 15:09:35 +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 EE6F461221 for ; Thu, 4 Nov 2021 15:09:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org EE6F461221 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com 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-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:To:Subject:Reply-To:Cc:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=2lKDPAm74VJlQRoTZF7BGKkeH5rBj0g3qKzYZJekh4w=; b=VZL/6Ti8T3WqM7/8Fjykui3ExD e8EduS4LgQIWRE+sQMKUqWqEbmrmV39mNQBNHXYXXVxM87bXKqqH124lZCmqSef7aqHfYQb8fMVle 7gwA2wYqlT1UNPba29s0y5be14FJDtbDXgro4lIlBVCckX6tKGOysXs6lY67f+6dmpFEIKeFAqRAW k02buAWTo5uU0DgMxp6rWuQS1hCZCW/++RYzBrC0sEOcRoL3iPPTxDEQVkB1/+ar2FJIM08FyUx8J x91Lc5IXkIV4iwqKgzvlaBGxmp9vB9ZicxQw8v6ZtIwc+xOFbTowKNzN99WPzpqnEigF8YyGye1ji vc13ZR/g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mieLR-009Cm8-NY; Thu, 04 Nov 2021 15:08:01 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mieLN-009Ck2-3H for linux-arm-kernel@lists.infradead.org; Thu, 04 Nov 2021 15:07:58 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7870C1FB; Thu, 4 Nov 2021 08:07:48 -0700 (PDT) Received: from [10.57.45.134] (unknown [10.57.45.134]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 30D773F7D7; Thu, 4 Nov 2021 08:07:47 -0700 (PDT) Subject: Re: [PATCH v1 2/4] coresight: etm4x: Don't use virtual contextID for non-root PID namespace To: Leo Yan , Mathieu Poirier , Mike Leach , Alexander Shishkin , James Clark , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <20211031144214.237879-1-leo.yan@linaro.org> <20211031144214.237879-3-leo.yan@linaro.org> From: Suzuki K Poulose Message-ID: <2cd79645-2f1f-1e59-1a26-5540aa7b6f3b@arm.com> Date: Thu, 4 Nov 2021 15:07:45 +0000 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <20211031144214.237879-3-leo.yan@linaro.org> Content-Language: en-GB X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211104_080757_226390_2B66B4B9 X-CRM114-Status: GOOD ( 24.57 ) 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-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Leo On 31/10/2021 14:42, Leo Yan wrote: > 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 Patch looks good to me. Please see minor comment below. > --- > .../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) Please could we add a helper function to make this obvious ? e.g: task_is_in_root_ns(task) ? Suzuki _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel