From patchwork Thu Feb 15 20:27:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasiliy Kovalev X-Patchwork-Id: 13559126 X-Patchwork-Delegate: kuba@kernel.org Received: from air.basealt.ru (air.basealt.ru [194.107.17.39]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 824FF132475 for ; Thu, 15 Feb 2024 20:27:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=194.107.17.39 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708028855; cv=none; b=hKst7Zu39ZbIfc0bIZwAxrjLsnHJigFyJ3aUN0N+7SIKcLI0R2bjKA8pZVk/AuiSSI6zbmdeLHtXEsV9zYwEcw+QHiuaE56DC1Q3UY7QVgSuE0Fkzf0cuMKDEUcxgNCgDD+j6C1Hudu+XzDqZypn/zeG06r/8CkxT2XVTrseobk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708028855; c=relaxed/simple; bh=jplBJ6SpWZ7uj96I/jEqtfl7o1m5V7jekhAN+UuAojg=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=RNwkDeNaMKnZ6hld+f0dCQUF1hQYiWKY4dy8VICkPtykdFnx689MzoFBpqvvWTp9lp3ijn46Zx7EJkpgLlul2nQkRpuLxuJ9AIPrjoMbxX7tAVs3tsoIzXhWmi/BkVYcbFe/N2pKOlZ+hMOgod8cHV8G+lhiAqYATub5C6MLsF0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=altlinux.org; spf=pass smtp.mailfrom=altlinux.org; arc=none smtp.client-ip=194.107.17.39 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=altlinux.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=altlinux.org Received: by air.basealt.ru (Postfix, from userid 490) id E4D962F2025B; Thu, 15 Feb 2024 20:27:31 +0000 (UTC) X-Spam-Level: Received: from altlinux.ipa.basealt.ru (unknown [178.76.204.78]) by air.basealt.ru (Postfix) with ESMTPSA id B85A22F20259; Thu, 15 Feb 2024 20:27:29 +0000 (UTC) From: kovalev@altlinux.org To: netdev@vger.kernel.org Cc: davem@davemloft.net, dsahern@kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, david.lebrun@uclouvain.be, kovalev@altlinux.org Subject: [PATCH] ipv6: sr: fix possible use-after-free and null-ptr-deref Date: Thu, 15 Feb 2024 23:27:17 +0300 Message-Id: <20240215202717.29815-1-kovalev@altlinux.org> X-Mailer: git-send-email 2.33.8 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Vasiliy Kovalev The pernet operations structure for the subsystem must be registered before registering the generic netlink family. Fixes: 915d7e5e5930 ("ipv6: sr: add code base for control plane support of SR-IPv6") Signed-off-by: Vasiliy Kovalev --- net/ipv6/seg6.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/net/ipv6/seg6.c b/net/ipv6/seg6.c index 29346a6eec9ffe..35508abd76f43d 100644 --- a/net/ipv6/seg6.c +++ b/net/ipv6/seg6.c @@ -512,22 +512,24 @@ int __init seg6_init(void) { int err; - err = genl_register_family(&seg6_genl_family); + err = register_pernet_subsys(&ip6_segments_ops); if (err) goto out; - err = register_pernet_subsys(&ip6_segments_ops); + err = genl_register_family(&seg6_genl_family); if (err) - goto out_unregister_genl; + goto out_unregister_pernet; #ifdef CONFIG_IPV6_SEG6_LWTUNNEL err = seg6_iptunnel_init(); if (err) - goto out_unregister_pernet; + goto out_unregister_genl; err = seg6_local_init(); - if (err) - goto out_unregister_pernet; + if (err) { + seg6_iptunnel_exit(); + goto out_unregister_genl; + } #endif #ifdef CONFIG_IPV6_SEG6_HMAC @@ -548,11 +550,11 @@ int __init seg6_init(void) #endif #endif #ifdef CONFIG_IPV6_SEG6_LWTUNNEL -out_unregister_pernet: - unregister_pernet_subsys(&ip6_segments_ops); -#endif out_unregister_genl: genl_unregister_family(&seg6_genl_family); +#endif +out_unregister_pernet: + unregister_pernet_subsys(&ip6_segments_ops); goto out; }