From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2DC22C433ED for ; Tue, 6 Apr 2021 17:44:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D0699613CB for ; Tue, 6 Apr 2021 17:44:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347065AbhDFRoK (ORCPT ); Tue, 6 Apr 2021 13:44:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:39512 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347042AbhDFRoJ (ORCPT ); Tue, 6 Apr 2021 13:44:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617731040; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=UCJGZ8Odc87IDddavOSngaYlHxvPBbKub9pvZ7PfgyQ=; b=VJ1c93Xug+0t5lPcNDTHffNkBK6Kll7iXofZvUaq55YdnQnp+S4Wak4WiTCdG9vT49PpeI khfYqeQhhaOJN5I4PODub4L+jZrJ3DksIeCLybYlwCR1Pha1ASjX60VSCu28MiQ6dtncZy gP5xBfrlZtbSs+FkTAKLAf7UtY8qwBE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-470-VOYV7UtdPNebkdhubNu7CQ-1; Tue, 06 Apr 2021 13:43:58 -0400 X-MC-Unique: VOYV7UtdPNebkdhubNu7CQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0B00E1922961; Tue, 6 Apr 2021 17:43:57 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.40.192.43]) by smtp.corp.redhat.com (Postfix) with SMTP id 9AAAD19D61; Tue, 6 Apr 2021 17:43:54 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Tue, 6 Apr 2021 19:43:56 +0200 (CEST) Date: Tue, 6 Apr 2021 19:43:53 +0200 From: Oleg Nesterov To: Hillf Danton , Song Liu , Peter Zijlstra Cc: Namhyung Kim , syzbot , Srikar Dronamraju , Greg KH , linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com Subject: perf_buffer.event_list is not RCU-safe? Message-ID: <20210406174352.GB13270@redhat.com> References: <00000000000030aca605be6e0102@google.com> <20210327042150.7460-1-hdanton@sina.com> <20210328025217.7312-1-hdanton@sina.com> <20210401092907.1098-1-hdanton@sina.com> <20210402074636.1270-1-hdanton@sina.com> <20210406172322.GA13270@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210406172322.GA13270@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/06, Oleg Nesterov wrote: > > perf_mmap_close() was added by 9bb5d40cd93c9 ("perf: Fix mmap() accounting hole") I meant perf_mmap_close() -> put_event() > and this commit doesn't look right anyway It seems there is another problem or I am totally confused. I do not understand why can we use list_for_each_entry_rcu(event, rb->event_list) if this can race with perf_event_set_output(event) which can move "event" to another list, in this case list_for_each_entry_rcu() can loop forever. perf_mmap_close() even mentions this race and restarts the iteration to avoid it but I don't think this is enough, rcu_read_lock(); list_for_each_entry_rcu(event, &rb->event_list, rb_entry) { if (!atomic_long_inc_not_zero(&event->refcount)) { /* * This event is en-route to free_event() which will * detach it and remove it from the list. */ continue; } just suppose that "this event" is moved to another list first and after that it goes away so that atomic_long_inc_not_zero() fails; in this case the next iteration will play with event->rb_entry.next, and this is not necessarily "struct perf_event", it can can be "list_head event_list". Don't we need rb->event_lock ? Oleg.