From nobody Sun Feb 8 15:59:24 2026 Received: from mail-oo1-f71.google.com (mail-oo1-f71.google.com [209.85.161.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4CBB261FFE for ; Fri, 16 Jan 2026 08:59:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.71 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768553983; cv=none; b=MXSvdD/4psaJIZnXv1Avo9Tri6l1Lcit2rWf7rCIAEZxHEJdejnVvN2pyOvUN2X8JHIkcJYZCECfCv8dYM8zw1EJ/CJqfObvqVZpxM3CMC+/i7mGl4seImVE2u3/pYodu3euL7wsZv8+I8CR79kZA6WPtn/xUPPgEvYUbOZCaKM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768553983; c=relaxed/simple; bh=0Zuys5zBIIWWXlPYE/tWJUtJsEjBu8Xdw3DeJg+dvUI=; h=MIME-Version:Date:In-Reply-To:Message-ID:Subject:From:To: Content-Type; b=u0Hzevt8xcB7uqQGv4la47ihY4L+Pc3UTOZ7xd/EFI0MxD0opODmv6bH4KHYj+dx24riwpCxBnhFxYHzmTLI/1pznF+nI1Qvzpy8wy+LBg+sEgDaMyF/gYVB43d760DvWBEqXsY+z1S4FHAg2bMcqe99mr6Fx+SmKczM3q6zhpM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com; arc=none smtp.client-ip=209.85.161.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com Received: by mail-oo1-f71.google.com with SMTP id 006d021491bc7-661125c8491so3042666eaf.3 for ; Fri, 16 Jan 2026 00:59:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768553980; x=1769158780; h=to:from:subject:message-id:in-reply-to:date:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=B3OfJAWUmgdZIlo/eB2PgqrF64UsdBGOOw3po0VxOns=; b=DPuIKE0vakBjMEEkcSbldyFP7GIx5WGI1LCMgltFGL6y3TFqxJVvkCT+IjxlINsjia Z+cizRz+VmGfCg6qibEa6TFfVf1e0wX0UhGIDQD6LICZWgV53fb29uqCB95lQLgCs+Vj KBYIKUGHKeZ7sxiHjZJXL1AE4bVxCuEzJPk8YezUtHDEvABVvUscgoot0PFIK+tO1fYj gcshB5jNFsn/PMnvwE8TRB1Whc3kBEyCBGQljX2hhD+T/8bAf5z88f/do/Sbc8hWGvVh pnN+f0H7MHFrRuepe7c4MSXjm+N/uncundx3WIA3heo1IcaEzrD62v8AM4HRHtPub7RG 4NqQ== X-Gm-Message-State: AOJu0YzUJ+0JzWidu1VRPUJ9MvPr8fYSEaI5RF2BYeXZDdcE3SH3VDTG hBVOn/JDez9l+jPNp0PwWFpYS4bqvIVcdOHE7DUIwrUUB67qwZJ2R6Bu8qkZTLBLE2CH3dqZ6Z/ 5QqH4qOtPA3eiFiMP9eCLfwUzSPKAalHLBXqGTHdwT3lNeUegb097QUnFMbI= Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Received: by 2002:a05:6820:4489:b0:659:9a49:8f34 with SMTP id 006d021491bc7-66117a0476amr1013507eaf.69.1768553980269; Fri, 16 Jan 2026 00:59:40 -0800 (PST) Date: Fri, 16 Jan 2026 00:59:40 -0800 In-Reply-To: <69694849.050a0220.58bed.0025.GAE@google.com> X-Google-Appengine-App-Id: s~syzkaller X-Google-Appengine-App-Id-Alias: syzkaller Message-ID: <6969fdfc.050a0220.58bed.0044.GAE@google.com> Subject: Forwarded: [PATCH] netrom: fix memory leak in nr_add_node() From: syzbot To: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For archival purposes, forwarding an incoming command email to linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com. *** Subject: [PATCH] netrom: fix memory leak in nr_add_node() Author: kartikey406@gmail.com #syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git= master When nr_add_node() creates a new neighbor but the route quality is too low to be added (node already has 3 routes with better quality), the newly allocated neighbor is never used but remains in the neighbor list with refcount=3D1, causing a memory leak. Also fix the same leak in the error path when nr_node allocation fails after creating a new neighbor. Fix by tracking whether a new neighbor was allocated and removing it from the list if it was not used (count =3D=3D 0) or on allocation failure. Add debug printk to trace the issue. Reported-by: syzbot+3f2d46b6e62b8dd546d3@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=3D3f2d46b6e62b8dd546d3 Signed-off-by: Deepanshu Kartikey --- net/netrom/nr_route.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/net/netrom/nr_route.c b/net/netrom/nr_route.c index b94cb2ffbaf8..3cc462c2bef3 100644 --- a/net/netrom/nr_route.c +++ b/net/netrom/nr_route.c @@ -100,11 +100,16 @@ static int __must_check nr_add_node(ax25_address *nr,= const char *mnemonic, { struct nr_node *nr_node; struct nr_neigh *nr_neigh; + bool new_neigh =3D false; int i, found; struct net_device *odev; =20 + printk(KERN_ERR "nr_add_node: entered, quality=3D%d\n", quality); + + if ((odev=3Dnr_dev_get(nr)) !=3D NULL) { /* Can't add routes to ourself */ dev_put(odev); + printk(KERN_ERR "nr_add_node: exit EINVAL (route to self)\n"); return -EINVAL; } =20 @@ -112,6 +117,8 @@ static int __must_check nr_add_node(ax25_address *nr, c= onst char *mnemonic, =20 nr_neigh =3D nr_neigh_get_dev(ax25, dev); =20 + printk(KERN_ERR "nr_add_node: nr_node=3D%p, nr_neigh=3D%p\n", nr_node, nr= _neigh); + /* * The L2 link to a neighbour has failed in the past * and now a frame comes from this neighbour. We assume @@ -172,6 +179,8 @@ static int __must_check nr_add_node(ax25_address *nr, c= onst char *mnemonic, } } =20 + new_neigh =3D true; + printk(KERN_ERR "nr_add_node: created new neighbor\n"); spin_lock_bh(&nr_neigh_list_lock); hlist_add_head(&nr_neigh->neigh_node, &nr_neigh_list); nr_neigh_hold(nr_neigh); @@ -182,9 +191,14 @@ static int __must_check nr_add_node(ax25_address *nr, = const char *mnemonic, nr_neigh->quality =3D quality; =20 if (nr_node =3D=3D NULL) { + printk(KERN_ERR "nr_add_node: creating new node\n"); if ((nr_node =3D kmalloc(sizeof(*nr_node), GFP_ATOMIC)) =3D=3D NULL) { - if (nr_neigh) + printk(KERN_ERR "nr_add_node: node alloc failed\n"); + if (nr_neigh) { + if (new_neigh) + nr_remove_neigh(nr_neigh); nr_neigh_put(nr_neigh); + } return -ENOMEM; } =20 @@ -209,6 +223,7 @@ static int __must_check nr_add_node(ax25_address *nr, c= onst char *mnemonic, spin_unlock_bh(&nr_node_list_lock); =20 nr_neigh_put(nr_neigh); + printk(KERN_ERR "nr_add_node: exit after new node, neigh count=3D%d\n", = nr_neigh->count); return 0; } nr_node_lock(nr_node); @@ -225,9 +240,12 @@ static int __must_check nr_add_node(ax25_address *nr, = const char *mnemonic, } } =20 + printk(KERN_ERR "nr_add_node: found=3D%d, nr_node->count=3D%d\n", found, = nr_node->count); + if (!found) { /* We have space at the bottom, slot it in */ if (nr_node->count < 3) { + printk(KERN_ERR "nr_add_node: adding route (count < 3)\n"); nr_node->routes[2] =3D nr_node->routes[1]; nr_node->routes[1] =3D nr_node->routes[0]; =20 @@ -242,6 +260,7 @@ static int __must_check nr_add_node(ax25_address *nr, c= onst char *mnemonic, } else { /* It must be better than the worst */ if (quality > nr_node->routes[2].quality) { + printk(KERN_ERR "nr_add_node: replacing worst route\n"); nr_node->routes[2].neighbour->count--; nr_neigh_put(nr_node->routes[2].neighbour); =20 @@ -255,6 +274,9 @@ static int __must_check nr_add_node(ax25_address *nr, c= onst char *mnemonic, nr_neigh_hold(nr_neigh); nr_neigh->count++; } + else { + printk(KERN_ERR "nr_add_node: quality too low, not adding\n"); + } } } =20 @@ -279,6 +301,15 @@ static int __must_check nr_add_node(ax25_address *nr, = const char *mnemonic, } } =20 + printk(KERN_ERR "nr_add_node: end, new_neigh=3D%d, count=3D%d\n", new_nei= gh, nr_neigh->count); + + if (new_neigh && nr_neigh->count =3D=3D 0) { + printk(KERN_ERR "nr_add_node: end, new_neigh=3D%d, count=3D%d\n", new_ne= igh, nr_neigh->count); + nr_remove_neigh(nr_neigh); + } else if (new_neigh) { + printk(KERN_ERR "nr_add_node: new_neigh used, count=3D%d\n", nr_neigh->c= ount); + } + nr_neigh_put(nr_neigh); nr_node_unlock(nr_node); nr_node_put(nr_node); --=20 2.43.0