From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) (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 7388A345CD3 for ; Mon, 13 Jul 2026 10:47:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783939677; cv=none; b=QPwYvMJMBuwm3St/Q6fadLH3WqMotA7GTEnaJrqwbA/V3w775ATADLQYT/2xcbDCcaHAFDCd04q0N0g29ZWitcrJdH7bNUcNjVEapIF1W0H+CRZFhIcmvjN0vkRm3SQB52n7HFJTZdgqvetbICw2KEdBqdgqV07+j0UT6eUQdT8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783939677; c=relaxed/simple; bh=GxG/GDWpn5mwK1tIal/l0Dw5POK+wIXBW12wM/0SicE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=dg+rhR361aM+gCHTF49o8fBZ3LmO/jlJkGthbujFC8ongWizs8RX+EysMYupTofiGju4pNhVT0Okps+QCakjeU/KroPooBuTO6EfFD9vFiZs1mQvSM+oMOLPRXS6CHgiOrVBe9trc0Z6ywX6BsYh6aS+emtBOTZ4KvDWLaGwrNc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=trailofbits.com; spf=pass smtp.mailfrom=trailofbits.com; dkim=pass (2048-bit key) header.d=trailofbits.com header.i=@trailofbits.com header.b=SCNJLHdV; arc=none smtp.client-ip=209.85.222.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=trailofbits.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=trailofbits.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=trailofbits.com header.i=@trailofbits.com header.b="SCNJLHdV" Received: by mail-qk1-f171.google.com with SMTP id af79cd13be357-92e6391b114so203487485a.3 for ; Mon, 13 Jul 2026 03:47:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trailofbits.com; s=google; t=1783939674; x=1784544474; 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:content-type; bh=djDZZW+WjRlIj682sN8PrAtMnjaRhZOc5mbUij8u74g=; b=SCNJLHdVIYR2vI17FYhRc6vMgRd72AMHsMdRQ2KdsC2Klv15BaH19iXc/C0zJDHJnV 13LKalp32u9aLgo83/OlgzCrRH/y2bKncA2TqrT72u793a//UnkIHQx3YYlWvvZolQRL YetGEv/2CoaxkYzO2UN+cEzHndQhLyywNBYIppkE7OwEk9LSiUaPMhDjkiTUM6oQwgib Xv/jYw5nBqXpfRNxW4Ec/C24bSerdnlm/00lkVWCtAziw6f/hQiwef98V8eGi8e1E80x V+Qik5b7VOgrVcZoo0TEsScFDeedDSBLp83T5XegPuLFBIMbJkBIjmJO3s5qlOoTcb7j /bDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783939674; x=1784544474; 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:content-type; bh=djDZZW+WjRlIj682sN8PrAtMnjaRhZOc5mbUij8u74g=; b=WigNcFeEF1qLdCjaQkR/TC7f2ubsDWdLQ6TEDQFA53vswNo2mp8iHwhWod/mBOYqnf BlCeHAW5n6FPDpFgZrVJSK3KO22sW15b4DAdY/Lwf/vyssBPlV6uZJvfJKmyYuZfStyv Hx94UYuCwe47MBbmNja9zhLaP90widtem9W88emGE3lll4Doe5X6t5Ye0MY8IEAwJGLZ 3S/HVqRCIEl1119GpGXZMeQghIFZIBbT1YzNOi1EiQ7KGYHOhiVBatUZJzAx5NSHM4eX MoOIc39sE+6VJZSrvDmZuza1+hoGwAg2g3f39e6gzB9M1yvSyrcsXePS+8AYVTJjv2hh T5OQ== X-Forwarded-Encrypted: i=1; AHgh+RrKhZ+g1Irez5BrJenwbp5obLg/K1qJPMj3KHYWVS8UyVa4XK775UKRSOuE2BKysqQ6S+RpjZCKjRs8FaI=@vger.kernel.org X-Gm-Message-State: AOJu0YwKZ3ON70xrX+c28iD9cvvmeEyxaukYK0/RlstOV4Rp3uWrWrny CLnDy1huBec/LetOlK4btAl9ZkDd4K2O6DELBDvmPqD7OEhMVwPB48sodTHXtwsB8uI= X-Gm-Gg: AfdE7cnLOlTkUz1nPOOAdvOPu5+JzDqiY/fvHpN4mKL2mlKYq7BpTiDixGm7rUti4hk kEFlmsLjZNidIc18I8a1qFeqNTfXAAuYEItpC68xsaxTbig1eqSVs9ewOD7pNjIe1Ths2wO1Zhv jt4U56BCjXaflgIfedWgQgGLrwsrEJfw4dKdBuLu/n/zng7SPc2YY0FItvKrCL2R1MiivwSar/Z 95/8xPw9dQL/iaf+plCIozJIZ6Llw5+KSZPhNwf6XfiKYP0+AeluzWRr05pFcwbEnM0k3wkCVJG ZFkTvAfk0gZEBhXeJ0822aEEg1b4qosY6B0oi6hpD2SWXF2dXXtDa4s+Dxmm0oRhW9sa4Tx75Nv xbWJdNurnZa6ig9WYVKbIcgvhNa7oQIqoyS7Eac4ThwV0l+TQ7UK9NKLpJdTVSCu0/2A2ygCr3h xG1WzCMoV4ddDjUR+/qg== X-Received: by 2002:a05:620a:25d1:b0:92e:71bb:d1ac with SMTP id af79cd13be357-92ef2aeb554mr848155785a.19.1783939674393; Mon, 13 Jul 2026 03:47:54 -0700 (PDT) Received: from localhost ([146.190.222.192]) by smtp.gmail.com with UTF8SMTPSA id af79cd13be357-92ee59223e7sm1031429685a.0.2026.07.13.03.47.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 13 Jul 2026 03:47:54 -0700 (PDT) From: David Lee To: Martin Schiller Cc: David Lee , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Dominik 'Disconnect3d' Czarnota , linux-x25@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH net] net/x25: fix use-after-free in x25_kill_by_neigh() Date: Mon, 13 Jul 2026 10:47:50 +0000 Message-ID: <20260713104752.241175-1-david.lee@trailofbits.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: 8bit x25_kill_by_neigh() walks the global X.25 socket list looking for sockets attached to a terminating neighbour. x25_list_lock protects list membership while the lookup is in progress, but it does not pin a socket's lifetime after the lock is dropped. The function currently drops x25_list_lock before calling lock_sock(s). A concurrent close can run x25_release(), remove the same socket from x25_list, and drop the last socket reference in that window. The neighbour teardown path can then lock or inspect a freed struct sock/struct x25_sock. Take sock_hold(s) while x25_list_lock still proves that the list entry is live, then drop the temporary reference after the socket has been locked, rechecked, and released. Recheck x25_sk(s)->neighbour after lock_sock(), because another path may have disconnected the socket before this path acquired the socket lock. Restart the list walk after each disconnect because the list lock was dropped and the previous iterator state may no longer be valid. A QEMU/KASAN run against origin/master reproduced a slab-use-after-free in x25_kill_by_neigh(). Fixes: 7781607938c8 ("net/x25: Fix null-ptr-deref caused by x25_disconnect") Cc: stable@vger.kernel.org Signed-off-by: David Lee Assisted-by: Codex:gpt-5.5 --- Trail of Bits has a reproducer that triggers kernel panic demonstrating the bug, and can share it if needed. net/x25/af_x25.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/net/x25/af_x25.c b/net/x25/af_x25.c index c31d2af5dd22..8aae9273b7c1 100644 --- a/net/x25/af_x25.c +++ b/net/x25/af_x25.c @@ -1768,15 +1768,19 @@ void x25_kill_by_neigh(struct x25_neigh *nb) { struct sock *s; +again: write_lock_bh(&x25_list_lock); sk_for_each(s, &x25_list) { if (x25_sk(s)->neighbour == nb) { + sock_hold(s); write_unlock_bh(&x25_list_lock); lock_sock(s); - x25_disconnect(s, ENETUNREACH, 0, 0); + if (x25_sk(s)->neighbour == nb) + x25_disconnect(s, ENETUNREACH, 0, 0); release_sock(s); - write_lock_bh(&x25_list_lock); + sock_put(s); + goto again; } } write_unlock_bh(&x25_list_lock);