lkml.org 
[lkml]   [2015]   [Mar]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] perf: fix race in build_id_cache__add_s()
On Fri, Mar 20, 2015 at 11:37:25AM +0100, Milos Vyletel wrote:
> int build_id_cache__add_s(const char *sbuild_id, const char *debugdir,
> const char *name, bool is_kallsyms, bool is_vdso)
> {
> ...
> if (access(filename, F_OK)) {
> ^--------------------------------------------------------- [1]
> if (is_kallsyms) {
> if (copyfile("/proc/kallsyms", filename))
> goto out_free;
> } else if (link(realname, filename) && copyfile(name, filename))
> ^-----------------------------^------------- [2]
> \------------ [3]
> goto out_free;
> }
> ...
>
> when multiple instances of perf record get to [1] at more or less same time and
> run access() one or more may get failure because the file does not exist yet
> (since the first instance did not have chance to link it yet). at this point the
> race moves to link() at [2] where first thread to get there links file and goes
> on but second one gets -EEXIST so it runs copyfile [3] which truncates the file.

nice.. :-\

Acked-by: Jiri Olsa <jolsa@kernel.org>

in addition we should use some inter-perf lock
on all .debug dir operations

jirka


\
 
 \ /
  Last update: 2015-03-20 13:41    [W:0.056 / U:0.784 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site