Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp239703imm; Tue, 24 Jul 2018 18:07:03 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcS2tJdkSNmMfVW2qhFAmOTr6+YSiGj32G2qFgEwSU6AIYHEb4mq0DGlhu7oBPuBWiyMlJO X-Received: by 2002:a62:5f82:: with SMTP id t124-v6mr20021605pfb.223.1532480823482; Tue, 24 Jul 2018 18:07:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532480823; cv=none; d=google.com; s=arc-20160816; b=Yin7kyiWfqmDPEfM9wp4mxZC0n0vX75nUGWs3hJTtwJVKte5l7p6sj3stSlUJZdynf VrPlHSgaurYpk0KHELgQrddT7A704DF7nv33dB3oWKzkxZRLCa+lq9mMGsGnd2aVsvXd WTd34GytgwwNiLazYW0EM+xQAVFRi9/cgVgI1j6PfyqMslqZK7scg/7G6HuabH8VGC/z UMtGX+nqqBiCR/SRrMgaB+gQqIGQhd6PEmfhm6Y+CtPAeDnU3e3mM1Smns/9ylRl2+gv +2UT8So9j/5oL1lseky3GhkpifqLNg/0f0qaEYJliEf1P2/hvpjAADFHnNX93Xb09rZn HrXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature:arc-authentication-results; bh=kkKGag1Bh2s0WSjrL9o5Z9yQa0grJvFUWpOKW/E6v2E=; b=aP2ir6fzo+RQ09EtmDWymAXKyWodCID/Gm7fVLn/RKxR+tbBcy8nttze0vnzZArMoB LwcjgOovAfCFnHIRsuWD/3TG7ZRTB4597rncSfiXVm8GAH5MHsrNB7oiaCRUW7nKxW3b vn7Nh3eN+pH5CuXF3rvxEA045kJokdh7zdbJk9X+SRVOTdJna+XQMTxGzOE4qrMAUCGr 3KwbNSOiudG8TskXs/mIJHrpNWdZXdMpnu84Wm4b0r/9SAwzIAifLTBC7Y8KK9oiOSAj O5Xe7YhvXPsiyq+Z66Bki93xzXJ/tYMm0/GiCJN4Qe3/+cnkDDU3oXs4KSA8PTXyXLMe qHLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bvAE6qXz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g27-v6si12123662pgm.208.2018.07.24.18.06.48; Tue, 24 Jul 2018 18:07:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bvAE6qXz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388541AbeGYCOb (ORCPT + 99 others); Tue, 24 Jul 2018 22:14:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:38244 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388517AbeGYCOb (ORCPT ); Tue, 24 Jul 2018 22:14:31 -0400 Received: from devbox (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 844DC20852; Wed, 25 Jul 2018 01:05:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1532480723; bh=MkutZ6Iq8zkXBC7KWbtN0iE3PYyZlTFpgq4rLA6FFUg=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=bvAE6qXzpJ2fww/h2nd5ayaya9eDN6AXXVfCYnC9dqjEbPZWPodPOnFbOcwJbqlvv BxKFycfM7aOinp6Y47x4Etj+Cg0MbG+9KXtCu8NjIOuEZADBD0Hpl4KQq7TLsZ5PaC mrNyWYp1NX7Ehe5NlfuNBfZxZhCdd5DhB85jH6ZI= Date: Wed, 25 Jul 2018 10:05:20 +0900 From: Masami Hiramatsu To: Steven Rostedt Cc: Ingo Molnar , Shuah Khan , Tom Zanussi , Hiraku Toyooka , linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH 1/3] [BUGFIX] tracing: Fix double free of event_trigger_data Message-Id: <20180725100520.9370df20d29d529236f4a368@kernel.org> In-Reply-To: <20180724164959.3cbc1422@gandalf.local.home> References: <153149923649.11274.14970833360963898112.stgit@devbox> <153149926702.11274.12489440326560729788.stgit@devbox> <20180723221006.60cc7aa9@vmware.local.home> <20180725000909.6c8b2f3881ee75c4f6bd466b@kernel.org> <20180724164959.3cbc1422@gandalf.local.home> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 24 Jul 2018 16:49:59 -0400 Steven Rostedt wrote: > On Wed, 25 Jul 2018 00:09:09 +0900 > Masami Hiramatsu wrote: > > > Hmm, your patch seems to leak a memory since event_trigger_init() will > > be called twice on same trigger_data (Note that event_trigger_init() > > does not init ref counter, but increment it.) So we should decrement > > it when we find it is succeeded. Moreover, if register_trigger() > > Good catch, and easily fixed. > > > fails before calling data->ops->init() (see -EEXIST case), the ref > > counter will be 0 (-1 +1). But if it fails after data->ops->init(), > > the ref counter will be 1 (-1 +1 +1). It still be unstable. > > (Ah, that means we may have another trouble...) > > I'm not sure there's a problem here. I now have: > > out_reg: > /* Up the trigger_data count to make sure reg doesn't free it on failuer */ > event_trigger_init(trigger_ops, trigger_data); > ret = cmd_ops->reg(glob, trigger_ops, trigger_data, file); > /* > * The above returns on success the # of functions enabled, > * but if it didn't find any functions it returns zero. > * Consider no functions a failure too. > */ > if (!ret) { > ret = -ENOENT; > } else if (ret > 0) > ret = 0; Can we mixed up ret == 0 and ret > 0? It seems cmd_ops->reg() == 0 is a failure case. > > /* Down the counter of trigger_data or free it if not used anymore */ > event_trigger_free(trigger_ops, trigger_data); > out: > return ret; > > Thus we increment trigger_data before calling reg, and free it > afterward. But if reg() did an init too, then the event_trigger_free() > just decs the ref counter. To avoid confusion, I would like to suggest to rename those pair to event_trigger_data_get/put(). :) > > As for register_trigger() > > > > > > > > > > P.S. This brings up another minor bug. The failure should return ENOMEM > > > not ENOENT. > > > > Hmm it seems we should review the register_trigger() implementation. > > It should return the return value of trace_event_trigger_enable_disable(), > > shouldn't it? > > > > Yeah, that's not done well. I'll fix it up. Thanks! > > Thanks for pointing it out. > > -- Steve -- Masami Hiramatsu