]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net/smc: fix sleep-inside-lock in __smc_setsockopt() causing local DoS
authorNicolò Coccia <n.coccia96@gmail.com>
Sun, 10 May 2026 16:34:13 +0000 (12:34 -0400)
committerJakub Kicinski <kuba@kernel.org>
Wed, 13 May 2026 01:43:40 +0000 (18:43 -0700)
A logic flaw in __smc_setsockopt() allows a local unprivileged user to
cause a Denial of Service (DoS) by holding the socket lock indefinitely.

The function __smc_setsockopt() calls copy_from_sockptr() while holding
lock_sock(sk). By passing a userfaultfd-monitored memory page (or
FUSE-backed memory on systems where unprivileged userfaultfd is disabled)
as the optval, an attacker can halt execution during the copy operation,
keeping the lock held.

Combined with asynchronous tear-down operations like shutdown(), this
exhausts the kernel wq (kworkers) and triggers the hung task watchdog.

[  240.123456] INFO: task kworker/u8:2 blocked for more than 120 seconds.
[  240.123489] Call Trace:
[  240.123501]  smc_shutdown+...
[  240.123512]  lock_sock_nested+...

This patch moves the user-space copy outside the lock_sock() critical
section to prevent the issue.

Fixes: a6a6fe27bab4 ("net/smc: Dynamic control handshake limitation by socket options")
Signed-off-by: Nicolò Coccia <n.coccia96@gmail.com>
Reviewed-by: Dust Li <dust.li@linux.alibaba.com>
Tested-by: Dust Li <dust.li@linux.alibaba.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/smc/af_smc.c

index 185dbed7de5d6ceab88c9d92b61ed4d21d7767ff..da28652f681088a3ec312993f126e21c800eefcb 100644 (file)
@@ -3054,18 +3054,17 @@ static int __smc_setsockopt(struct socket *sock, int level, int optname,
 
        smc = smc_sk(sk);
 
+       /* pre-fetch user data outside the lock */
+       if (optname == SMC_LIMIT_HS) {
+               if (optlen < sizeof(int))
+                       return -EINVAL;
+               if (copy_from_sockptr(&val, optval, sizeof(int)))
+                       return -EFAULT;
+       }
+
        lock_sock(sk);
        switch (optname) {
        case SMC_LIMIT_HS:
-               if (optlen < sizeof(int)) {
-                       rc = -EINVAL;
-                       break;
-               }
-               if (copy_from_sockptr(&val, optval, sizeof(int))) {
-                       rc = -EFAULT;
-                       break;
-               }
-
                smc->limit_smc_hs = !!val;
                rc = 0;
                break;