Received: by 2002:ac0:f2c4:0:0:0:0:0 with SMTP id f4csp2181683imp; Mon, 25 Jul 2022 08:11:59 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sVo2y4gVdcMJB0GiBNEgdHp+J0UCuoxx3QtoB42liVDVGZ12/8SvjRBzWiXr82rcTkqRDf X-Received: by 2002:a05:6402:538a:b0:43a:298e:bc2b with SMTP id ew10-20020a056402538a00b0043a298ebc2bmr13644625edb.125.1658761918831; Mon, 25 Jul 2022 08:11:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658761918; cv=none; d=google.com; s=arc-20160816; b=X3+Obwov58b/J77R4kbbC20So8bfDzw1Htf7QDYAfyPmQYx4D2/dj2ZC3urZeBc0Qd OxG3NiQc60rziXWuR8A62SeYhhk+zg9+BLWWBMSdVlocEFMUlz7bQR9ikRW+dryqKnb/ 1w8voDBpUnETz6rguS8ZoCgy5IxwTwqniEZjv2FFDREMn5A03lipCmKJBuOYc2e0r/lP 1dstwTVcnFenSVGkm+CT4Dh5BMoLjFP7rREM0KJsKrIEXFQFvai9VvwWST9zlY/xLUkJ WWBF+tx5lpm3zzvUOhaGA2Cb/4aX8oYdkeU4iCkqOczHtWnDsEzI+j1nzGDoBJWkwod3 kb5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=hOzgdGaxG9lqrRrGagNDLe+Usov2bYHsVYmdfzhFWek=; b=bcSW/G9+wMelFkQ9ZOUgq4wi0NSWlTVxgv3m+QeO7ysyodqee2TWOVGJLI7xIhR732 5D0esbg7M9IqyMR5lPOc4/uZqwpH6f9MLtD0bLdk6LraL2kHs85O38Fyb+pXTE97mL8I SGsgrr/tKSmW7PUzuzy9FKzZU/tNKusNWu5zduvb875NDHcO30xjW7SCpF/CP94cPfh7 ZEChgnBVfoFPJOxPo8HZrC5rVysuWWBkpW5qVd6MhiBsHKrhrt7LsDT3XgLEJQfGQL58 hb7FjBmLCtOkSffdGnjmS/3HLGDwM19qjciLhmttonnyejS8DXr9aZNU0scM7COjUdU2 k9iw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hr7-20020a1709073f8700b0072a9e62a9dfsi14694180ejc.111.2022.07.25.08.11.33; Mon, 25 Jul 2022 08:11:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235738AbiGYO4o (ORCPT + 99 others); Mon, 25 Jul 2022 10:56:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235692AbiGYO4n (ORCPT ); Mon, 25 Jul 2022 10:56:43 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78A04E0CC; Mon, 25 Jul 2022 07:56:42 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 16F2A61226; Mon, 25 Jul 2022 14:56:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E9561C341C6; Mon, 25 Jul 2022 14:56:40 +0000 (UTC) Date: Mon, 25 Jul 2022 10:56:39 -0400 From: Steven Rostedt To: Andreas Schwab Cc: Daniel Bristot de Oliveira , linux-trace-devel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] rtla: fix double free Message-ID: <20220725105639.295a7d7d@gandalf.local.home> In-Reply-To: References: X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 25 Jul 2022 15:46:40 +0200 Andreas Schwab wrote: > On Jul 25 2022, Daniel Bristot de Oliveira wrote: > > > Hi Andreas > > > > On 7/25/22 15:10, Andreas Schwab wrote: > >> Don't call trace_instance_destroy in trace_instance_init when it fails, > >> this is done by the caller. > > > > Regarding the Subject, are you seeing a double-free error, or it is just an > > optimization? > > A double free nowadays is almost always an error, due to better malloc > checking. > > > AFAICS, trace_instance_destroy() checks the pointers before calling free(). > > That doesn't help when the pointer is not cleared afterwards. Do you > prefer that? > > > Why am I asking? because if it is a double-free bug, we need to add the "Fixes:" > > tag, > > It's the first time I tried running rtla, so I don't know whether it is > a regression, but from looking at the history it appears to have been > introduced already in commit 0605bf009f18 ("rtla: Add osnoise tool") > I think the real fix is to make trace_instance_destroy() be able to be called more than once. void trace_instance_destroy(struct trace_instance *trace) { if (trace->inst) { disable_tracer(trace->inst); destroy_instance(trace->inst); trace->inst = NULL; } if (trace->seq) { free(trace->seq); trace->seq = NULL; } if (trace->tep) { tep_free(trace->tep); trace->tep = NULL; } } As trace_instance_init() is doing the above allocations, it should clean it up on error. But I also agree, this will lead to double free without changing trace_instance_destroy() to be the above and then calling it twice. -- Steve