Skip to contentSkip to conversation

smc: disallow TCP_ULP in smc_setsockopt()

PATCH Superseded Cong Wang 2 participants 4 messages Apr 10, 2021 – Apr 13, 2021

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Cong Wang

author
#0 lore raw

PATCH 1/1 smc: disallow TCP_ULP in smc_setsockopt()

From: Cong Wang <[email protected]>

syzbot is able to setup kTLS on an SMC socket, which coincidentally uses sk_user_data too, later, kTLS treats it as psock so triggers a refcnt warning. The cause is that smc_setsockopt() simply calls TCP setsockopt(). I do not think it makes sense to setup kTLS on top of SMC, so we can just disallow this.

Reported-and-tested-by [email protected]
Cc John Fastabend <[email protected]>
Cc Karsten Graul <[email protected]>
---
 net/smc/af_smc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/smc/af_smc.c +3 -1
index 47340b3b514f..0d4d6d28f20c 100644
@@ -2162,6 +2162,9 @@ static int smc_setsockopt(struct socket *sock, int level, int optname,
 	struct smc_sock *smc;
 	int val, rc;
 
+	if (optname == TCP_ULP)
+		return -EOPNOTSUPP;
+
 	smc = smc_sk(sk);
 
 	/* generic setsockopts reaching us here always apply to the
@@ -2186,7 +2189,6 @@ static int smc_setsockopt(struct socket *sock, int level, int optname,
 	if (rc || smc->use_fallback)
 		goto out;
 	switch (optname) {
-	case TCP_ULP:
 	case TCP_FASTOPEN:
 	case TCP_FASTOPEN_CONNECT:
 	case TCP_FASTOPEN_KEY:
Signature · 1 line
2.25.1
#1 lore raw
Quoted 31 lines · Cong Wang

From: Cong Wang <[email protected]>

syzbot is able to setup kTLS on an SMC socket, which coincidentally uses sk_user_data too, later, kTLS treats it as psock so triggers a refcnt warning. The cause is that smc_setsockopt() simply calls TCP setsockopt(). I do not think it makes sense to setup kTLS on top of SMC, so we can just disallow this.

Reported-and-tested-by [email protected]
Cc John Fastabend <[email protected]>
Cc Karsten Graul <[email protected]>
---
 net/smc/af_smc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/smc/af_smc.c +3 -0
index 47340b3b514f..0d4d6d28f20c 100644
@@ -2162,6 +2162,9 @@ static int smc_setsockopt(struct socket *sock, int level, int optname,
 	struct smc_sock *smc;
 	int val, rc;
 
+	if (optname == TCP_ULP)
+		return -EOPNOTSUPP;
+
 	smc = smc_sk(sk);
 
 	/* generic setsockopts reaching us here always apply to the

net/smc/af_smc.c static int smc_setsockopt(struct socket *sock, int level, int optname, · line 2189

Quoted 4 lines
net/smc/af_smc.c +0 -1
@@ -2186,7 +2189,6 @@ static int smc_setsockopt(struct socket *sock, int level, int optname,
 	if (rc || smc->use_fallback)
 		goto out;
 	switch (optname) {
-	case TCP_ULP:

Should'nt it return -EOPNOTSUPP in that case, too?

Quoted 4 lines
net/smc/af_smc.c +0 -0
 	case TCP_FASTOPEN:
 	case TCP_FASTOPEN_CONNECT:
 	case TCP_FASTOPEN_KEY:
Signature · 3 lines
Karsten

(I'm a dude)
author
#2 lore raw
Quoted 33 lines · Karsten Graul
Quoted 29 lines · Cong Wang

From: Cong Wang <[email protected]>

syzbot is able to setup kTLS on an SMC socket, which coincidentally uses sk_user_data too, later, kTLS treats it as psock so triggers a refcnt warning. The cause is that smc_setsockopt() simply calls TCP setsockopt(). I do not think it makes sense to setup kTLS on top of SMC, so we can just disallow this.

Reported-and-tested-by [email protected]
Cc John Fastabend <[email protected]>
Cc Karsten Graul <[email protected]>
---
 net/smc/af_smc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/smc/af_smc.c +3 -0
index 47340b3b514f..0d4d6d28f20c 100644
@@ -2162,6 +2162,9 @@ static int smc_setsockopt(struct socket *sock, int level, int optname,
      struct smc_sock *smc;
      int val, rc;
 
+     if (optname == TCP_ULP)
+             return -EOPNOTSUPP;
+
      smc = smc_sk(sk);
 
Quoted 8 lines

net/smc/af_smc.c static int smc_setsockopt(struct socket *sock, int level, int optname, · line 2189

Quoted 6 lines
net/smc/af_smc.c +0 -1
      /* generic setsockopts reaching us here always apply to the
@@ -2186,7 +2189,6 @@ static int smc_setsockopt(struct socket *sock, int level, int optname,
      if (rc || smc->use_fallback)
              goto out;
      switch (optname) {
-     case TCP_ULP:

Should'nt it return -EOPNOTSUPP in that case, too?

I do not think I understand this. In case of TCP_ULP, we will not even reach this switch case after my patch.

Thanks.

#3 lore raw
In reply to Cong Wang
Quoted 8 lines · Cong Wang

From: Cong Wang <[email protected]>

syzbot is able to setup kTLS on an SMC socket, which coincidentally uses sk_user_data too, later, kTLS treats it as psock so triggers a refcnt warning. The cause is that smc_setsockopt() simply calls TCP setsockopt(). I do not think it makes sense to setup kTLS on top of SMC, so we can just disallow this.

Quoted 5 lines
Reported-and-tested-by [email protected]
Cc John Fastabend <[email protected]>
Cc Karsten Graul <[email protected]>

---