From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.181 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796073154; b=aLrIMgdtEf0tgUnMHELLqqwr2bRJWyLfICS+EGRl7ddWNGcHPt/+RX9M1IfeSSQHFSTM Ek9IwAQVALc98TJJwq6amQo9H5o5wL5J3XrgBH17J0y41BGuiIAFgn3l8Vt6/R/tvtAlI VZDI76tyjDlN9LfaE4MEQDTZH8+/bPvlX1dD0JL3O3TaVo14otM3uUE6QMUpp9AJfBj/S KONP/Ca0cucJKJgKTNG9gHG6pPokpj77RTbl8uHj4LPFXEaSkLfPb7I8lv9a35kzHNy/W VfBBiZPydniqo/gyO1M31LZoeHwvkOIaAkj46xVZ4I4xPPopM9NDkMRh7i/s/3iwbLg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796073154; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=G1oXwFBNFBKaMqDl+HApsIBIW5Gz6OhFMCQMB7GAkXs=; b=V9QlmnMGO4WfRUyAuQoU8PpnQ+YPC6ur3rpZHiYmVSyiH3KMS+MQv0Sq+J6g8gs+JaSM jxdoHyBx6qdDssb2MXiA8gxK8kAM57/7rmmTHbew9tjfxQSeTA8CfXvP3Z1AsDJxXypbJ StTXbrnaEFnduiJAF9XHkpjAqxxbhOxAv2NFxLaY0kt2mAe2i2RJJJt3wFEyChcrxCB9d 4W+8D+UHq8p/JvD5rlBCXnW1DF6gEDz0OTzseYiN+7oRqFn55iALRoz0BS9M6IPvkWooi WWTpwJGT+vxuibEN0LWfoiXCbMtdrugeWWMIbhU0GC2TP5eRpVPZjwx715ftkOASdDQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=bO5MIq5v; arc=none smtp.remote-ip=209.85.221.181 Received: from mail-vk1-f181.google.com (mail-vk1-f181.google.com [209.85.221.181]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 28D58606A334 for ; Mon, 30 Nov 2026 21:12:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 28D58606A334 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.a=rsa-sha256 header.s=20260707 header.b=bO5MIq5v Received: by mail-vk1-f181.google.com with SMTP id 71dfb90a1353d-5ee3e658c70so3599357e0c.0 for ; Mon, 30 Nov 2026 13:12:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796073153; x=1796677953; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to:content-type; bh=G1oXwFBNFBKaMqDl+HApsIBIW5Gz6OhFMCQMB7GAkXs=; b=bO5MIq5v6f5lsDRgpQ6x0NQEjYGpUvb9UWxnHdZoj8Jgb9t/z2I/zez3LM503L4twk YEK0mWwShSc4Sjsf4NqE7HgV5iRR/4uRKJ0Xwb25Q8lGq6qing5TiTGPhZWPDu2sqO3r BIbVlKGEbkkMaC2SvtAKzObxyBA6FrBml4BlGps0fQTNW0AbFlx7tUlhlPXitN4/3MSR xiICyACHOzGwW/tO274fN1ApuUWTIt1w4TinisAht/vR59xh0enn+YKQ/dCPNU7mAu0p ILbvWg9T/To3MQ6YoKIQKcDn9GP+8DwvpJZwceDVwtAIWMUNj3/YIAaIMmWztg0Q9LBx f2sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796073153; x=1796677953; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to:content-type; bh=G1oXwFBNFBKaMqDl+HApsIBIW5Gz6OhFMCQMB7GAkXs=; b=s1U/kkczkRGhET7Kus0cUDioBjIK+c6pBPPTFtUfM/Hcipn+voqM6JisoXFLEf4X2f QNwNAcp+QfWlTq9YkYPpR8V84hbg9wEIVx/Ie0HYRMrYi68Sc/tOyVjiktu834mh5xiQ 4MqixI84ak45vzdj49gYSPsDiD9KMb0v1tfRdXvjDqXkY2s2dzoilEOSE4BR3UhDpzJ2 R39Vx5p6bXTHqhI0E/T7DqOIhxTetj+3HhYR//AFlzT11OQIlLGx8lsE/g1A+JmVn6Q2 GjJ6wPQs9NGsWI96MB3QUEZiZSCbS6Y0ZkXsghMXDiC3wwWQlVIiPw5wrYBYCy+c51Zx n5bg== X-Gm-Message-State: APuU4Z9UlsjTqIeVwcfve5XQLSb4Ga/uFo5vM+6/+QlatyQbnGzVPZCC gW6ei2O0ptBDQHXM4lmzydhm2+HB2QRqXGjCJqsZtemDVo1LRFrD/VuL1eNuw1mNsmI= X-Gm-Gg: AZFdTZcvmxnGkZaJtSqTbFnMfwr96GqGJSwWCLi3GAj5xkvldzI0BAeaNdJf4mW4jlE EROnRNN1y52qFg1fLZVavs9SXf23OdrVBDhTU79K/Za8yeNu1MQgsKoRsg0e2Jb9G0fkBt9OeMv WZO0CPu3GU7XY80MNvGrJn3VRNsYaC0EiA6I+yig6mQ39yBE4vA0nJ4qjScV9/gb1Czb2U4nsfp xBKQSau9lwts7MoU60Kt5li1xNFfOyi6R3jlaDFUbyB4sGcM8lRJFQE3EDxKX7TVmCwVVw63DFt 59geo2Qu9jTHGdYkJnwrA+wMRF+i4F0QMhRiYd92VYFGc/do6M9UuUUT2iu31+fr0nNWJ2cIrde 0Rb5XsnpOcEyVVfmge80E/2xOiRqdjNOmWRwCA0wZkBA6YDz20cNVeRU8WwsHHN3wPQvkTQXBur mBoubF0RcUh/Gkpc8/k9sDI1X82PRSMmXIoDa8FG0ie59P4oiUFCITsp74Gz6dFCN7Jv3+dwOk8 hDxU3GNM2SIxkE4GBe1uV8OHkOFUXEw3A+uEcxHLDyVVBYJrj7XDI3n91z6QrP9eJha+615xNET z8NEUwj6ykPBmAtZGo/6E/LHopfrSoOI4wrdf5jMkvFhP/or4Pf19S1ukpcj0ksT83KBDnrwkqL H1cg6qTU63y3awn8hUDVh29B8h86TSGpo38W4tV2qBM9n/nEF8TlsOwxfdYuVzNl6mu/zWTT2Oa FeCuk2+2jMTgyB4iMCPpsbwrBO X-Received: by 2002:a05:6122:288a:b0:5c9:c60e:3a40 with SMTP id 71dfb90a1353d-5ee8af56a83mr26095970e0c.18.1796073153029; Mon, 30 Nov 2026 13:12:33 -0800 (PST) Received: from lvondent-mobl5.taila91cb8.ts.net ([72.188.211.115]) by smtp.gmail.com with ESMTPSA id 71dfb90a1353d-5ee8b609bc7sm35472261e0c.12.2026.11.30.13.12.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 13:12:32 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v9 3/5] Bluetooth: L2CAP: Fix leaking sockets released before their channel is deleted Date: Mon, 30 Nov 2026 16:12:26 -0500 Message-ID: <20261130211228.621145-4-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261130211228.621145-1-luiz.dentz@gmail.com> References: <20261130211228.621145-1-luiz.dentz@gmail.com> X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Luiz Augusto von Dentz When a socket without an owner is closed while its channel is still around, l2cap_sock_kill() doesn't kill it since it is not flagged SOCK_ZAPPED yet, which only chan->ops->teardown() does. This happens with deferred Enhanced Credit Based channels refused while other channels of the same request are still waiting to be authorized, either by userspace releasing the socket or, for the ones never accepted, by the listener being closed. The channels that are deleted by something else afterwards, like l2cap_ecred_rsp_defer() does once it sends the response that includes them, don't call chan->ops->close() either, so nobody kills the orphaned socket anymore and it is leaked along with the references it holds. Fix this by calling l2cap_sock_kill() from l2cap_sock_teardown_cb() once the socket is flagged SOCK_ZAPPED, which only kills it if it has no owner. The ones closing the channel afterwards do nothing since the socket is no longer linked to it. Fixes: 9aa9d9473f15 ("Bluetooth: L2CAP: Fix responding with wrong PDU type") Assisted-by: OpenCode:claude-fable-5.2 Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/l2cap_sock.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c index d5663a4642a9..ec5d25067bc5 100644 --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c @@ -1800,6 +1800,16 @@ static void l2cap_sock_teardown_cb(struct l2cap_chan *chan, int err) /* Only zap after cleanup to avoid use after free race */ sock_set_flag(sk, SOCK_ZAPPED); + /* A socket without an owner, either because it was released while the + * channel was still around or because it was never accepted, can't be + * killed before it is zapped, and nobody else will once the channel is + * deleted by something else, e.g. the response of a request that + * included it, so do it now. l2cap_sock_kill() does nothing if the + * socket still has an owner, and the ones that close the channel + * afterwards do nothing either since the socket is no longer linked + * to it. + */ + l2cap_sock_kill(sk); } static void l2cap_sock_state_change_cb(struct l2cap_chan *chan, int state, -- 2.56.0