summaryrefslogtreecommitdiffstats
path: root/drivers/hwtracing
diff options
context:
space:
mode:
authorMathieu Poirier <mathieu.poirier@linaro.org>2018-07-11 15:40:11 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-07-15 07:52:56 -0400
commit7bd50ccf001f77db236af51797579359b09e2354 (patch)
tree170431f9c6a9f5672e8fe9f4d642931ff637021f /drivers/hwtracing
parent5151e2b578e92f88d676ad78d36a2ef93d0a0dea (diff)
coresight: etm3x: Don't use contextID with PID namespaces
Tracers can trigger trace acquisition based on contextID value, something that isn't useful when PID namespaces are enabled. Indeed the PID value of a process has a different representation in the kernel and the PID namespace, making the feature confusing and potentially leaking internal kernel information. As such simply return an error when the feature is being used from a PID namespace other than the default one. Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org> Reviewed-by: Kim Phillips <kim.phillips@arm.com> Acked-by: "Eric W. Biederman" <ebiederm@xmission.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/hwtracing')
-rw-r--r--drivers/hwtracing/coresight/coresight-etm.h3
-rw-r--r--drivers/hwtracing/coresight/coresight-etm3x-sysfs.c43
-rw-r--r--drivers/hwtracing/coresight/coresight-etm3x.c4
3 files changed, 38 insertions, 12 deletions
diff --git a/drivers/hwtracing/coresight/coresight-etm.h b/drivers/hwtracing/coresight/coresight-etm.h
index e8b4549e30e2..79e1ad860d8a 100644
--- a/drivers/hwtracing/coresight/coresight-etm.h
+++ b/drivers/hwtracing/coresight/coresight-etm.h
@@ -168,8 +168,6 @@
168 * @seq_curr_state: current value of the sequencer register. 168 * @seq_curr_state: current value of the sequencer register.
169 * @ctxid_idx: index for the context ID registers. 169 * @ctxid_idx: index for the context ID registers.
170 * @ctxid_pid: value for the context ID to trigger on. 170 * @ctxid_pid: value for the context ID to trigger on.
171 * @ctxid_vpid: Virtual PID seen by users if PID namespace is enabled, otherwise
172 * the same value of ctxid_pid.
173 * @ctxid_mask: mask applicable to all the context IDs. 171 * @ctxid_mask: mask applicable to all the context IDs.
174 * @sync_freq: Synchronisation frequency. 172 * @sync_freq: Synchronisation frequency.
175 * @timestamp_event: Defines an event that requests the insertion 173 * @timestamp_event: Defines an event that requests the insertion
@@ -202,7 +200,6 @@ struct etm_config {
202 u32 seq_curr_state; 200 u32 seq_curr_state;
203 u8 ctxid_idx; 201 u8 ctxid_idx;
204 u32 ctxid_pid[ETM_MAX_CTXID_CMP]; 202 u32 ctxid_pid[ETM_MAX_CTXID_CMP];
205 u32 ctxid_vpid[ETM_MAX_CTXID_CMP];
206 u32 ctxid_mask; 203 u32 ctxid_mask;
207 u32 sync_freq; 204 u32 sync_freq;
208 u32 timestamp_event; 205 u32 timestamp_event;
diff --git a/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c b/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c
index 9435c1481f61..75487b3fad86 100644
--- a/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c
+++ b/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c
@@ -4,6 +4,7 @@
4 * Author: Mathieu Poirier <mathieu.poirier@linaro.org> 4 * Author: Mathieu Poirier <mathieu.poirier@linaro.org>
5 */ 5 */
6 6
7#include <linux/pid_namespace.h>
7#include <linux/pm_runtime.h> 8#include <linux/pm_runtime.h>
8#include <linux/sysfs.h> 9#include <linux/sysfs.h>
9#include "coresight-etm.h" 10#include "coresight-etm.h"
@@ -1025,8 +1026,15 @@ static ssize_t ctxid_pid_show(struct device *dev,
1025 struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); 1026 struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
1026 struct etm_config *config = &drvdata->config; 1027 struct etm_config *config = &drvdata->config;
1027 1028
1029 /*
1030 * Don't use contextID tracing if coming from a PID namespace. See
1031 * comment in ctxid_pid_store().
1032 */
1033 if (task_active_pid_ns(current) != &init_pid_ns)
1034 return -EINVAL;
1035
1028 spin_lock(&drvdata->spinlock); 1036 spin_lock(&drvdata->spinlock);
1029 val = config->ctxid_vpid[config->ctxid_idx]; 1037 val = config->ctxid_pid[config->ctxid_idx];
1030 spin_unlock(&drvdata->spinlock); 1038 spin_unlock(&drvdata->spinlock);
1031 1039
1032 return sprintf(buf, "%#lx\n", val); 1040 return sprintf(buf, "%#lx\n", val);
@@ -1037,19 +1045,28 @@ static ssize_t ctxid_pid_store(struct device *dev,
1037 const char *buf, size_t size) 1045 const char *buf, size_t size)
1038{ 1046{
1039 int ret; 1047 int ret;
1040 unsigned long vpid, pid; 1048 unsigned long pid;
1041 struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); 1049 struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
1042 struct etm_config *config = &drvdata->config; 1050 struct etm_config *config = &drvdata->config;
1043 1051
1044 ret = kstrtoul(buf, 16, &vpid); 1052 /*
1053 * When contextID tracing is enabled the tracers will insert the
1054 * value found in the contextID register in the trace stream. But if
1055 * a process is in a namespace the PID of that process as seen from the
1056 * namespace won't be what the kernel sees, something that makes the
1057 * feature confusing and can potentially leak kernel only information.
1058 * As such refuse to use the feature if @current is not in the initial
1059 * PID namespace.
1060 */
1061 if (task_active_pid_ns(current) != &init_pid_ns)
1062 return -EINVAL;
1063
1064 ret = kstrtoul(buf, 16, &pid);
1045 if (ret) 1065 if (ret)
1046 return ret; 1066 return ret;
1047 1067
1048 pid = coresight_vpid_to_pid(vpid);
1049
1050 spin_lock(&drvdata->spinlock); 1068 spin_lock(&drvdata->spinlock);
1051 config->ctxid_pid[config->ctxid_idx] = pid; 1069 config->ctxid_pid[config->ctxid_idx] = pid;
1052 config->ctxid_vpid[config->ctxid_idx] = vpid;
1053 spin_unlock(&drvdata->spinlock); 1070 spin_unlock(&drvdata->spinlock);
1054 1071
1055 return size; 1072 return size;
@@ -1063,6 +1080,13 @@ static ssize_t ctxid_mask_show(struct device *dev,
1063 struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); 1080 struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
1064 struct etm_config *config = &drvdata->config; 1081 struct etm_config *config = &drvdata->config;
1065 1082
1083 /*
1084 * Don't use contextID tracing if coming from a PID namespace. See
1085 * comment in ctxid_pid_store().
1086 */
1087 if (task_active_pid_ns(current) != &init_pid_ns)
1088 return -EINVAL;
1089
1066 val = config->ctxid_mask; 1090 val = config->ctxid_mask;
1067 return sprintf(buf, "%#lx\n", val); 1091 return sprintf(buf, "%#lx\n", val);
1068} 1092}
@@ -1076,6 +1100,13 @@ static ssize_t ctxid_mask_store(struct device *dev,
1076 struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); 1100 struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
1077 struct etm_config *config = &drvdata->config; 1101 struct etm_config *config = &drvdata->config;
1078 1102
1103 /*
1104 * Don't use contextID tracing if coming from a PID namespace. See
1105 * comment in ctxid_pid_store().
1106 */
1107 if (task_active_pid_ns(current) != &init_pid_ns)
1108 return -EINVAL;
1109
1079 ret = kstrtoul(buf, 16, &val); 1110 ret = kstrtoul(buf, 16, &val);
1080 if (ret) 1111 if (ret)
1081 return ret; 1112 return ret;
diff --git a/drivers/hwtracing/coresight/coresight-etm3x.c b/drivers/hwtracing/coresight/coresight-etm3x.c
index 15ed64d51a5b..7c74263c333d 100644
--- a/drivers/hwtracing/coresight/coresight-etm3x.c
+++ b/drivers/hwtracing/coresight/coresight-etm3x.c
@@ -230,10 +230,8 @@ void etm_set_default(struct etm_config *config)
230 230
231 config->seq_curr_state = 0x0; 231 config->seq_curr_state = 0x0;
232 config->ctxid_idx = 0x0; 232 config->ctxid_idx = 0x0;
233 for (i = 0; i < ETM_MAX_CTXID_CMP; i++) { 233 for (i = 0; i < ETM_MAX_CTXID_CMP; i++)
234 config->ctxid_pid[i] = 0x0; 234 config->ctxid_pid[i] = 0x0;
235 config->ctxid_vpid[i] = 0x0;
236 }
237 235
238 config->ctxid_mask = 0x0; 236 config->ctxid_mask = 0x0;
239 /* Setting default to 1024 as per TRM recommendation */ 237 /* Setting default to 1024 as per TRM recommendation */