From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.180 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796068621; b=k96HjPbZGzLAQP96+I+4cJDNRHNDsjsm5Vb6WJVht2vDbHm1uCsmQWy8D99SdYYuNstf CeDXfUGqaTuu0w6ZvFnsN0qpmzCdqCoJJUII/m8NUwtWcPFQVWlr7r2qpDOUW2VYerLtk d9sJejjjyP+XvfCRu/MfOUQAVVIIM0S04rulBjk3gtL+naLpAGknTZkTEsKty6yqIU6qw bghZ/sjEXQslQnPLwjJ2GxpOSl65+JvN9bnX4KFxg0ykDI/5E+PN9Ublr4azkhxhJre2/ aeVPASJCygsQ29Yj9d4gbnAmavg+tERryZilll1msvSk6Akx0X80KuzUDg1TP9wA55A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796068621; 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=RvQRSr5XOA02KhSu3l2r2NF6Am2XDh04BUTUGyDCajWykwW2xqfbMBm2jUNtgWavbj7Y 3WgsjaykICoUEnPrCSkHEUyAzPOQlTemBhJtWXbFqB/9Yh2REc7xKxzBnNQ+jFEdmULpn Ly0mhPh6EnB4c4eOqWmcKBIzDG2eaPPGUv6hdg7n7XG7qtwE6UxLqZrIzcE6gI+1nEbIZ Ug6F7cGedRMbANv9k8vViGYOnodtiEBwBnNfd4rliWB8cYLEHIxP1Kl/tOjG+YEbKHrga aOLJmJNo9PirUangQFgTpe9sPga58AXlKALHM7+actU7L+E+wefaSgt4QScKvxdgvQQ== 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=f4HRMwlj; arc=none smtp.remote-ip=209.85.221.180 Received: from mail-vk1-f180.google.com (mail-vk1-f180.google.com [209.85.221.180]) (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 77BF9606A329 for ; Mon, 30 Nov 2026 19:57:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 77BF9606A329 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=f4HRMwlj Received: by mail-vk1-f180.google.com with SMTP id 71dfb90a1353d-5eaabf28c06so7226490e0c.2 for ; Mon, 30 Nov 2026 11:57:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796068620; x=1796673420; 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=f4HRMwljZPLVNosaqHWj6ClxaLLcfuaLIT0TWSOtCE/rwHvh0XOGsMVtISq/OHoWZh FTitYTSqqTtMkkHAm1d24yDlmzLfRD/ycvg2KBVwG9caDKLWwDuvyET/GnYzvMsHfxUS B8m2A9JyIb4DvEBi3zfWWWlk7NA0lBXF8GQ/P8EWdOvXm9WLwld3TGKqbSY+UJZw5K3+ MxMaYAhca8fBg8/wV+Bue4XmYw4B05b+s5ajl2TtDJIHCFh11DoB/RAVfYFO8JWEHnhF qpabZJqkfNtyvWbv+AmXDx84p7E8xB0xwDWPIiRtkbczqpU+iJZf0fT5qzXOG+98ZxvE VL+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796068620; x=1796673420; 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=wiE5eXjGSXpet+2KYlrqs9g4aURit98eFb72N669AfDaFfG2MfHQ5bBfIKrjeesvc7 mPEcztJYxfRSQUjIhKiEtt/cbQEf4kvt9wPk+PEx+rgoLhy1Jnn+W4D8ZsAmdzSxYZkx wDbsL2T7NXJYq0UXsUZcXCAHiK1xwj/1becmliRxKQBA40vCQ1hS/OsdbbOroVDD3kzM KP6W6zdGg8hHh8J7+TNV5BoNA9lDPbfhznHcdmSKIRhveEZM3Qs/QwLjwGTQg8EWTg59 drn/cxVJBQqvRiJ+epUkKt3Dh93StyMi8HWMbfjRVO86VYb0gcNn6/mKunmogNjtMHal al6Q== X-Gm-Message-State: APuU4Z8flgo8+fc+2X7JW4J7ac62DG3ZqwroqxjO6Bk12ioVt6kZ59aF DQFnGOGb/zTo/LEjxKRGr1eQNWU1eN3lqjJlO5MVl+rIB5vukRJiQdZy3Zg3DWH9 X-Gm-Gg: AZFdTZe+SUavq8Uk2s3WyqIzL3T5n9GcgOHW+euvRcA1NYNHdF7lxtcwwUC54Rpofm6 ae+dyLK7dcLgfd/JPOKd3ELNYfLtkAbVOjA2aGdZ8xIMBdAYw8o5kHgNWMFzk/YzswqRQB2gAt6 WnnHXH/Z6i7bheSTBuEg+yZduZ8CSMJBOZ1XweW02k//vdgZ/vP3lhHM8Opt36s2MXghtzwKgFM TgjQvPvcAtmlf1NeQb7GhHnbJCNNANvB2p7adA6dh63szk76HgIMofvZp1cO3S1SM3DZiRNd+vv m52lpwYLTGw0bHpvargSLnPfLBhmAtL4NZNrfQaZhzlPfL9ZrnOdOgntWqfwCBbLeJNFvqNV4+G P/QceERqEvSfP3qrdQIE5YUoeEX9uqt15aOu8xb3hCOU+ADeRVdkVnQGZUw5wLAu9kYqny2C6rU te3gZVev2obfMpD78c7Y7N55C/A/aw0xN3VWSXUzL0fGfBzlj5AsGnb3oqNkBHtQmAJ8VnkTbEJ nfiFzVaeKIDkI3nFKSYcA+cflKzr0bsSZwuuRC7NqPvs1OwIgU+Rjb+tJMYbf+KK1koKimmZkEj d/M8SIdDallGmuaVlqRnOcx6M4K4JMw571KmEmq8p4mBF4Oovmg9mdbjCnshpZD1WBsOfXOVksv khA1kFMFalA35bxXwGmSxPubkWh5d/4sgnYGsbuaAXIzGT2kSfxthNhvUnvr5e64BGmhpkY73IB qCxNMr X-Received: by 2002:a05:6122:2897:b0:5ea:be1b:1b66 with SMTP id 71dfb90a1353d-5ee8ad10ac3mr22890937e0c.0.1796068620322; Mon, 30 Nov 2026 11:57:00 -0800 (PST) Received: from lvondent-mobl5.taila91cb8.ts.net ([72.188.211.115]) by smtp.gmail.com with ESMTPSA id a1e0cc1a2514c-99e6dec7cb5sm36694016241.2.2026.11.30.11.56.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 11:57:00 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v8 3/5] Bluetooth: L2CAP: Fix leaking sockets released before their channel is deleted Date: Mon, 30 Nov 2026 14:56:52 -0500 Message-ID: <20261130195654.560637-4-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261130195654.560637-1-luiz.dentz@gmail.com> References: <20261130195654.560637-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