From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4CFD146BE for ; Mon, 20 Feb 2023 13:37:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C21EDC433EF; Mon, 20 Feb 2023 13:37:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1676900255; bh=zv/BiT4SJmHw+pvsgQMRb+Bed+1Da39/4lKFFFRbc4Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vJWV7opwZq7DqLKspuvN9kX0gcznIeQxqI6UDTpf7q/78nN/iJl0VnDrwZbXUiTOW SHKmBXzYsStPxY0sfMi/H/SP+OOk08I9weT/SFSyQGBhlf+2ccFp+7hiIdifUjdiqB hdjnDFzRsl5n2FJJEWbPluun1d4sXh/EChxI5D1g= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Hyunwoo Kim , "David S. Miller" , Sasha Levin Subject: [PATCH 4.14 10/53] net/x25: Fix to not accept on connected socket Date: Mon, 20 Feb 2023 14:35:36 +0100 Message-Id: <20230220133548.545993979@linuxfoundation.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230220133548.158615609@linuxfoundation.org> References: <20230220133548.158615609@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Hyunwoo Kim [ Upstream commit f2b0b5210f67c56a3bcdf92ff665fb285d6e0067 ] When listen() and accept() are called on an x25 socket that connect() succeeds, accept() succeeds immediately. This is because x25_connect() queues the skb to sk->sk_receive_queue, and x25_accept() dequeues it. This creates a child socket with the sk of the parent x25 socket, which can cause confusion. Fix x25_listen() to return -EINVAL if the socket has already been successfully connect()ed to avoid this issue. Signed-off-by: Hyunwoo Kim Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/x25/af_x25.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/net/x25/af_x25.c b/net/x25/af_x25.c index e103ec39759f..73e293c3f2fb 100644 --- a/net/x25/af_x25.c +++ b/net/x25/af_x25.c @@ -496,6 +496,12 @@ static int x25_listen(struct socket *sock, int backlog) int rc = -EOPNOTSUPP; lock_sock(sk); + if (sock->state != SS_UNCONNECTED) { + rc = -EINVAL; + release_sock(sk); + return rc; + } + if (sk->sk_state != TCP_LISTEN) { memset(&x25_sk(sk)->dest_addr, 0, X25_ADDR_LEN); sk->sk_max_ack_backlog = backlog; -- 2.39.0