Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp717017rdh; Wed, 14 Feb 2024 09:13:49 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXmMFL63yQakLufygT/6f8lMqrRhRLjTccErREiMtSM8NhxcOs4de+E4dV9zZZ5a1JW5Of0uwvoOYa/W/RCGONcH5pTZsMPUxmosuuX1A== X-Google-Smtp-Source: AGHT+IGygh6l0KbjCDZ+fQHTvATkJn1mV2XsDWSPRDF5SIdLYqTCIeRY9eTGWn/PHQhbWdmMKx+V X-Received: by 2002:aa7:d3cc:0:b0:55f:63ac:2425 with SMTP id o12-20020aa7d3cc000000b0055f63ac2425mr2187947edr.41.1707930829462; Wed, 14 Feb 2024 09:13:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707930829; cv=pass; d=google.com; s=arc-20160816; b=jIZhaGP0JdIW5bc7Ib9s4ryB/c86qdGKAjkKCAYPFz1bRCEfKCb/qBoYM8FyX5rzbn Gp3N4SbEjnLaRnR6p4qnadrDbGqcSwTfxVx3/ExmaVF0J+DNfInUNf1rcCuPljZBEo3L jaygtujNbTTqx9RTTI8OJ6MTZV7i1T7tPtAXuZaXYHs94nDJljx0g1p4A7+AbZ7kQ7mf n5r4zxrmwEck2K7hPTI3tvWOaeFzK/wCe4PbGgTvPa4Em4oXnlKUzYmI8rELF3AGDlIa bjCiNbY1tQfsobAhvlWpotp+YY+5QhBSV/6p9l4T/mOss5/albySlah9epTWWSeeehfj ULDQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date; bh=SXNKlPYboK8B1pw2jXwqUDOkYIgK2xsek8aKB1ZUHZI=; fh=ijSxkd8dXtcjuwrloqqzDX7ZG6EeWv7vA1z4rsOGhrY=; b=XSppHmJOWURLV62uyNsOXPsJyZ51j9tQvwBXjg5WZQ97yYgBQsEpfi8h0u3P0nOAEy K2G3cPWvMkG0MUi65GH8ExnAbElliEY2+8qulCi0o+fv49qGAtYVeu2+DE2qw6Efykpy 0xmb3vJ2sJ30ZwfsBGCKRCZUtuCr4TKgLiiCcYy+wGqWBhXjMsi6MrXcxwmXnAeFHiHw XrG2N3y2JNtHZSN/JKb0NQC8PATl0G8Tc4s+9+tcR3WD6qbWLBhUKfp1vcCUQPGLjmJE M8p32WHx3xNAQ1h7mO5tvPpieb2i+p8EVjus2S0IeNO9mcqvsd7znqM7+M9ZBhp0gILK g8DA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=gnumonks.org); spf=pass (google.com: domain of linux-kernel+bounces-65627-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65627-linux.lists.archive=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCUXY7Cx02F0A02N0q2F7+KKJWj+cygSlW1xgGwGOjOTyIZYVPYN/UnKMf/IUEiIkiyH99HiRDY5LRPCPpojrpff6m+5G266X963gPOMoQ== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id y10-20020aa7d50a000000b0056053103589si5003729edq.359.2024.02.14.09.13.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 09:13:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65627-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=gnumonks.org); spf=pass (google.com: domain of linux-kernel+bounces-65627-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65627-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D379B1F2AA0D for ; Wed, 14 Feb 2024 17:13:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C60607AE5D; Wed, 14 Feb 2024 17:13:35 +0000 (UTC) Received: from ganesha.gnumonks.org (ganesha.gnumonks.org [213.95.27.120]) (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 8E89B7A706; Wed, 14 Feb 2024 17:13:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.95.27.120 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707930815; cv=none; b=PIvj7sguSM4Sy4HF/ajdzRKSjujsmdA+LzCBYE2eE/3wic30dDVYTa4d78Hv/xDBCF8kd07DEYTaI/HV2D4avqqK+5TA2+NgumoBDuzEnuofzG96xPmw0DZdJ0jFxv0lBdVfNCakJ1XwbsUYh1aWWWQ5PDtSkwetR45dIbBQIn0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707930815; c=relaxed/simple; bh=lnxYYZhuHdZc7D0Y0bEbSBOBkMXVHnRmRIzuiMPc4fU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=DjJ1el30yp7j87dXSb5IJXSgRH+mZ2QuzNup0qS9wrrywAU4jX+nIzlteHV2sFFYlVbF0brbsd+Fm5tDSa6k63gUCuGZNQu6mhng410m0NJo8DPebRveCuxJYCwAc2Y/aIAhCw4+MAHr6onFWQqJjVIP7RuhAYziZURLtBOoJ5E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=netfilter.org; spf=pass smtp.mailfrom=gnumonks.org; arc=none smtp.client-ip=213.95.27.120 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=netfilter.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gnumonks.org Received: from [78.30.41.52] (port=54270 helo=gnumonks.org) by ganesha.gnumonks.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1raIp3-001Ooj-PP; Wed, 14 Feb 2024 18:13:27 +0100 Date: Wed, 14 Feb 2024 18:13:24 +0100 From: Pablo Neira Ayuso To: kovalev@altlinux.org Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, edumazet@google.com, laforge@gnumonks.org, davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, nickel@altlinux.org, oficerovas@altlinux.org, dutyrok@altlinux.org, stable@vger.kernel.org Subject: Re: [PATCH ver.2] gtp: fix use-after-free and null-ptr-deref in gtp_genl_dump_pdp() Message-ID: References: <20240214162733.34214-1-kovalev@altlinux.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Score: -1.9 (-) On Wed, Feb 14, 2024 at 08:06:12PM +0300, kovalev@altlinux.org wrote: > 14.02.2024 19:49, Pablo Neira Ayuso wrote: > > On Wed, Feb 14, 2024 at 07:27:33PM +0300, kovalev@altlinux.org wrote: > > > From: Vasiliy Kovalev > > > > > > The gtp_net_ops pernet operations structure for the subsystem must be > > > registered before registering the generic netlink family. > > Thanks for finding a remedy for this. > > > > If your fix is correct, (I didn't test your patch yet) then maybe this > > needs to be fixed in a few more spots in the tree? > > > > net/devlink/core.c-static int __init devlink_init(void) > > net/devlink/core.c-{ > > net/devlink/core.c- int err; > > net/devlink/core.c- > > net/devlink/core.c- err = genl_register_family(&devlink_nl_family); > > net/devlink/core.c- if (err) > > net/devlink/core.c- goto out; > > net/devlink/core.c: err = register_pernet_subsys(&devlink_pernet_ops); > > net/devlink/core.c- if (err) > > > > net/handshake/netlink.c- ret = genl_register_family(&handshake_nl_family); > > net/handshake/netlink.c- if (ret) { > > net/handshake/netlink.c- pr_warn("handshake: netlink registration failed (%d)\n", ret); > > net/handshake/netlink.c- handshake_req_hash_destroy(); > > net/handshake/netlink.c- return ret; > > net/handshake/netlink.c- } > > net/handshake/netlink.c- > > net/handshake/netlink.c- /* > > net/handshake/netlink.c- * ORDER: register_pernet_subsys must be done last. > > net/handshake/netlink.c- * > > net/handshake/netlink.c- * If initialization does not make it past pernet_subsys > > net/handshake/netlink.c- * registration, then handshake_net_id will remain 0. That > > net/handshake/netlink.c- * shunts the handshake consumer API to return ENOTSUPP > > net/handshake/netlink.c- * to prevent it from dereferencing something that hasn't > > net/handshake/netlink.c- * been allocated. > > net/handshake/netlink.c- */ > > net/handshake/netlink.c: ret = register_pernet_subsys(&handshake_genl_net_ops); > > > > net/ipv4/tcp_metrics.c: ret = register_pernet_subsys(&tcp_net_metrics_ops); > > net/ipv4/tcp_metrics.c- if (ret < 0) > > net/ipv4/tcp_metrics.c- panic("Could not register tcp_net_metrics_ops\n"); > > net/ipv4/tcp_metrics.c- > > net/ipv4/tcp_metrics.c- ret = genl_register_family(&tcp_metrics_nl_family); > > net/ipv4/tcp_metrics.c- if (ret < 0) > > net/ipv4/tcp_metrics.c- panic("Could not register tcp_metrics generic netlink\n"); > > net/ipv4/tcp_metrics.c-} > > > > net/ipv6/ioam6.c-int __init ioam6_init(void) > > net/ipv6/ioam6.c-{ > > net/ipv6/ioam6.c: int err = register_pernet_subsys(&ioam6_net_ops); > > net/ipv6/ioam6.c- if (err) > > net/ipv6/ioam6.c- goto out; > > net/ipv6/ioam6.c- > > net/ipv6/ioam6.c- err = genl_register_family(&ioam6_genl_family); > > net/ipv6/ioam6.c- if (err) > > net/ipv6/ioam6.c- goto out_unregister_pernet_subsys; > > > > net/ipv6/seg6.c- err = genl_register_family(&seg6_genl_family); > > net/ipv6/seg6.c- if (err) > > net/ipv6/seg6.c- goto out; > > net/ipv6/seg6.c- > > net/ipv6/seg6.c: err = register_pernet_subsys(&ip6_segments_ops); > > net/ipv6/seg6.c- if (err) > > net/ipv6/seg6.c- goto out_unregister_genl; > > > > net/netlink/genetlink.c- err = genl_register_family(&genl_ctrl); > > net/netlink/genetlink.c- if (err < 0) > > net/netlink/genetlink.c- goto problem; > > net/netlink/genetlink.c- > > net/netlink/genetlink.c: err = register_pernet_subsys(&genl_pernet_ops); > > net/netlink/genetlink.c- if (err) > > net/netlink/genetlink.c- goto problem; > > Most likely, judging by the backtrace, the bug is the same [1]: > > Call Trace: >   >  genl_dumpit+0x119/0x220 net/netlink/genetlink.c:1025 >  netlink_dump+0x588/0xca0 net/netlink/af_netlink.c:2264 >  __netlink_dump_start+0x6d0/0x9c0 net/netlink/af_netlink.c:2370 >  genl_family_rcv_msg_dumpit+0x1e1/0x2d0 net/netlink/genetlink.c:1074 >  genl_family_rcv_msg net/netlink/genetlink.c:1190 [inline] >  genl_rcv_msg+0x470/0x800 net/netlink/genetlink.c:1208 >  netlink_rcv_skb+0x16b/0x440 net/netlink/af_netlink.c:2543 >  genl_rcv+0x28/0x40 net/netlink/genetlink.c:1217 >  netlink_unicast_kernel net/netlink/af_netlink.c:1341 [inline] >  netlink_unicast+0x53b/0x810 net/netlink/af_netlink.c:1367 >  netlink_sendmsg+0x8b7/0xd70 net/netlink/af_netlink.c:1908 >  sock_sendmsg_nosec net/socket.c:730 [inline] >  __sock_sendmsg+0xd5/0x180 net/socket.c:745 >  ____sys_sendmsg+0x6ac/0x940 net/socket.c:2584 >  ___sys_sendmsg+0x135/0x1d0 net/socket.c:2638 >  __sys_sendmsg+0x117/0x1e0 net/socket.c:2667 >  do_syscall_x64 arch/x86/entry/common.c:52 [inline] >  do_syscall_64+0xd3/0x250 arch/x86/entry/common.c:83 >  entry_SYSCALL_64_after_hwframe+0x63/0x6b > RIP: 0033:0x7f35d567cda9 Ok, then a series of fixes probably needs to happen so each maintain can review and apply them. Maybe some of these subsystems above can only be compiled built-in, so that cannot trigger. In any case, are you up to pick on that series? Thanks.