Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp700550rdh; Wed, 14 Feb 2024 08:51:51 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUX/f3hPAy4TwnDC+SZ+uOu+Uf0PCtxKviAwZm5w/u9IWF3UULDbw5GwoqCKcwP9P8qLNXwyjlYWGbPKyQuBqr40tLK/HQbG+At96BAtQ== X-Google-Smtp-Source: AGHT+IEjZ9wsV3XTKjicVM/Rp8w8mGaI2ls4SZSeFSo9Teih7Iwm3AOwpLGyZPOErUCX+mABS2ap X-Received: by 2002:a05:6214:262c:b0:68f:bf1:23dd with SMTP id gv12-20020a056214262c00b0068f0bf123ddmr1301081qvb.37.1707929511058; Wed, 14 Feb 2024 08:51:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707929511; cv=pass; d=google.com; s=arc-20160816; b=HJvAQXypfmL+6eaYyJfplHcRWrzfzfO1CWlvP253nmnfVS5C1vWoCNBnS+p41djwip z9mGn/YnMvjhgd/DA1siNN2QSWWYQzrGmvxBdoT7DDpeJgogTPlVdyF4Wjw6hroEXAmy XSnwkIVmr26zt/aCO8039oXSYBhD2N/YJEF8k4nC3v8sKhKh+Bl2SRvInbpfVWRCTqpj vD14XJx/a2ZxSSZ1NAT4Vyzw9TAWPbglPLu68mqBT1SCf4ES7RHynEGRt+gg9d1k1bPr fx47ldxrWIPiWiIQjd7szJntNhZKXqFSpAb0voFhiCyduq9ePi80q/qklbRRsprpA2uA 9aYQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=KVIwacBUVla9ZZO/m64khx0GO93f9sie4SUEEFaHv20=; fh=Ew3tudZKNICp9QJmGSzYjccAgfI8+YzAUXS/feiJ6O4=; b=cCeqK4xukO3yMB9i+YaNYbreU7cIcFs8x3B5CWBLj/d+IOLWDlxgOpNIcw93Z88AbY IRCPaF6xEZaK05nyRpBkeJdklr3KXfGCDMT6WvXIOc711BxpewWRUQ5FbUXy/apky6Qz 0k4KxvV0dp85MIX36+FSSkbjkKIVydyA6fGEWWyUTZgAzdCPj3yQpMUorCYM4kqMMUIc MW85eqCD0AhFHTnx+8LYcJqtjHm1UVVzvERsVEVXEGmfwadcuqp/UOD8/71pjFBURtJw /kBjbUo17p7/2RqxAO9VWKpP048pQ6HL39AJ3k4PkEEpDv6zLvWxmU0gZkKMgw8I7peC Wimg==; 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-65586-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65586-linux.lists.archive=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCWtgkQ8RyrDnpFRdwBNEKT7SktQ9d8hGSiAd4eauDbewAiRfAQiMuo9aZft/sklq6jRCVeYAuymSdS03l0N+QSBAVE3FzX2whlUtWTHWg== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id t10-20020a05621421aa00b0068ce8312e21si4514659qvc.415.2024.02.14.08.51.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 08:51:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65586-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=gnumonks.org); spf=pass (google.com: domain of linux-kernel+bounces-65586-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65586-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 575451C22C6A for ; Wed, 14 Feb 2024 16:50:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 773FC60BAA; Wed, 14 Feb 2024 16:49:49 +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 E8E8D60BA9; Wed, 14 Feb 2024 16:49:45 +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=1707929389; cv=none; b=Vi7AenoGPZDaaXSFjhv/2ubmWPAJ+9UZ1O/Fpbf2RgvCmgt9uk0LAfSPzj4mE0GvGNbka5a1KGqKaEJiZ9rrF74rzmU6cB2BjKKg2zN2rwqMDbV8nnywwN/Pw7nAtwUxbmqOSoZIpSwJHEJp5zArSb/kW7ewvKElsVDzucdHnsM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707929389; c=relaxed/simple; bh=zR2KWP8yg4tZ+LnvHd7op1sKZotXTweSN7cy2brrjkM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=sAEdLBso8SefIEAGoSbZ3y6vSTs5AqblXoIT4wx5TGeR/V8YqxG7Y6UAz6OTTRy9nAXQrVEGKFEG0iFbMefZb6YlFePKF9CuqbqdAcV77gRawoewisioIyYFJq/zNG8sD3ZYwq9L9zY3oHo1F9waA6C03yGPH/OrAYx1Ehv04tc= 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=48386 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 1raIS4-001NHr-PN; Wed, 14 Feb 2024 17:49:42 +0100 Date: Wed, 14 Feb 2024 17:49:40 +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 In-Reply-To: <20240214162733.34214-1-kovalev@altlinux.org> X-Spam-Score: -1.8 (-) 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; > Syzkaller hit 'general protection fault in gtp_genl_dump_pdp' bug: [...] > diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c > index b1919278e931f4..2129ae42c70304 100644 > --- a/drivers/net/gtp.c > +++ b/drivers/net/gtp.c > @@ -1907,20 +1907,20 @@ static int __init gtp_init(void) > if (err < 0) > goto error_out; > > - err = genl_register_family(>p_genl_family); > + err = register_pernet_subsys(>p_net_ops); > if (err < 0) > goto unreg_rtnl_link; > > - err = register_pernet_subsys(>p_net_ops); > + err = genl_register_family(>p_genl_family); > if (err < 0) > - goto unreg_genl_family; > + goto unreg_pernet_subsys; > > pr_info("GTP module loaded (pdp ctx size %zd bytes)\n", > sizeof(struct pdp_ctx)); > return 0; > > -unreg_genl_family: > - genl_unregister_family(>p_genl_family); > +unreg_pernet_subsys: > + unregister_pernet_subsys(>p_net_ops); > unreg_rtnl_link: > rtnl_link_unregister(>p_link_ops); > error_out: > -- > 2.33.8 >