From nobody Thu Apr 9 10:29:04 2026 Received: from mail-oo1-f72.google.com (mail-oo1-f72.google.com [209.85.161.72]) (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 C5F6C3CE4B2 for ; Mon, 9 Mar 2026 15:20:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.72 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773069647; cv=none; b=my4090MyW9nTZC7Gp7TizU3BMpvyVTlvmLT7m3iwbw1LyWzlMwW66VYvVKYM77AlH1o8+4rAdrrgByf8mFDl+Yvx48mIffPvdneZGjIgjGa2aBYpOcXCxmY1RWSXzhzEKPDxqYCkCB76dg56YFPV9Tggot7fxDnev/o0By90kxE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773069647; c=relaxed/simple; bh=DKkvkd2qF/ZNUmCyBIBzFv0gT0n1x+Qc75nZUi509m4=; h=MIME-Version:Date:In-Reply-To:Message-ID:Subject:From:To: Content-Type; b=nNk7oDEVvcl0i93wE1cvS5Lj+tc6h2o+HZd/Fhy0FxnEp6G5qnIs2KEPSLS1VsiAlAAaF//3fzfwJD5zlmouS2/bEtrqb7xlXYs7aJn+zr0sOwI6tf72NdD1O1h3mTPYzNXyWRrjGgPhlw3sn/F8D0UycangpH+2XfPhZuQ/fuQ= 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.72 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-f72.google.com with SMTP id 006d021491bc7-67bb368c757so15740647eaf.3 for ; Mon, 09 Mar 2026 08:20:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773069645; x=1773674445; 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=D3J2E1d9i9JevxsfH+BJ+3RGKPnF7Fb9s/y4ogQQX5A=; b=OM4jW98io3XNBqpiqvoj4QvG76gQGYyY3SpKSZLNt2OavvTFWEvOpbXx3CBYiOY8kh 4xwxubj5h7/pn/76j0i+v82sVmqZfnuA7ksqlCEr9X9vDn0DaY0/98007/m/KBZZo3tn 5lShKt+AKsy6Z2SVa2vJvlYwpy69skZkG6E4BSuV3gU6ojk88zFq+udZeeOMIs6odslZ gIQMuVWvYvjycprqZ4/ryLovpA/eT5w0k5ru1MmqUvYRembbBhbSfdM4Fu8kxOfNCKoq cHLcLbicqNOK35ZbjTk6PyiinPBXo53dBTYW+Vl0t9HlBICYsSyUqRzq3Qq9GJjbA7MS wp0g== X-Gm-Message-State: AOJu0Yy3vGEMlsgGf7zsp+nKLouQOGYz/+IbW9I8BndAcDJcrDC6L5iQ ApWspsbZMQ7J/KpGS/aHG9Yxam7rNCIZqLTFj4+TSmUaFpNK1jxEVSyzP12WSyfoj3bY1GVWTWQ G3kNMoozZtUaocu6pQrebECXzTC4Xlwj3yGzHIQJtZW8eoAQglmkfQ14G7FU= 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:982:b0:67a:1bf4:eb03 with SMTP id 006d021491bc7-67b9bd1b13cmr7852606eaf.45.1773069644788; Mon, 09 Mar 2026 08:20:44 -0700 (PDT) Date: Mon, 09 Mar 2026 08:20:44 -0700 In-Reply-To: <69ad7ccb.a00a0220.b130.0003.GAE@google.com> X-Google-Appengine-App-Id: s~syzkaller X-Google-Appengine-App-Id-Alias: syzkaller Message-ID: <69aee54c.050a0220.310d8.0029.GAE@google.com> Subject: Forwarded: [PATCH] atm: lec: fix use-after-free in sock_def_readable() 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] atm: lec: fix use-after-free in sock_def_readable() Author: kartikey406@gmail.com #syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git= master A race condition exists between lec_atm_close() setting priv->lecd to 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 any synchronization, while callers dereference priv->lecd without any protection against concurrent teardown. Fix this by converting priv->lecd to an RCU-protected pointer: - Mark priv->lecd as __rcu in lec.h - Use rcu_assign_pointer() in lec_atm_close() and lecd_attach() for safe pointer assignment - Use rcu_access_pointer() for NULL checks that do not dereference the pointer in lec_start_xmit(), lec_push(), send_to_lecd() and lecd_attach() - Use rcu_read_lock/rcu_dereference/rcu_read_unlock in send_to_lecd(), lec_handle_bridge() and lec_atm_send() to safely access lecd - Use rcu_assign_pointer() followed by synchronize_rcu() in lec_atm_close() to ensure all readers have completed before proceeding. This is safe since lec_atm_close() is called from vcc_release() which holds lock_sock(), a sleeping lock. - Remove the manual sk_receive_queue drain from lec_atm_close() since vcc_destroy_socket() already drains it after lec_atm_close() returns. v2: Switch from spinlock + sock_hold/put approach to RCU to properly fix the race. The v1 spinlock approach had two issues pointed out by Eric Dumazet: 1. priv->lecd was still accessed directly after releasing the lock instead of using a local copy. 2. The spinlock did not prevent packets being queued after lec_atm_close() drains sk_receive_queue since timer and workqueue paths bypass netif_stop_queue(). Reported-by: syzbot+f50072212ab792c86925@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=3Df50072212ab792c86925 Link: https://lore.kernel.org/all/20260309093614.502094-1-kartikey406@gmail= .com/T/ [v1] Signed-off-by: Deepanshu Kartikey --- net/atm/lec.c | 70 +++++++++++++++++++++++++++++++++------------------ net/atm/lec.h | 2 +- 2 files changed, 46 insertions(+), 26 deletions(-) diff --git a/net/atm/lec.c b/net/atm/lec.c index fb93c6e1c329..32adf28663a0 100644 --- a/net/atm/lec.c +++ b/net/atm/lec.c @@ -154,10 +154,18 @@ 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); - sk =3D sk_atm(priv->lecd); - skb_queue_tail(&sk->sk_receive_queue, skb2); - sk->sk_data_ready(sk); + struct atm_vcc *vcc; + rcu_read_lock(); + vcc =3D rcu_dereference(priv->lecd); + if (vcc) { + atm_force_charge(vcc, skb2->truesize); + sk =3D sk_atm(vcc); + skb_queue_tail(&sk->sk_receive_queue, skb2); + sk->sk_data_ready(sk); + } else { + dev_kfree_skb(skb2); + } + rcu_read_unlock(); } } #endif /* IS_ENABLED(CONFIG_BRIDGE) */ @@ -216,7 +224,7 @@ static netdev_tx_t lec_start_xmit(struct sk_buff *skb, int is_rdesc; =20 pr_debug("called\n"); - if (!priv->lecd) { + if (!rcu_access_pointer(priv->lecd)) { pr_info("%s:No lecd attached\n", dev->name); dev->stats.tx_errors++; netif_stop_queue(dev); @@ -449,10 +457,18 @@ 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); - sk =3D sk_atm(priv->lecd); - skb_queue_tail(&sk->sk_receive_queue, skb2); - sk->sk_data_ready(sk); + struct atm_vcc *vcc; + rcu_read_lock(); + vcc =3D rcu_dereference(priv->lecd); + if (vcc) { + atm_force_charge(vcc, skb2->truesize); + sk =3D sk_atm(vcc); + skb_queue_tail(&sk->sk_receive_queue, skb2); + sk->sk_data_ready(sk); + } else { + dev_kfree_skb(skb2); + } + rcu_read_unlock(); } } #endif /* IS_ENABLED(CONFIG_BRIDGE) */ @@ -468,23 +484,16 @@ static int lec_atm_send(struct atm_vcc *vcc, struct s= k_buff *skb) =20 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); =20 - priv->lecd =3D NULL; + rcu_assign_pointer(priv->lecd, NULL); + synchronize_rcu(); /* Do something needful? */ =20 netif_stop_queue(dev); lec_arp_destroy(priv); =20 - if (skb_peek(&sk_atm(vcc)->sk_receive_queue)) - pr_info("%s closing with messages pending\n", dev->name); - while ((skb =3D skb_dequeue(&sk_atm(vcc)->sk_receive_queue))) { - atm_return(vcc, skb->truesize); - dev_kfree_skb(skb); - } - pr_info("%s: Shut down!\n", dev->name); module_put(THIS_MODULE); } @@ -510,12 +519,14 @@ send_to_lecd(struct lec_priv *priv, atmlec_msg_type t= ype, const unsigned char *mac_addr, const unsigned char *atm_addr, struct sk_buff *data) { + struct atm_vcc *vcc; struct sock *sk; struct sk_buff *skb; struct atmlec_msg *mesg; =20 - if (!priv || !priv->lecd) + if (!priv || !rcu_access_pointer(priv->lecd)) return -1; + skb =3D alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC); if (!skb) return -1; @@ -532,18 +543,27 @@ send_to_lecd(struct lec_priv *priv, atmlec_msg_type t= ype, if (atm_addr) memcpy(&mesg->content.normal.atm_addr, atm_addr, ATM_ESA_LEN); =20 - atm_force_charge(priv->lecd, skb->truesize); - sk =3D sk_atm(priv->lecd); + rcu_read_lock(); + vcc =3D rcu_dereference(priv->lecd); + if (!vcc) { + rcu_read_unlock();=20 + kfree_skb(skb); + return -1; + } + + atm_force_charge(vcc, skb->truesize); + sk =3D sk_atm(vcc); skb_queue_tail(&sk->sk_receive_queue, skb); sk->sk_data_ready(sk); =20 if (data !=3D NULL) { pr_debug("about to send %d bytes of data\n", data->len); - atm_force_charge(priv->lecd, data->truesize); + atm_force_charge(vcc, data->truesize); skb_queue_tail(&sk->sk_receive_queue, data); sk->sk_data_ready(sk); } =20 + rcu_read_unlock(); return 0; } =20 @@ -618,7 +638,7 @@ static void lec_push(struct atm_vcc *vcc, struct sk_buf= f *skb) =20 atm_return(vcc, skb->truesize); if (*(__be16 *) skb->data =3D=3D htons(priv->lecid) || - !priv->lecd || !(dev->flags & IFF_UP)) { + !rcu_access_pointer(priv->lecd) || !(dev->flags & IFF_UP)) { /* * Probably looping back, or if lecd is missing, * lecd has gone down @@ -753,12 +773,12 @@ static int lecd_attach(struct atm_vcc *vcc, int arg) priv =3D netdev_priv(dev_lec[i]); } else { priv =3D netdev_priv(dev_lec[i]); - if (priv->lecd) + if (rcu_access_pointer(priv->lecd)) return -EADDRINUSE; } lec_arp_init(priv); priv->itfnum =3D i; /* LANE2 addition */ - priv->lecd =3D vcc; + rcu_assign_pointer(priv->lecd, vcc); vcc->dev =3D &lecatm_dev; vcc_insert_socket(sk_atm(vcc)); =20 diff --git a/net/atm/lec.h b/net/atm/lec.h index be0e2667bd8c..ec85709bf818 100644 --- a/net/atm/lec.h +++ b/net/atm/lec.h @@ -91,7 +91,7 @@ struct lec_priv { */ spinlock_t lec_arp_lock; struct atm_vcc *mcast_vcc; /* Default Multicast Send VCC */ - struct atm_vcc *lecd; + struct atm_vcc __rcu *lecd; struct delayed_work lec_arp_work; /* C10 */ unsigned int maximum_unknown_frame_count; /* --=20 2.43.0