From: Peter Zijlstra <peterz@infradead.org>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Ingo Molnar <mingo@kernel.org>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 0/2] (Was: perf_event_mmap(vma) && !vma->vm_mm)
Date: Wed, 16 Oct 2013 22:28:22 +0200 [thread overview]
Message-ID: <20131016202822.GI2675@laptop.programming.kicks-ass.net> (raw)
In-Reply-To: <20131016200924.GA23214@redhat.com>
On Wed, Oct 16, 2013 at 10:09:24PM +0200, Oleg Nesterov wrote:
> OK, so I think this code should die, it only adds the confusion.
>
> Note also that at least on x86_64 "[vdso]" is not correct (if !vma_mm
> was possible), this adds more confusion.
Right, but x86_64 will return [vsyscall] and we'll never get there.
> > Also, the x86_32 arch_vma_name() didn't deal with the gate_vma (it still
> > doesn't appear to do so) as opposed to x86_64 which does.
>
> Hmm... I am looking into arch/x86/vdso/vdso32-setup.c, it seems it does.
> But probably I missed something, this doesn't matter.
Right, vdso32-setup.c:arch_vma_name() never checks for vma ==
get_gate_vma(). So it would return NULL for the gate vma, not a proper
name like you argue it should.
> > But the main reason I added it was because task_mmu.c:show_map_vma() did
> > so too; I just wanted to be extra careful.
>
> Yes, but this code can actually hit gate_vma. (and I'd say that if some
> arch/ has the global gate_vma-like vma's, it should implement arch_vma_name
> correctly, but this is off-topic).
I'd tend to agree with you there, but clearly this isn't/wasn't the case
and the generic code grew a fallback or so.
> ---------------------------------------------------------------------------
> Please look at these 2 simple patches. Initially I was going to send
> the 3rd patch, but I simply can't understand the "align" logic.
>
> First of all, we surely do not need __GFP_ZERO for kzalloc(PATH_MAX),
> even if we need to nullify the alignment. So I am going to send another
> patch in any case.
>
> But do we really need to nullify the extra bytes after strlen()? If yes,
> for what? If no, we can simply do s/kzalloc/kmalloc/ and kill that
> memset(tmp, 0, sizeof(tmp)) at the start.
>
> Otoh. Why do we need the temporary string buffer (char tmp[16]) at all?
> We either use the result from d_path() (which has a room), or we use a
> string literal (may be returned by arch_vma_name), in the latter case
> it is safe to assume we can read the extra 7 bytes from .data?
>
> IOW. Could you explain why the patch below (on top of 1-2) is wrong?
The perf buffer works in multiples of u64 (8 bytes), your proposed patch
gives a string shorter than size; remember:
size = ALIGN(strlen(name)+1, sizeof(u64));
And therefore the copy into the buffer will access beyond the end of
string, copying god knows what into userspace.
So yes, we could go make sure all stings are proper multiples of 8 bytes
and pad with '\0' at the end, but the zalloc + strcpy was by far the
easiest way to not get it wrong and leak crap to userspace.
next prev parent reply other threads:[~2013-10-16 20:28 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-12 19:22 perf_event_mmap(vma) && !vma->vm_mm Oleg Nesterov
2013-10-14 10:24 ` Peter Zijlstra
2013-10-16 20:09 ` [PATCH 0/2] (Was: perf_event_mmap(vma) && !vma->vm_mm) Oleg Nesterov
2013-10-16 20:09 ` [PATCH 1/2] perf: Kill the dead !vma->vm_mm code in perf_event_mmap_event() Oleg Nesterov
2013-10-29 14:08 ` [tip:perf/core] perf: Kill the dead !vma-> vm_mm " tip-bot for Oleg Nesterov
2013-10-16 20:10 ` [PATCH 2/2] perf: Do not waste PAGE_SIZE bytes for ALIGN(8) " Oleg Nesterov
2013-10-29 14:08 ` [tip:perf/core] " tip-bot for Oleg Nesterov
2013-10-16 20:28 ` Peter Zijlstra [this message]
2013-10-16 20:43 ` [PATCH 0/2] (Was: perf_event_mmap(vma) && !vma->vm_mm) Oleg Nesterov
2013-10-16 20:55 ` Peter Zijlstra
2013-10-16 20:55 ` Oleg Nesterov
2013-10-16 20:58 ` Peter Zijlstra
2013-10-16 20:58 ` Oleg Nesterov
2013-10-16 21:16 ` Peter Zijlstra
2013-10-17 15:20 ` Oleg Nesterov
2013-10-17 15:27 ` Oleg Nesterov
2013-10-17 16:47 ` Peter Zijlstra
2013-10-17 18:24 ` Oleg Nesterov
2013-10-17 21:32 ` Peter Zijlstra
2013-11-06 13:19 ` [tip:perf/core] perf: Factor out strncpy() in perf_event_mmap_event() tip-bot for Oleg Nesterov
2013-10-17 16:38 ` [PATCH 0/2] (Was: perf_event_mmap(vma) && !vma->vm_mm) Peter Zijlstra
2013-10-17 15:22 ` [PATCH 3/2] perf: Optimize the fill/align code in perf_event_mmap_event() Oleg Nesterov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20131016202822.GI2675@laptop.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=oleg@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox