forked from Minki/linux
perf: Change zero-padding of strings in perf_event_mmap_event()
Oleg complained about the excessive 0-ing in perf_event_mmap_event(), so try and be smarter about it while keeping it fairly fool proof and avoid leaking random bits out to userspace. Suggested-by: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/n/tip-8jirlm99m6if2z13wd6rbyu6@git.kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
This commit is contained in:
parent
3ea2f2b96f
commit
2c42cfbfe1
@ -5106,15 +5106,13 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
|
|||||||
unsigned int size;
|
unsigned int size;
|
||||||
char tmp[16];
|
char tmp[16];
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
const char *name;
|
char *name;
|
||||||
|
|
||||||
memset(tmp, 0, sizeof(tmp));
|
|
||||||
|
|
||||||
if (file) {
|
if (file) {
|
||||||
struct inode *inode;
|
struct inode *inode;
|
||||||
dev_t dev;
|
dev_t dev;
|
||||||
|
|
||||||
buf = kzalloc(PATH_MAX, GFP_KERNEL);
|
buf = kmalloc(PATH_MAX, GFP_KERNEL);
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
name = strncpy(tmp, "//enomem", sizeof(tmp));
|
name = strncpy(tmp, "//enomem", sizeof(tmp));
|
||||||
goto got_name;
|
goto got_name;
|
||||||
@ -5137,7 +5135,7 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
|
|||||||
min = MINOR(dev);
|
min = MINOR(dev);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
name = arch_vma_name(vma);
|
name = (char *)arch_vma_name(vma);
|
||||||
if (name) {
|
if (name) {
|
||||||
name = strncpy(tmp, name, sizeof(tmp) - 1);
|
name = strncpy(tmp, name, sizeof(tmp) - 1);
|
||||||
tmp[sizeof(tmp) - 1] = '\0';
|
tmp[sizeof(tmp) - 1] = '\0';
|
||||||
@ -5160,7 +5158,14 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
got_name:
|
got_name:
|
||||||
size = ALIGN(strlen(name)+1, sizeof(u64));
|
/*
|
||||||
|
* Since our buffer works in 8 byte units we need to align our string
|
||||||
|
* size to a multiple of 8. However, we must guarantee the tail end is
|
||||||
|
* zero'd out to avoid leaking random bits to userspace.
|
||||||
|
*/
|
||||||
|
size = strlen(name)+1;
|
||||||
|
while (!IS_ALIGNED(size, sizeof(u64)))
|
||||||
|
name[size++] = '\0';
|
||||||
|
|
||||||
mmap_event->file_name = name;
|
mmap_event->file_name = name;
|
||||||
mmap_event->file_size = size;
|
mmap_event->file_size = size;
|
||||||
|
Loading…
Reference in New Issue
Block a user