From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751555AbbCTN0T (ORCPT ); Fri, 20 Mar 2015 09:26:19 -0400 Received: from mail.kernel.org ([198.145.29.136]:45387 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751498AbbCTN0S (ORCPT ); Fri, 20 Mar 2015 09:26:18 -0400 Date: Fri, 20 Mar 2015 10:26:15 -0300 From: Arnaldo Carvalho de Melo To: Jiri Olsa Cc: Milos Vyletel , Peter Zijlstra , Paul Mackerras , Ingo Molnar , Namhyung Kim , Jiri Olsa , Stephane Eranian , "open list:PERFORMANCE EVENT..." Subject: Re: [PATCH] perf: fix race in build_id_cache__add_s() Message-ID: <20150320132615.GE16485@kernel.org> References: <1426847846-11112-1-git-send-email-milos@redhat.com> <20150320121807.GB6304@krava.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150320121807.GB6304@krava.brq.redhat.com> X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Fri, Mar 20, 2015 at 01:18:07PM +0100, Jiri Olsa escreveu: > 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 > > in addition we should use some inter-perf lock > on all .debug dir operations Yeah, would be nice to have that improved. Thanks, applied. - Arnaldo