Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1163547imm; Wed, 1 Aug 2018 11:13:59 -0700 (PDT) X-Google-Smtp-Source: AAOMgpefJrhQm3Jeevh4zdoDEDUe0Hp+Na+6w2mVAbUS41bYWNQFW/7Zkao6mY/ESllsTC2LNabf X-Received: by 2002:a62:3cd7:: with SMTP id b84-v6mr28016832pfk.183.1533147239719; Wed, 01 Aug 2018 11:13:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533147239; cv=none; d=google.com; s=arc-20160816; b=IfI+9q8QU2fYDUN/kVmkEtv9S5rEkLSNyRRY0t7K6QGuNjZEfiwPYRJpqKfH64tNcu phOgAN5iUa1nkah1kHwmmMps0jBpCsCkRwTAZiCLwYIp5uTcqcD2tZeUy0s32EBzinBc DEAs408QGxjYZM0MUKcHGaRwyFwi2CCAWLWGmzXERqKPXcgnOaR4AIzXLDK4EUJe27xP 7ctYVQfcR8iIh2bCIlFAs4Lk2lD+1WbaMFr1AqOQU2vPLPpvu4InYr5Kjvn2ZNhDMQgF y6QhlGE04XosAT2oN2RYlSdfqfK5Aui5dFwff1rO2pFR+rvTjd3hn3Ig3Diyo/TGavwH h1Mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=9mDgK8B2DPxJigqKTNsYfUiM/WrAxgFjQtYxPLnF9+k=; b=nc4dukvIAmQi9MwwISWz9VbIUUzUQjwCm4H4vhW+w2Tmiz5W3lhBjslxyTGON2RQVp +UC2e7kIWQz41Tl9RhO4dRjQy9zlG6/0xLqRqfN5RIffBCc4GUJjkp+n3iaAaJp4QApQ tbrI/mM+MBYZZNBzOfBmzbukCZEGcYevujY/JA6pOfkvX51vSt3QchDu9e7JyUB9b5Uh tYWKb0KOVQRwcE8VEdI7T9ckgBTpEBOPej7ZGCfp8MEsjll2rK6QRfdaspFsTjpLJuAW 1mKkrDpPQVe0+xsEYOXRMBql4zu8L7DQOTBkYfnPp3GqRct05y0tlN5tvfgbN3lkcv86 1QDQ== 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 z127-v6si16204924pgb.455.2018.08.01.11.13.45; Wed, 01 Aug 2018 11:13:59 -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 S1732601AbeHAT7y (ORCPT + 99 others); Wed, 1 Aug 2018 15:59:54 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:49924 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389715AbeHATIe (ORCPT ); Wed, 1 Aug 2018 15:08:34 -0400 Received: from localhost (D57E6652.static.ziggozakelijk.nl [213.126.102.82]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id B171B1330; Wed, 1 Aug 2018 17:12:04 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Steven Rostedt (VMware)" Subject: [PATCH 4.14 014/246] tracing: Fix possible double free in event_enable_trigger_func() Date: Wed, 1 Aug 2018 18:48:44 +0200 Message-Id: <20180801165012.385193023@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801165011.700991984@linuxfoundation.org> References: <20180801165011.700991984@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Steven Rostedt (VMware) commit 15cc78644d0075e76d59476a4467e7143860f660 upstream. There was a case that triggered a double free in event_trigger_callback() due to the called reg() function freeing the trigger_data and then it getting freed again by the error return by the caller. The solution there was to up the trigger_data ref count. Code inspection found that event_enable_trigger_func() has the same issue, but is not as easy to trigger (requires harder to trigger failures). It needs to be solved slightly different as it needs more to clean up when the reg() function fails. Link: http://lkml.kernel.org/r/20180725124008.7008e586@gandalf.local.home Cc: stable@vger.kernel.org Fixes: 7862ad1846e99 ("tracing: Add 'enable_event' and 'disable_event' event trigger commands") Reivewed-by: Masami Hiramatsu Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Greg Kroah-Hartman --- kernel/trace/trace_events_trigger.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- a/kernel/trace/trace_events_trigger.c +++ b/kernel/trace/trace_events_trigger.c @@ -1396,6 +1396,9 @@ int event_enable_trigger_func(struct eve goto out; } + /* Up the trigger_data count to make sure nothing frees it on failure */ + event_trigger_init(trigger_ops, trigger_data); + if (trigger) { number = strsep(&trigger, ":"); @@ -1446,6 +1449,7 @@ int event_enable_trigger_func(struct eve goto out_disable; /* Just return zero, not the number of enabled functions */ ret = 0; + event_trigger_free(trigger_ops, trigger_data); out: return ret; @@ -1456,7 +1460,7 @@ int event_enable_trigger_func(struct eve out_free: if (cmd_ops->set_filter) cmd_ops->set_filter(NULL, trigger_data, NULL); - kfree(trigger_data); + event_trigger_free(trigger_ops, trigger_data); kfree(enable_data); goto out; }