Michal Kubecek bad820
From: Paolo Abeni <pabeni@redhat.com>
Michal Kubecek bad820
Date: Wed, 18 Jan 2023 13:24:12 +0100
Michal Kubecek bad820
Subject: net/ulp: use consistent error code when blocking ULP
Michal Kubecek bad820
Patch-mainline: v6.2-rc5
Michal Kubecek bad820
Git-commit: 8ccc99362b60c6f27bb46f36fdaaccf4ef0303de
Michal Kubecek bad820
References: CVE-2023-0461 bsc#1208787
Michal Kubecek bad820
Michal Kubecek bad820
The referenced commit changed the error code returned by the kernel
Michal Kubecek bad820
when preventing a non-established socket from attaching the ktls
Michal Kubecek bad820
ULP. Before to such a commit, the user-space got ENOTCONN instead
Michal Kubecek bad820
of EINVAL.
Michal Kubecek bad820
Michal Kubecek bad820
The existing self-tests depend on such error code, and the change
Michal Kubecek bad820
caused a failure:
Michal Kubecek bad820
Michal Kubecek bad820
  RUN           global.non_established ...
Michal Kubecek bad820
 tls.c:1673:non_established:Expected errno (22) == ENOTCONN (107)
Michal Kubecek bad820
 non_established: Test failed at step #3
Michal Kubecek bad820
          FAIL  global.non_established
Michal Kubecek bad820
Michal Kubecek bad820
In the unlikely event existing applications do the same, address
Michal Kubecek bad820
the issue by restoring the prior error code in the above scenario.
Michal Kubecek bad820
Michal Kubecek bad820
Note that the only other ULP performing similar checks at init
Michal Kubecek bad820
time - smc_ulp_ops - also fails with ENOTCONN when trying to attach
Michal Kubecek bad820
the ULP to a non-established socket.
Michal Kubecek bad820
Michal Kubecek bad820
Reported-by: Sabrina Dubroca <sd@queasysnail.net>
Michal Kubecek bad820
Fixes: 2c02d41d71f9 ("net/ulp: prevent ULP without clone op from entering the LISTEN status")
Michal Kubecek bad820
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Michal Kubecek bad820
Reviewed-by: Sabrina Dubroca <sd@queasysnail.net>
Michal Kubecek bad820
Link: https://lore.kernel.org/r/7bb199e7a93317fb6f8bf8b9b2dc71c18f337cde.1674042685.git.pabeni@redhat.com
Michal Kubecek bad820
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Michal Kubecek bad820
Acked-by: Michal Kubecek <mkubecek@suse.cz>
Michal Kubecek bad820
Michal Kubecek bad820
---
Michal Kubecek bad820
 net/ipv4/tcp_ulp.c | 2 +-
Michal Kubecek bad820
 1 file changed, 1 insertion(+), 1 deletion(-)
Michal Kubecek bad820
Michal Kubecek bad820
--- a/net/ipv4/tcp_ulp.c
Michal Kubecek bad820
+++ b/net/ipv4/tcp_ulp.c
Michal Kubecek bad820
@@ -136,7 +136,7 @@ static int __tcp_set_ulp(struct sock *sk, const struct tcp_ulp_ops *ulp_ops)
Michal Kubecek bad820
 	if (icsk->icsk_ulp_ops)
Michal Kubecek bad820
 		goto out_err;
Michal Kubecek bad820
 
Michal Kubecek bad820
-	err = -EINVAL;
Michal Kubecek bad820
+	err = -ENOTCONN;
Michal Kubecek bad820
 	if (!ulp_ops->clone && sk->sk_state == TCP_LISTEN)
Michal Kubecek bad820
 		goto out_err;
Michal Kubecek bad820