Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp230481pxb; Wed, 11 Nov 2020 02:07:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJxmaKuzQzk/DGEOysFXvyPOux/7YTA9xExbv5pz3GFqeuP7x6uU4yJtSjEjXkYTyoKT7GmH X-Received: by 2002:a50:de45:: with SMTP id a5mr25324672edl.91.1605089227536; Wed, 11 Nov 2020 02:07:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605089227; cv=none; d=google.com; s=arc-20160816; b=WYASdicYPB4lH9gVSI/lRs6I3irw4lb6Y4EqAEau6Uj9clVQ71FlQoJ1u/pyIyUOkx yEPzYm/lJiCoqqhHVE6tMH4YSNWIfy2noLGdhDi4oatvkut6xpKmLBhNqquZ1UGC/RsX fjWS19vQEvbWXpF/qdMnjlOeTM2izsePNoqOe/6fIq5T0GNMdHy291JFkz1afafAfJM9 +CMVSOD+gQqKs4JMxZzVSbnMUCjG+A+sVliX/aORG8qbVzg4pv94wI/4d0GTwZLCq+/v /RFIxBztIMQRb2S0kcY8YqIcO/qnX2ybUl887Y2ciNMgxnTH6J/KM7kodrc4fdPL9Y5T qr2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=9rZwIqZztwOL1U6m2Ih25e7+ck0jlI4vUSseVss+TsI=; b=maB5RIsBItbwTFTRtGnVXEn1UD4d+BIhXLoprsOWvTU0d//Kb+5SMoIV4orL5X7CP4 qX8I7vx4/ZAYtS5+DhbwSoR2WmybK7rnnRKt5YG3nBQ0ZY/KuxBXqBOF1kWFEsVLX130 xlCbrv95i01vg7aB00E2MZ2vVfPzCRp4rnkaiqQ3ro2fJ39TETkDHLm8yeioP9iQa0oU fty19nr4jqh9/tjKUCCTw57kvfvM+T8ep+YD0/OnrADR6XcAfAh/VzC33K3Ga0TLXuoF kc1D+bSe4aQbI+mJePSGJ68to/6sgg/gRR+CAwdEcilefJckjQO9lj1tN0kX5p1rX4E0 nPJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DfHz+bYF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m18si941926ejb.604.2020.11.11.02.06.40; Wed, 11 Nov 2020 02:07:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DfHz+bYF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727000AbgKKKEl (ORCPT + 99 others); Wed, 11 Nov 2020 05:04:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726054AbgKKKEk (ORCPT ); Wed, 11 Nov 2020 05:04:40 -0500 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67CD0C0613D1; Wed, 11 Nov 2020 02:04:40 -0800 (PST) Received: by mail-pg1-x544.google.com with SMTP id i26so1147798pgl.5; Wed, 11 Nov 2020 02:04:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=9rZwIqZztwOL1U6m2Ih25e7+ck0jlI4vUSseVss+TsI=; b=DfHz+bYF6uF4L6ciowIpNlMAzhpE83IECESzcYrTD4zb0Ox8K7aPr0xjiUNxl2vKsw pqkg+dnSWBqkRBmm0g8CBJ67jutIS1a/wekg68W5eIPJIFa94ZA+tvQkuNInZQNJngxz Z48I5hL4PKMZR3XkkDpbRaF7ixv9aikZy5tYtHFHQ4hbFaUtJw1aUcSl+IajSqE3RGks bK2ejNsHu5e4+DV0WdwblF5+iNIu8XPzTJDUTlok7kPNEchEhirx2zmhwqfy23x9l7Sq ml5DMvx/3KLgeX9rLvhqwOqqbHyPthoKrIPRwAsy2hq8yR45zJ3GUHCpQLpXHd6I1s4M 1F7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=9rZwIqZztwOL1U6m2Ih25e7+ck0jlI4vUSseVss+TsI=; b=HOkfZoToG0zv8qeOeWBRevEZtDqrYIsqydG7/I9fp8EDedn5cQVX9JVHOWLG4WrSuK wrXCLPj8miXBZjy6uyLFL4a9ags9Ad/+hWb4go9RlVaOqafxJl2f1OnUYNUR9r7GlB3W c9kFvhbmPoj/Wna3/l4tfd+8EXOwhBQKAoSR0hvEVQgR+m5RDEmnDeeYw+K8cTcAdL7s +wCZ4otzePCKs68aj7wOsaXi4scOtBXtdwcXJxs/Lx3w/ytnj7VhwV8wMyuY1TbLHSOF 6G5jzb0Xuby56+1YC8iZx4AZv5WqLySPD+w4kgfpqgftwOZogJheWPS0gI4FTsiHOFZt BSJg== X-Gm-Message-State: AOAM5333bfD2xgPXDt4jO1e4bjQ+ybtkdH+YQGBtd6HspstDkLwqhRUQ CFkm6gFQUfZf2l0k4IB+Dcs= X-Received: by 2002:a62:2c16:0:b029:15d:8d2:2e6d with SMTP id s22-20020a622c160000b029015d08d22e6dmr22600604pfs.52.1605089079849; Wed, 11 Nov 2020 02:04:39 -0800 (PST) Received: from shane-XPS-13-9380.hsd1.ca.comcast.net ([2601:646:8800:1c00:5320:802e:3749:ff39]) by smtp.gmail.com with ESMTPSA id y3sm1870769pfl.77.2020.11.11.02.04.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Nov 2020 02:04:39 -0800 (PST) From: Xie He To: Jakub Kicinski , "David S. Miller" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Martin Schiller Cc: Xie He Subject: [PATCH net] net: x25: Fix kernel crashes due to x25_disconnect releasing x25_neigh Date: Wed, 11 Nov 2020 02:04:24 -0800 Message-Id: <20201111100424.3989-1-xie.he.0141@gmail.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The x25_disconnect function in x25_subr.c would decrease the refcount of "x25->neighbour" (struct x25_neigh) and reset this pointer to NULL. However: 1) When we receive a connection, the x25_rx_call_request function in af_x25.c does not increase the refcount when it assigns the pointer. When we disconnect, x25_disconnect is called and the struct's refcount is decreased without being increased in the first place. This causes frequent kernel crashes when using AF_X25 sockets. 2) When we initiate a connection but the connection is refused by the remote side, x25_disconnect is called which decreases the refcount and resets the pointer to NULL. But the x25_connect function in af_x25.c, which is waiting for the connection to be established, notices the failure and then tries to decrease the refcount again, resulting in a NULL-pointer-dereference error. This crashes the kernel every time a connection is refused by the remote side. Fixes: 4becb7ee5b3d ("net/x25: Fix x25_neigh refcnt leak when x25 disconnect") Cc: Martin Schiller Signed-off-by: Xie He --- net/x25/af_x25.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/net/x25/af_x25.c b/net/x25/af_x25.c index 0bbb283f23c9..8e59f9ecbeab 100644 --- a/net/x25/af_x25.c +++ b/net/x25/af_x25.c @@ -826,10 +826,12 @@ static int x25_connect(struct socket *sock, struct sockaddr *uaddr, rc = 0; out_put_neigh: if (rc) { - read_lock_bh(&x25_list_lock); - x25_neigh_put(x25->neighbour); - x25->neighbour = NULL; - read_unlock_bh(&x25_list_lock); + if (x25->neighbour) { + read_lock_bh(&x25_list_lock); + x25_neigh_put(x25->neighbour); + x25->neighbour = NULL; + read_unlock_bh(&x25_list_lock); + } x25->state = X25_STATE_0; } out_put_route: @@ -1050,6 +1052,7 @@ int x25_rx_call_request(struct sk_buff *skb, struct x25_neigh *nb, makex25->lci = lci; makex25->dest_addr = dest_addr; makex25->source_addr = source_addr; + x25_neigh_hold(nb); makex25->neighbour = nb; makex25->facilities = facilities; makex25->dte_facilities= dte_facilities; -- 2.27.0