Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp225724rwb; Tue, 25 Jul 2023 14:56:32 -0700 (PDT) X-Google-Smtp-Source: APBJJlEq+9UzsSybIhzkXvqazphL4X02v+glAYQqAwr857HFlNF0iztUc8qwzTCoxKcdUxEhP47w X-Received: by 2002:aa7:cd48:0:b0:522:5591:d748 with SMTP id v8-20020aa7cd48000000b005225591d748mr119232edw.15.1690322191912; Tue, 25 Jul 2023 14:56:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690322191; cv=none; d=google.com; s=arc-20160816; b=XH4HZfKATjCC4AhXGuohgV5q0+bmSswvNTNHgI4zPFopUZRqdf5W9Ud7eVmh1u5qY3 oCQ40G3dOaZg+V5m0IoM3rN1VvWaVimH3qXS6hHfWn32KB7dwaWrQ2yGjnaQhOqHIyV+ LEj54mlojVrjREOYbdO7Ix8I0q4nPlVPxTB/lSeRLXl2ExYPpSkfFNkOxi0YEVdbe444 N+maZKSSAFD1JDrjMGO6nmgTS0JyQIKIYEAYSqkPxdwPQcdugSqng/cN5Kd3AbPFLFDA VdRlauRsJJOg11/nMB07rROZR2fTNc5YCf6hzPx1Il6LyjvFudVh8TDDImsZSMWW61cn ecIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:dkim-filter; bh=QIj/W1Ow+/WijWz7gTeX0AbUfuvnp4V1K0pNKv5gGZg=; fh=qqNBJcrOkuEpfpi3+KyZlueSeiy8MapzVhhETxrZDG0=; b=yXzR3UFJtKf2Mc16+cgUmyqU0krQxQ1NxjkSGNq0sOt+720qKMiwmkcDetqOLTZoSQ MSTH+pXDEqpZm4hprzuD1vZWs7UIHnLpZNO4WXw2KW5EbYyuiLlumat2aH0/vNmnuRqZ QLpJfo8E/2C9x7ZwSEy69E1gjhoS88DLe5A8TWaKTb1BXqerAh9eTcthcGthtTszEAz1 ldDp/FZgd0/1xU9rKOnP/6f475HQXfdo7ZrMLe+68OTNWM4T5/cT8XjgG0rTXBOmtKPn KWFWe37iruTCQ5PzJeYStcsDPKoAGCjGKfAOsWe6T06UQ3de2mm04VwpJ7Hfwk/rGujG TSqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=fsIauPBT; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p13-20020a05640210cd00b005221fa80fd8si4946394edu.617.2023.07.25.14.56.07; Tue, 25 Jul 2023 14:56:31 -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; dkim=pass header.i=@ispras.ru header.s=default header.b=fsIauPBT; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231254AbjGYVjA (ORCPT + 99 others); Tue, 25 Jul 2023 17:39:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229664AbjGYVi7 (ORCPT ); Tue, 25 Jul 2023 17:38:59 -0400 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF4D31BE9; Tue, 25 Jul 2023 14:38:56 -0700 (PDT) Received: from localhost (unknown [46.242.14.200]) by mail.ispras.ru (Postfix) with ESMTPSA id 77FC140737C9; Tue, 25 Jul 2023 21:38:54 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 77FC140737C9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1690321134; bh=QIj/W1Ow+/WijWz7gTeX0AbUfuvnp4V1K0pNKv5gGZg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=fsIauPBTc/W7atPRGKYt8QwNj+biQdNNcPelkt0JUTlshG6hI41HS4OAz0uOgtQ/H 4leIq+HT3FIPqvxRL/iF/ak2l3khQB14DcYXWjqJx1ZIxp4kHVCOnd1fJHN7EgIUEr kscZBXtCbpG+hHlXkZ3cHSBhn6bYxJkPwPPKfwrE= Date: Wed, 26 Jul 2023 00:38:53 +0300 From: Fedor Pchelkin To: Xin Long Cc: Jon Maloy , Ying Xue , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, tipc-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org, Alexey Khoroshilov , lvc-project@linuxtesting.org Subject: Re: [PATCH] tipc: stop tipc crypto on failure in tipc_node_create Message-ID: References: <20230725183646.5668-1-pchelkin@ispras.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 23/07/25 03:46PM, Xin Long wrote: > On Tue, Jul 25, 2023 at 2:37 PM Fedor Pchelkin wrote: > > > > If tipc_link_bc_create() fails inside tipc_node_create() for a newly > > allocated tipc node then we should stop its tipc crypto and free the > > resources allocated with a call to tipc_crypto_start(). > > > > Call tipc_crypto_stop() in that case. Also extract the similar error exit > > paths into a goto statement. > > > > Found by Linux Verification Center (linuxtesting.org). > > > > Fixes: cb8092d70a6f ("tipc: move bc link creation back to tipc_node_create") > > Signed-off-by: Fedor Pchelkin > > --- > > net/tipc/node.c | 17 +++++++++++------ > > 1 file changed, 11 insertions(+), 6 deletions(-) > > > > diff --git a/net/tipc/node.c b/net/tipc/node.c > > index 5e000fde8067..0d64005a803b 100644 > > --- a/net/tipc/node.c > > +++ b/net/tipc/node.c > > @@ -546,9 +546,7 @@ struct tipc_node *tipc_node_create(struct net *net, u32 addr, u8 *peer_id, > > #ifdef CONFIG_TIPC_CRYPTO > > if (unlikely(tipc_crypto_start(&n->crypto_rx, net, n))) { > > pr_warn("Failed to start crypto RX(%s)!\n", n->peer_id_string); > > - kfree(n); > > - n = NULL; > > - goto exit; > > + goto free_node; > > } > > #endif > > n->addr = addr; > > @@ -583,9 +581,7 @@ struct tipc_node *tipc_node_create(struct net *net, u32 addr, u8 *peer_id, > > n->capabilities, &n->bc_entry.inputq1, > > &n->bc_entry.namedq, snd_l, &n->bc_entry.link)) { > > pr_warn("Broadcast rcv link creation failed, no memory\n"); > > - kfree(n); > > - n = NULL; > > - goto exit; > > + goto stop_crypto; > > } > > tipc_node_get(n); > Can you please try moving up tipc_node_get(n) ahead tipc_link_bc_create() > and use tipc_node_put(n) to replace kfree(n) to avoid the extra > tipc_crypto_stop() call below? > > Thanks. > Guess moving tipc_node_get() before tipc_link_bc_create() would not solve the problem as ref is already initialized to 1 at that point. So just replacing direct kfree() with tipc_node_put() will fix it. Thank you for advice! I'll resend the v2 shortly. > > timer_setup(&n->timer, tipc_node_timeout, 0); > > @@ -610,6 +606,15 @@ struct tipc_node *tipc_node_create(struct net *net, u32 addr, u8 *peer_id, > > exit: > > spin_unlock_bh(&tn->node_list_lock); > > return n; > > +stop_crypto: > > + > > +#ifdef CONFIG_TIPC_CRYPTO > > + tipc_crypto_stop(&n->crypto_rx); > > +free_node: > > +#endif > > + kfree(n); > > + spin_unlock_bh(&tn->node_list_lock); > > + return NULL; > > } > > > > static void tipc_node_calculate_timer(struct tipc_node *n, struct tipc_link *l) > > -- > > 2.41.0 > >