Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1652108ybl; Wed, 8 Jan 2020 22:32:49 -0800 (PST) X-Google-Smtp-Source: APXvYqxCvZ3mjlwOOm5bKwyhR2wtks+8NXGQ+gXlt3aQzsRANvO9g/iyh6OK/bvGXN3lJmV1Bpyf X-Received: by 2002:a05:6808:8cd:: with SMTP id k13mr2075641oij.4.1578551569044; Wed, 08 Jan 2020 22:32:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578551569; cv=none; d=google.com; s=arc-20160816; b=c+Pm3QcYJX8sjlizLJE6TJZjhYs1zSIp27skWin8P9Vd5nh7HS58p3MEDkEZPw+U00 PIDQIx6dvA+NL9DnYod43gqqeETmSP15xiQ0tDW5HbKv0YUvtoVc3XnMnbl2nMXXMmOy hM9o5bxsoeAgX5Lu3foS4+sunwD5kpXZgrvnVeuXY+hv/fM2mPUMZIl83rbidOTPA1mz TdTi0N1SCRsQ7gZHzlZRFhx+Pb2JfVnl//A3PLEXvmqYNO8ux59zSr37RrEu/tgvj0BU PM/GpPsXMGoFdTSKQbjAp2chI2qjE5KLf9f0fqZ9qNgyjfX7XVfXSEj30mvJ4EvJh/f7 lJWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=0I97jC8Wuu/aL+qw2iRAqd9hZ/i+CMPKiYZkYEhkJHc=; b=rTOqRgSOXkDZWMaCPHlFU3tlWFOb82f/aThLpZst52vYqFNU2BE4+CYGY2pN0JBhO7 LMrXzxI6/J9YPj+98gnVCwUkCeCFcbDOFTdJ8EOD1zzRwGHaVtPsp6JvgjiQFTy36+GE /nUhjx3OFI6tGXt9qBm3uE+r59/Ea0xnTCxGLaIs0aDPlpJMMfAxLyVf4EEazP2hPvJ+ lYZhBXDzaISN/RchkslTSFnFrykda3ezgZT+r34ThCdzcRRYgXZNt3csgHjB0GxRrfdL osupFzvama4sIid70tz15CIgkRSuK65ltiv31xRzLDyJcYjom4ikn0Ukb8uFP/Ep+2dr UEgw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k4si3090094oiw.55.2020.01.08.22.32.36; Wed, 08 Jan 2020 22:32:49 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728090AbgAIGb4 (ORCPT + 99 others); Thu, 9 Jan 2020 01:31:56 -0500 Received: from host-88-217-225-28.customer.m-online.net ([88.217.225.28]:49454 "EHLO mail.dev.tdt.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726541AbgAIGbz (ORCPT ); Thu, 9 Jan 2020 01:31:55 -0500 Received: from mschiller01.dev.tdt.de (unknown [10.2.3.20]) by mail.dev.tdt.de (Postfix) with ESMTPSA id 28EB620AAB; Thu, 9 Jan 2020 06:31:48 +0000 (UTC) From: Martin Schiller To: arnd@arndb.de, davem@davemloft.net Cc: andrew.hendry@gmail.com, edumazet@google.com, gregkh@linuxfoundation.org, tglx@linutronix.de, linux-x25@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com, Martin Schiller , syzbot+429c200ffc8772bfe070@syzkaller.appspotmail.com, syzbot+eec0c87f31a7c3b66f7b@syzkaller.appspotmail.com Subject: [PATCH] net/x25: fix nonblocking connect Date: Thu, 9 Jan 2020 07:31:14 +0100 Message-Id: <20200109063114.23195-1-ms@dev.tdt.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mail.dev.tdt.de Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch fixes 2 issues in x25_connect(): 1. It makes absolutely no sense to reset the neighbour and the connection state after a (successful) nonblocking call of x25_connect. This prevents any connection from being established, since the response (call accept) cannot be processed. 2. Any further calls to x25_connect() while a call is pending should simply return, instead of creating new Call Request (on different logical channels). This patch should also fix the "KASAN: null-ptr-deref Write in x25_connect" and "BUG: unable to handle kernel NULL pointer dereference in x25_connect" bugs reported by syzbot. Signed-off-by: Martin Schiller Reported-by: syzbot+429c200ffc8772bfe070@syzkaller.appspotmail.com Reported-by: syzbot+eec0c87f31a7c3b66f7b@syzkaller.appspotmail.com --- net/x25/af_x25.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/net/x25/af_x25.c b/net/x25/af_x25.c index 2efe44a34644..d5b09bbff375 100644 --- a/net/x25/af_x25.c +++ b/net/x25/af_x25.c @@ -766,6 +766,10 @@ static int x25_connect(struct socket *sock, struct sockaddr *uaddr, if (sk->sk_state == TCP_ESTABLISHED) goto out; + rc = -EALREADY; /* Do nothing if call is already in progress */ + if (sk->sk_state == TCP_SYN_SENT) + goto out; + sk->sk_state = TCP_CLOSE; sock->state = SS_UNCONNECTED; @@ -812,7 +816,7 @@ static int x25_connect(struct socket *sock, struct sockaddr *uaddr, /* Now the loop */ rc = -EINPROGRESS; if (sk->sk_state != TCP_ESTABLISHED && (flags & O_NONBLOCK)) - goto out_put_neigh; + goto out; rc = x25_wait_for_connection_establishment(sk); if (rc) -- 2.20.1