From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9544445DCE; Fri, 29 Nov 2024 17:10:58 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 674B4402AE; Fri, 29 Nov 2024 17:10:58 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id B66514014F for ; Fri, 29 Nov 2024 17:10:56 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732896656; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=2E2WmCjIxX7CApOqoQHhkuzWJz/nUg00Aib98OPZwhE=; b=GQDrkHuTfpO1G30pfmvifnF+2XfeIX7HhjiFInux4eVhuCUfp1hDNRufZWJXkRzE9NTb2w nBgluJMfESOg5FsRu8U5y5tHuxeOJqxS48fSBbfXDQUcuVFD1Ia0ifyGbOPoL8Jcjz9DBs VfwhIlivKNJooA9smVSZQ9AAvjPy4Hs= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-592-FM995awAMvaNItT0S59QTA-1; Fri, 29 Nov 2024 11:10:55 -0500 X-MC-Unique: FM995awAMvaNItT0S59QTA-1 X-Mimecast-MFC-AGG-ID: FM995awAMvaNItT0S59QTA Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5AEDF1944D45; Fri, 29 Nov 2024 16:10:52 +0000 (UTC) Received: from ringo.home (unknown [10.39.208.7]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id ECBF01956095; Fri, 29 Nov 2024 16:10:49 +0000 (UTC) From: Robin Jarry To: dev@dpdk.org, Stephen Hemminger , Bruce Richardson , =?UTF-8?q?Morten=20Br=C3=B8rup?= , Chengwen Feng Subject: [PATCH dpdk] log: fix double free on cleanup Date: Fri, 29 Nov 2024 17:10:14 +0100 Message-ID: <20241129161013.704859-2-rjarry@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 5aP_Dc3bfsVJ7tY1-oMt3sSvVVrauq6LtRU2eYRXw-k_1732896652 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Fix the following crash when closing a log file after rte_eal_cleanup(): double free or corruption (!prev) Thread 1 "grout" received signal SIGABRT, Aborted. __pthread_kill_implementation (threadid=, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44 ... #10 _IO_new_fclose (fp=0xb63090) at iofclose.c:74 #11 0x000000000049c04e in dpdk_fini () at ../main/dpdk.c:204 #12 0x0000000000402ab8 in main (...) at ../main/main.c:217 (gdb) up 11 #11 0x000000000049c04e in dpdk_fini () at ../main/dpdk.c:204 202 rte_eal_cleanup(); 203 if (log_stream != NULL) 204 fclose(log_stream); When the application has passed a custom file via rte_openlog_stream() DPDK should not call fclose() on it. Add an internal is_internal_file field to track whether the file has been allocated by DPDK (syslog or journald) to determine if it should be closed or not. Fixes: 985130369be3 ("log: rework syslog handling") Signed-off-by: Robin Jarry --- lib/log/log.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/log/log.c b/lib/log/log.c index eb087d601e8b..e1c18a8e5351 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -38,6 +38,7 @@ static struct rte_logs { uint32_t type; /**< Bitfield with enabled logs. */ uint32_t level; /**< Log level. */ FILE *file; /**< Output file set by rte_openlog_stream, or NULL. */ + bool is_internal_file; log_print_t print_func; size_t dynamic_types_len; struct rte_log_dynamic_type *dynamic_types; @@ -80,8 +81,11 @@ static RTE_DEFINE_PER_LCORE(struct log_cur_msg, log_cur_msg); int rte_openlog_stream(FILE *f) { + if (rte_logs.is_internal_file && rte_logs.file != NULL) + fclose(rte_logs.file); rte_logs.file = f; rte_logs.print_func = vfprintf; + rte_logs.is_internal_file = false; return 0; } @@ -520,6 +524,7 @@ eal_log_init(const char *id) /* if either syslog or journal is used, then no special handling */ if (logf) { rte_openlog_stream(logf); + rte_logs.is_internal_file = true; } else { bool is_terminal = isatty(fileno(stderr)); bool use_color = log_color_enabled(is_terminal); @@ -550,11 +555,8 @@ eal_log_init(const char *id) void rte_eal_log_cleanup(void) { - FILE *log_stream = rte_logs.file; - - /* don't close stderr on the application */ - if (log_stream != NULL) - fclose(log_stream); - + if (rte_logs.is_internal_file && rte_logs.file != NULL) + fclose(rte_logs.file); rte_logs.file = NULL; + rte_logs.is_internal_file = false; } -- 2.47.1