Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp301611imm; Tue, 24 Jul 2018 19:43:57 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfkNmVh3GDXNMEq5xqELF8dKigbbs5MaDX0CnG3Who/uNHMXRWu2ehtDP4guq/zp766c1nl X-Received: by 2002:a65:41c6:: with SMTP id b6-v6mr18333456pgq.174.1532486636979; Tue, 24 Jul 2018 19:43:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532486636; cv=none; d=google.com; s=arc-20160816; b=Gr/KO9eBscQGByl4pirdTvQo8adBuCtdZTKHe3EueR82mTvoF2amnCyeBdc3pUpKwB 5sYaTaipmxpCaWcZcT6660Aqch0rYuOGLfxUldIkTXBKJOQDJg96MECR7UvNFTWkW45d A9oyw/Zsol/l6+sUj/4QHm67+cTi+82iExJMdPENAGuQKY7N0Hof3AzaEDuaKVDymNs3 402mL+nddcIvWJM5avau8a9Jg6221reUy5PH1kK1+bfOCdZtcaAO7Ct2eiR3offas8oG uV2paTdpgOy1sh44S1FODnx9J76QXA0YqWsNDT3VL5w5NMN/224wE0adkiC+ajQ7MC9J nEjw== 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 :arc-authentication-results; bh=AAz3OL3RoBVMiJ6qhwuj14yH2RA4pmgriBlZxYdQasc=; b=IIeTYfhzzy3ikVHVKbVOSJcsaFU1kFUx366QlTS0PjJ0paS9pv7yM7g+qSLLYeC1Y6 ngUtGsEhxyu/Df2Mk2Hltpx7nbtCp6rWvKYWNsx85Yrul+oQwcs9VnNoaRCtPFMcwDX7 HRjONlYF2Ub9THxHxYYjjBlrVwxg8kvSxr3AwWDmZiDx4cq1cLEIHKyxi0oLc57fROJS o7ZIgblUFJL8ATZkh6WBKeLpkqxAM95u5xMr3YF/JA2ZpdT+axDoGjVrmv3HR2Ntagub 5FhA0FqYag6g3Bn4QgwfJuw2dXmL3MG1ZTQ/gPKXrrGZz0ahbdsu4n9onXcEMj+OfWfE wchQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j11-v6si6877788pll.234.2018.07.24.19.43.41; Tue, 24 Jul 2018 19:43:56 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388523AbeGYDvU (ORCPT + 99 others); Tue, 24 Jul 2018 23:51:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:52356 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388464AbeGYDvU (ORCPT ); Tue, 24 Jul 2018 23:51:20 -0400 Received: from gandalf.local.home (cpe-66-24-56-78.stny.res.rr.com [66.24.56.78]) (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 BFA6920856; Wed, 25 Jul 2018 02:41:51 +0000 (UTC) Date: Tue, 24 Jul 2018 22:41:49 -0400 From: Steven Rostedt To: Masami Hiramatsu Cc: Tom Zanussi , Ingo Molnar , Shuah Khan , 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: <20180724224149.0767fd13@gandalf.local.home> In-Reply-To: <20180725101653.09e095092a4bb77e6fc558df@kernel.org> 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> <20180724173008.454cdf10@gandalf.local.home> <20180724191331.738eb819@gandalf.local.home> <20180725101653.09e095092a4bb77e6fc558df@kernel.org> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-pc-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 Wed, 25 Jul 2018 10:16:53 +0900 Masami Hiramatsu wrote: > Hm, as far as I can see, when register_trigger() returns >= 0, it already > calls ->init the trigger_data. This means its refcount++, and in that > case, below patch will miss to free the trigger_data. > How about below for tentative fix? > > if (!ret) { > ret = -ENOENT; > /* We have to forcibly free the trigger_data */ > goto out_free; > } else if (ret > 0) > ret = 0; Or better yet, match it properly: out_reg: /* Up the trigger_data count to make sure reg doesn't free it on failure */ 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) { cmd_ops->unreg(glob, trigger_ops, trigger_data, file); ret = -ENOENT; } else if (ret > 0) ret = 0; /* Down the counter of trigger_data or free it if not used anymore */ event_trigger_free(trigger_ops, trigger_data); out: return ret; -- Steve