perf/urgent fixes:

- Fix kptr_restrict=2 related 'perf record' segfault (Wang Nan)
 
 - Fix CTF/libbabeltrace handling of chinese COMM strings (Wang Nan)
 
 Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2
 
 iQIcBAABCAAGBQJXSGeIAAoJENZQFvNTUqpAIbQP+wQcafPq7iEqscB4FtU2uKm4
 7HruIHRVH9dSJI3SoW46J1klnyzLlABzEQC0QJEZREtwgrbk+2Te+vj5xEaaJqsp
 V0pM9UobsLnmNxV5oQWKj1F+fuez5iis06iHB9QCC8tYb/8U31E6ZS60H3Z5aVFY
 HRb5rvqTAoFgJDfrslwahAeCl3IHRd7XEddPRGQi6FvbhItPczFUYwka6ugdDksk
 vYhn5a7xote2fMONhh78z/ajGXBj7oBx8qWUwqFi5a1XX1D6cKthme3ha+jErfVq
 XY4Gwz4/7YNifRGxxnCc10BDEcp69MvpF84oH2sfpj1dOoF87ItPFMIFgO2eKt9j
 iTs1tmC4IFzCQYjQuVp02GFrjHmM54AnvJ+e7a6647PII5M56em0FUCeSLIAQy4E
 h/kDkdwCxNpB4+i7pX+9CrTKmx+Wfb3YeL97LV7kSg/ESq11ds1mgpZfhVaQG1o4
 r5dC6yjfamiQM3QeHsRV1c5u1niTo67+daPHx409F/iR+gS0ZIMgX7/jW7apJLNx
 TVx3so9nOqnct2cddM24AfbPnmcWmWQBoA+Gp5uQQ8XbnfzS76NGBYOdsx1CYxbx
 1ZM4/nVLagHf8Ptcyyzm3xOCOz/naEe7zOj2WaRfLB5fgCKP0Mm2TpINsaWIJH2v
 Jg5Y7e4mx3q+1Bv3o3Hd
 =ANqh
 -----END PGP SIGNATURE-----

Merge tag 'perf-urgent-for-mingo-20160527' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/urgent

Pull perf/urgent fixes from Arnaldo Carvalho de Melo:

 - Fix kptr_restrict=2 related 'perf record' segfault (Wang Nan)

 - Fix CTF/libbabeltrace handling of chinese COMM strings (Wang Nan)

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
This commit is contained in:
Ingo Molnar 2016-05-29 20:15:37 +02:00
commit 711460514b
3 changed files with 49 additions and 10 deletions

View File

@ -204,6 +204,44 @@ static unsigned long long adjust_signedness(unsigned long long value_int, int si
return (value_int & value_mask) | ~value_mask;
}
static int string_set_value(struct bt_ctf_field *field, const char *string)
{
char *buffer = NULL;
size_t len = strlen(string), i, p;
int err;
for (i = p = 0; i < len; i++, p++) {
if (isprint(string[i])) {
if (!buffer)
continue;
buffer[p] = string[i];
} else {
char numstr[5];
snprintf(numstr, sizeof(numstr), "\\x%02x",
(unsigned int)(string[i]) & 0xff);
if (!buffer) {
buffer = zalloc(i + (len - i) * 4 + 2);
if (!buffer) {
pr_err("failed to set unprintable string '%s'\n", string);
return bt_ctf_field_string_set_value(field, "UNPRINTABLE-STRING");
}
if (i > 0)
strncpy(buffer, string, i);
}
strncat(buffer + p, numstr, 4);
p += 3;
}
}
if (!buffer)
return bt_ctf_field_string_set_value(field, string);
err = bt_ctf_field_string_set_value(field, buffer);
free(buffer);
return err;
}
static int add_tracepoint_field_value(struct ctf_writer *cw,
struct bt_ctf_event_class *event_class,
struct bt_ctf_event *event,
@ -270,8 +308,7 @@ static int add_tracepoint_field_value(struct ctf_writer *cw,
}
if (flags & FIELD_IS_STRING)
ret = bt_ctf_field_string_set_value(field,
data + offset + i * len);
ret = string_set_value(field, data + offset + i * len);
else {
unsigned long long value_int;

View File

@ -673,6 +673,8 @@ int perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
int err;
union perf_event *event;
if (symbol_conf.kptr_restrict)
return -1;
if (map == NULL)
return -1;

View File

@ -1933,17 +1933,17 @@ int setup_intlist(struct intlist **list, const char *list_str,
static bool symbol__read_kptr_restrict(void)
{
bool value = false;
FILE *fp = fopen("/proc/sys/kernel/kptr_restrict", "r");
if (geteuid() != 0) {
FILE *fp = fopen("/proc/sys/kernel/kptr_restrict", "r");
if (fp != NULL) {
char line[8];
if (fp != NULL) {
char line[8];
if (fgets(line, sizeof(line), fp) != NULL)
value = atoi(line) != 0;
if (fgets(line, sizeof(line), fp) != NULL)
value = (geteuid() != 0) ?
(atoi(line) != 0) :
(atoi(line) == 2);
fclose(fp);
}
fclose(fp);
}
return value;