From nobody Mon Apr 13 05:38:08 2026 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (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 B51EC34F48B for ; Mon, 9 Mar 2026 09:36:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773048986; cv=none; b=A+rOYU7SsRFhKvG8Osm0lK+0IfTozn8beEtFJTn6Nbz5zdV7UWyGUt8kfIFhSS9WcHCuSOGd3mhwxUgEf/cbzy2nliR+KDVOA/iUaNwU6a2AyDmPi6MZpZn5hkmyLmH5HilX992HF1ZbEvQ0x1sA19vD33Tftp6V2DgQAlslbBE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773048986; c=relaxed/simple; bh=ypmchPzWdWCXurOig2tSNh0Z8PppuUuNea8YyM8AKbE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=SNDKALSW+80nuHNj2nuDqXnQHzrdQgmjoiBNeavG7RlhWx6wf7czTdBo9L40K9nKGY2/wR0AtdoxBfM91T4LuSSqZBFrSuzwhXTqpBzxPEI1XGOuwsgk0+4Z7cJQ+2tVDYWcxnDOghDU71dcPS1yc/PjoaPKXod9V48hEkRFNEw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aKzkLlBn; arc=none smtp.client-ip=209.85.210.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aKzkLlBn" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-829a568f3ccso1359710b3a.0 for ; Mon, 09 Mar 2026 02:36:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773048984; x=1773653784; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=qykwMTP7A/5/YRIqOnHVxjHodm+EkvbjSmx3/8PuSRI=; b=aKzkLlBnyT/ldcl/l10CQoVeFMIJ42czPRY5AB3hO83TqFanNiwS2i3vVN/Z13yMcu 6QydQGFR4bqUJBE7Pi0U2SBNE7H1ri6ZnX4kRtLwOEfclytBdxSkInqg88N6x3al1v9j +4ylRDIAiSWVfpA5RhcJ+jilv63ohs0Ajty9hW1aapujAZGAixCJxEE7w+zdvxbdsp1+ IE2uRf7zyfSenp4++D0YSih94BK+NGWdZaRMbZbisFLavjyMQg/B/3v82XTNQhobonAW H7i2pDA+7LZT/JiUQT7LnON5r9XpCBIsiyul+CcOHvuS+8v8JdKnxgVFKlYoEs1jXadM tbqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773048984; x=1773653784; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=qykwMTP7A/5/YRIqOnHVxjHodm+EkvbjSmx3/8PuSRI=; b=qv1VV6v9h/34QsT94cgoXA6FvRxi1b9Lq+6uSgKp7YeLUaNdNvIiY1zLjGOOF/tFIr f0MWe4A8SywCiNF9Zc2qBz+WiWgpWa9XebkrosDqCw8aps3z9ivsnN0AfwTM7tlUDFaj kO1BJKrSScq8/aI7TtJES5B34UHMOoTeoI48/5JulbhEdN28V/eOK28k66JZDEUhtuot Q0VsFB1fSO5MzzAf3aq8h41BitS3sqlbY0FfFqmA4hsGvpYsPt2yenoTOacsjCrOH7zY L0Spf1bfhA+9/mQhkZ4+h8mcE+FdWM6CLi/8wLI95GJo1MdxPsx4SB31+SdtseDYw5Bg d6Rg== X-Forwarded-Encrypted: i=1; AJvYcCUDvT/D8Sh/Ztz15b/WoBCKG7/qQ9+2YNYKdRjmd1vzZNPWSwTRbv+h1YulfFJyA4oYeZMdwzkkoQTbskY=@vger.kernel.org X-Gm-Message-State: AOJu0YynkGtrKk5xYtR54yTQ8X1wQKpqa3cS3yXD0e6jFZuy3V1PTcNV tm/YYy6uT1+vAu6hL6ShS5CucUtwzIuHs/LCy16Hetn1ySuEIMU4gnH8 X-Gm-Gg: ATEYQzyhlztZHtXml7DcM8/y05yR+MwYzArDoI+yVNIe+Oqsg48ocjTiAzjhHUPIiAJ Gi6GucutqOqCekLykrPqy9KTyRjDbDcbGW2E1dbZ4GoMRn7Pcb6/8S5tRXMMoeydkmTGxy7kx22 +vVElbORJeYiUhyhgSzac6H4edi+uqa5TpjnEhjBw+vBmgyRUj1wFldk8PEY1uSU5tvvzeza077 UnvxCb3IC9nl3OeHS3oldF93B2O3blT8XOB86SENnQYHoFadPc9pFxbiwd8JU4IwJX7a6A8pWe/ 4HCnOqAwFEi9y7CrAYd68N+1ViGUEcLnRI6ykZttIaERkSrQQX7lKt6el2NOEHldj6yLIYFlECT EbHS+wtkDJ+Om67rja9EMeD5F2qKd98DUhTeRLi7cL1l3i1GS+qX2jcIPQpr0OTFj17foE8/Jla tJSDfV1015q8CH81Xh9mxz6Nz2Rcc2kB2KDVIG9KaEM9r+z5dzZOEn0toLlFS/JkrJSOe+GaEs0 0r9t5U= X-Received: by 2002:a05:6a00:7586:b0:81e:a228:f0c9 with SMTP id d2e1a72fcca58-829a2dbab9fmr7308186b3a.19.1773048984020; Mon, 09 Mar 2026 02:36:24 -0700 (PDT) Received: from deepanshu-kernel-hacker.. ([2405:201:682f:389d:cd95:c52c:1e0b:3ab7]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-829a48b437fsm9487994b3a.52.2026.03.09.02.36.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Mar 2026 02:36:23 -0700 (PDT) From: Deepanshu Kartikey To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, kees@kernel.org Cc: mingo@kernel.org, tglx@kernel.org, jiayuan.chen@shopee.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Deepanshu Kartikey , syzbot+f50072212ab792c86925@syzkaller.appspotmail.com Subject: [PATCH] atm: lec: fix use-after-free in sock_def_readable() Date: Mon, 9 Mar 2026 15:06:14 +0530 Message-ID: <20260309093614.502094-1-kartikey406@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A race condition exists between lec_atm_close() setting priv->lecd =3D NULL and concurrent access to priv->lecd in send_to_lecd(), lec_handle_bridge(), and lec_atm_send(). When the socket is freed via RCU while another thread is still using it, a use-after-free occurs in sock_def_readable() when accessing the socket's wait queue. The root cause is that lec_atm_close() clears priv->lecd without holding lec_arp_lock, while callers dereference priv->lecd without any protection against concurrent teardown. Fix this by: - Protecting priv->lecd =3D NULL in lec_atm_close() with lec_arp_lock to synchronize with callers that already hold the lock (e.g. lec_arp_resolve) - Using sock_hold/sock_put in send_to_lecd() to pin the socket while in use. This is safe because send_to_lecd() is called under lec_arp_lock by lec_arp_resolve(), preventing concurrent NULL assignment of lecd. - Using lec_arp_lock + sock_hold/sock_put in lec_handle_bridge() and lec_atm_send() where the lock is not held by the caller, with proper skb cleanup on early exit to avoid memory leaks. Note: Patch testing via syzbot was attempted but the test VM crashed due to a QEMU AHCI emulation assertion failure (hw/ide/core.c:934) unrelated to this fix. The QEMU crash is caused by syzbot's disk I/O fuzzing triggering a known QEMU NCQ emulation bug, not by this patch. Compile testing with "make W=3D1 net/atm/lec.o" passes cleanly. Reported-by: syzbot+f50072212ab792c86925@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=3Df50072212ab792c86925 Signed-off-by: Deepanshu Kartikey --- net/atm/lec.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/net/atm/lec.c b/net/atm/lec.c index fb93c6e1c329..7e051174a92b 100644 --- a/net/atm/lec.c +++ b/net/atm/lec.c @@ -131,6 +131,7 @@ static void lec_handle_bridge(struct sk_buff *skb, stru= ct net_device *dev) { char *buff; struct lec_priv *priv; + unsigned long flags; =20 /* * Check if this is a BPDU. If so, ask zeppelin to send @@ -154,10 +155,19 @@ static void lec_handle_bridge(struct sk_buff *skb, st= ruct net_device *dev) /* 0x01 is topology change */ =20 priv =3D netdev_priv(dev); - atm_force_charge(priv->lecd, skb2->truesize); + spin_lock_irqsave(&priv->lec_arp_lock, flags); + if (!priv->lecd) { + spin_unlock_irqrestore(&priv->lec_arp_lock, flags); + kfree_skb(skb2); + return; + } sk =3D sk_atm(priv->lecd); + sock_hold(sk); + spin_unlock_irqrestore(&priv->lec_arp_lock, flags); + atm_force_charge(priv->lecd, skb2->truesize); skb_queue_tail(&sk->sk_receive_queue, skb2); sk->sk_data_ready(sk); + sock_put(sk); } } #endif /* IS_ENABLED(CONFIG_BRIDGE) */ @@ -441,7 +451,7 @@ static int lec_atm_send(struct atm_vcc *vcc, struct sk_= buff *skb) /* hit from bridge table, send LE_ARP_RESPONSE */ struct sk_buff *skb2; struct sock *sk; - + unsigned long flags; pr_debug("%s: entry found, responding to zeppelin\n", dev->name); skb2 =3D alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC); @@ -449,10 +459,19 @@ static int lec_atm_send(struct atm_vcc *vcc, struct s= k_buff *skb) break; skb2->len =3D sizeof(struct atmlec_msg); skb_copy_to_linear_data(skb2, mesg, sizeof(*mesg)); - atm_force_charge(priv->lecd, skb2->truesize); + spin_lock_irqsave(&priv->lec_arp_lock, flags); + if (!priv->lecd) { + spin_unlock_irqrestore(&priv->lec_arp_lock, flags); + kfree_skb(skb2); + break; + } sk =3D sk_atm(priv->lecd); + sock_hold(sk); + spin_unlock_irqrestore(&priv->lec_arp_lock, flags); + atm_force_charge(priv->lecd, skb2->truesize); skb_queue_tail(&sk->sk_receive_queue, skb2); sk->sk_data_ready(sk); + sock_put(sk); } } #endif /* IS_ENABLED(CONFIG_BRIDGE) */ @@ -471,8 +490,11 @@ static void lec_atm_close(struct atm_vcc *vcc) struct sk_buff *skb; struct net_device *dev =3D (struct net_device *)vcc->proto_data; struct lec_priv *priv =3D netdev_priv(dev); + unsigned long flags; =20 + spin_lock_irqsave(&priv->lec_arp_lock, flags); priv->lecd =3D NULL; + spin_unlock_irqrestore(&priv->lec_arp_lock, flags); /* Do something needful? */ =20 netif_stop_queue(dev); @@ -534,6 +556,7 @@ send_to_lecd(struct lec_priv *priv, atmlec_msg_type typ= e, =20 atm_force_charge(priv->lecd, skb->truesize); sk =3D sk_atm(priv->lecd); + sock_hold(sk); skb_queue_tail(&sk->sk_receive_queue, skb); sk->sk_data_ready(sk); =20 @@ -543,7 +566,7 @@ send_to_lecd(struct lec_priv *priv, atmlec_msg_type typ= e, skb_queue_tail(&sk->sk_receive_queue, data); sk->sk_data_ready(sk); } - + sock_put(sk); return 0; } =20 --=20 2.43.0