perf/x86/intel/pt: Address filtering fixes for perf/urgent
Subsystems (3)
Alexander Shishkin
reviewerPATCH 1/3 perf/x86/intel/pt: Fix an off-by-one in address filter configuration
In reply to Alexander ShishkinPT address filter configuration requires that a range is specified by its first and last address, but at the moment we're obtaining the end of the range by adding user specified size to its start, which is off by one from what it actually needs to be.
Fix this and make sure that zero-sized filters don't pass the filter validation.
--- arch/x86/events/intel/pt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/events/intel/pt.c +2 -2
@@ -1081,7 +1081,7 @@ static int pt_event_addr_filters_validate(struct list_head *filters)list_for_each_entry (filter, filters, entry) {/* PT doesn't support single address triggers */ -if (!filter->range) +if (!filter->range || !filter->size)return -EOPNOTSUPP ;if (!filter->inode && !kernel_ip (filter->offset))
@@ -1111,7 +1111,7 @@ static void pt_event_addr_filters_sync(struct perf_event *event) }else {/* apply the offset */ msr_a = filter->offset + offs[range]; - msr_b = filter->size + msr_a; + msr_b = filter->size + msr_a -1 ; } filters->filter[range].msr_a = msr_a;
Signature · 1 line
2.9.3
Alexander Shishkin
reviewerPATCH 2/3 perf/x86/intel/pt: Fix kernel address filter's offset validation
In reply to Alexander ShishkinThe kernel_ip() filter is used mostly by the DS/LBR code to look at the branch addresses, but Intel PT also uses it to validate the address filter offsets for kernel addresses, for which it is not sufficient:
supplying something in bits 64:48 that's not a sign extension of the lower address bits (like 0xf00d000000000000) throws a #GP.
This patch adds address validation for the user supplied kernel filters.
--- arch/x86/events/intel/pt.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
arch/x86/events/intel/pt.c +6 -1
@@ -1074,6 +1074,11 @@ static void pt_addr_filters_fini(struct perf_event *event) event->hw.addr_filters =NULL ; } +static inline bool valid_kernel_ip (unsigned long ip) +{ +return virt_addr_valid (ip) &&kernel_ip (ip); +} +static int pt_event_addr_filters_validate (struct list_head *filters) {struct perf_addr_filter *filter;
@@ -1084,7 +1089,7 @@ static int pt_event_addr_filters_validate(struct list_head *filters)if (!filter->range || !filter->size)return -EOPNOTSUPP ; -if (!filter->inode && !kernel_ip (filter->offset)) +if (!filter->inode && !valid_kernel_ip (filter->offset))return -EINVAL ;if (++range >pt_cap_get (PT_CAP_num_address_ranges))
Signature · 1 line
2.9.3
Alexander Shishkin
reviewerPATCH 3/3 perf/x86/intel/pt: Do validate the size of a kernel address filter
In reply to Alexander ShishkinRight now, the kernel address filters in PT are prone to integer overflow that may happen in adding filter's size to its offset to obtain the end of the range. Such an overflow would also throw a #GP in the PT event configuration path.
Fix this by explicitly validating the result of this calculation.
--- arch/x86/events/intel/pt.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
arch/x86/events/intel/pt.c +7 -2
@@ -1089,8 +1089,13 @@ static int pt_event_addr_filters_validate(struct list_head *filters)if (!filter->range || !filter->size)return -EOPNOTSUPP ; -if (!filter->inode && !valid_kernel_ip (filter->offset)) -return -EINVAL ; +if (!filter->inode) { +if (!valid_kernel_ip (filter->offset)) +return -EINVAL ; + +if (!valid_kernel_ip (filter->offset + filter->size)) +return -EINVAL ; + }if (++range >pt_cap_get (PT_CAP_num_address_ranges))return -EOPNOTSUPP ;
Signature · 1 line
2.9.3
Alexander Shishkin
reviewercover perf/x86/intel/pt: Address filtering fixes for perf/urgent
Hi again,
Apologies for the botched recipient list in the previous one. So I moved the virt_addr_valid() inside pt.c as well to save cycles in the LBR code.
These are 3 bugs that Adrian found; all 3 seem like good -stable candidates.
Alexander Shishkin (3):
perf/x86/intel/pt: Fix an off-by-one in address filter configuration perf/x86/intel/pt: Fix kernel address filter's offset validation perf/x86/intel/pt: Do validate the size of a kernel address filter
arch/x86/events/intel/pt.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
Signature · 1 line
2.9.3
tip-bot for Alexander Shishkin
merge bot[tip:perf/urgent] perf/x86/intel/pt: Fix an off-by-one in address filter configuration
In reply to Alexander Shishkinperf/x86/intel/pt: Fix an off-by-one in address filter configuration
Commit-ID: 95f60084acbcee6c466256cf26eb52191fad9edc Gitweb: http://git.kernel.org/tip/95f60084acbcee6c466256cf26eb52191fad9edc Author: Alexander Shishkin <[email protected]> AuthorDate: Thu, 15 Sep 2016 18:13:50 +0300 Committer: Ingo Molnar <[email protected]> CommitDate: Fri, 16 Sep 2016 11:14:16 +0200
perf/x86/intel/pt: Fix an off-by-one in address filter configuration
PT address filter configuration requires that a range is specified by its first and last address, but at the moment we're obtaining the end of the range by adding user specified size to its start, which is off by one from what it actually needs to be.
Fix this and make sure that zero-sized filters don't pass the filter validation.
--- arch/x86/events/intel/pt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/events/intel/pt.c +2 -2
@@ -1081,7 +1081,7 @@ static int pt_event_addr_filters_validate(struct list_head *filters)list_for_each_entry (filter, filters, entry) {/* PT doesn't support single address triggers */ -if (!filter->range) +if (!filter->range || !filter->size)return -EOPNOTSUPP ;if (!filter->inode && !kernel_ip (filter->offset))
@@ -1111,7 +1111,7 @@ static void pt_event_addr_filters_sync(struct perf_event *event) }else {/* apply the offset */ msr_a = filter->offset + offs[range]; - msr_b = filter->size + msr_a; + msr_b = filter->size + msr_a -1 ; } filters->filter[range].msr_a = msr_a;
tip-bot for Alexander Shishkin
merge bot[tip:perf/urgent] perf/x86/intel/pt: Fix kernel address filter's offset validation
In reply to Alexander Shishkinperf/x86/intel/pt: Fix kernel address filter's offset validation
Commit-ID: ddfdad991e55b65c1cc4ee29502f6dceee04455a Gitweb: http://git.kernel.org/tip/ddfdad991e55b65c1cc4ee29502f6dceee04455a Author: Alexander Shishkin <[email protected]> AuthorDate: Thu, 15 Sep 2016 18:13:51 +0300 Committer: Ingo Molnar <[email protected]> CommitDate: Fri, 16 Sep 2016 11:14:16 +0200
perf/x86/intel/pt: Fix kernel address filter's offset validation
The kernel_ip() filter is used mostly by the DS/LBR code to look at the branch addresses, but Intel PT also uses it to validate the address filter offsets for kernel addresses, for which it is not sufficient:
supplying something in bits 64:48 that's not a sign extension of the lower address bits (like 0xf00d000000000000) throws a #GP.
This patch adds address validation for the user supplied kernel filters.
--- arch/x86/events/intel/pt.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
arch/x86/events/intel/pt.c +6 -1
@@ -1074,6 +1074,11 @@ static void pt_addr_filters_fini(struct perf_event *event) event->hw.addr_filters =NULL ; } +static inline bool valid_kernel_ip (unsigned long ip) +{ +return virt_addr_valid (ip) &&kernel_ip (ip); +} +static int pt_event_addr_filters_validate (struct list_head *filters) {struct perf_addr_filter *filter;
@@ -1084,7 +1089,7 @@ static int pt_event_addr_filters_validate(struct list_head *filters)if (!filter->range || !filter->size)return -EOPNOTSUPP ; -if (!filter->inode && !kernel_ip (filter->offset)) +if (!filter->inode && !valid_kernel_ip (filter->offset))return -EINVAL ;if (++range >pt_cap_get (PT_CAP_num_address_ranges))
tip-bot for Alexander Shishkin
merge bot[tip:perf/urgent] perf/x86/intel/pt: Do validate the size of a kernel address filter
In reply to Alexander Shishkinperf/x86/intel/pt: Do validate the size of a kernel address filter
Commit-ID: 1155bafcb79208abc6ae234c6e135ac70607755c Gitweb: http://git.kernel.org/tip/1155bafcb79208abc6ae234c6e135ac70607755c Author: Alexander Shishkin <[email protected]> AuthorDate: Thu, 15 Sep 2016 18:13:52 +0300 Committer: Ingo Molnar <[email protected]> CommitDate: Fri, 16 Sep 2016 11:14:16 +0200
perf/x86/intel/pt: Do validate the size of a kernel address filter
Right now, the kernel address filters in PT are prone to integer overflow that may happen in adding filter's size to its offset to obtain the end of the range. Such an overflow would also throw a #GP in the PT event configuration path.
Fix this by explicitly validating the result of this calculation.
--- arch/x86/events/intel/pt.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
arch/x86/events/intel/pt.c +7 -2
@@ -1089,8 +1089,13 @@ static int pt_event_addr_filters_validate(struct list_head *filters)if (!filter->range || !filter->size)return -EOPNOTSUPP ; -if (!filter->inode && !valid_kernel_ip (filter->offset)) -return -EINVAL ; +if (!filter->inode) { +if (!valid_kernel_ip (filter->offset)) +return -EINVAL ; + +if (!valid_kernel_ip (filter->offset + filter->size)) +return -EINVAL ; + }if (++range >pt_cap_get (PT_CAP_num_address_ranges))return -EOPNOTSUPP ;