Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp1847200imn; Mon, 1 Aug 2022 02:18:44 -0700 (PDT) X-Google-Smtp-Source: AA6agR4iV6Yc3RirMCFAL5784BUnW5+v6l1ABbgOgpQJTLLFI95PLyEP8ZWamx2eZl3uJXh2HmYf X-Received: by 2002:a17:907:12d7:b0:730:6d62:4ef7 with SMTP id vp23-20020a17090712d700b007306d624ef7mr4389030ejb.133.1659345523934; Mon, 01 Aug 2022 02:18:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659345523; cv=none; d=google.com; s=arc-20160816; b=f0dIapwQr6zi2UBjnspcGsZaE6Ye9SvPRx8uCKwoOTb+mtlCzV9PjjTOfcoUZ9HDDh 6pt/0tzJZyHuXk9QLZ7WkuSTKSAD7WR+bWDAcYZR0rz8W6Hq2TtNWHWiTJ7QRcLTYwNE o7VwFytE1lnTaU+DBPtreFaJqUoY9arT0E/kUlzI15lJezK2o59juNS53jpBPzZUOClB wCuktg3v1VEwKXgcEm0ZLP4QFSEIvCrnZR0sRPOLNtUPLhcXdeXALS2DnQJkeguDAoAm J+fh7XFcn7Iogifg2+JLu3UzWdnxdCD/1D6ffhHJkgDo40oNgm9/eozYIvhYSjRPdILt zgjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:in-reply-to:date:subject :cc:to:from:user-agent:references:dkim-signature; bh=mVLib6+KglGWzrVB//L7ezE4how+oky3wShDacSr+Rk=; b=Bziq/GczF8K53Z8m0NqzJxeF/FnACjnY0kk7voj73Gg7WLzPlZr2Iif7Ydu4IWcYDm OR8TrtszYXuF1H1swuDU3clWc+mvycNYymfMTJaGld5cThP98yL1d1GolhSZboz43zA9 Sja/svhbKijrAIm/xeHJ6uefbvsVyEF9f9WLhIkeybZl8/wmugj88wlpadVAegiUnlHp zuiW4lyKLOMG10TDhvkhoeixfuThGATH1gxqoWb2jBz8fn9nCKc1YXb6wVL4NZJUHr+r 3InYWjMQOjado5GFVWHXwS44IeWg28gfIGLdNgYRPnLN5yntOUXqv+33scISuy8rOY7T ZI1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b="fp+jCnQ/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sc19-20020a1709078a1300b006f4d14bbbb3si8506179ejc.150.2022.08.01.02.18.19; Mon, 01 Aug 2022 02:18:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b="fp+jCnQ/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229814AbiHAJQK (ORCPT + 99 others); Mon, 1 Aug 2022 05:16:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229709AbiHAJQH (ORCPT ); Mon, 1 Aug 2022 05:16:07 -0400 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 842C91928B for ; Mon, 1 Aug 2022 02:16:03 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id tl27so1327520ejc.1 for ; Mon, 01 Aug 2022 02:16:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=mime-version:message-id:in-reply-to:date:subject:cc:to:from :user-agent:references:from:to:cc; bh=mVLib6+KglGWzrVB//L7ezE4how+oky3wShDacSr+Rk=; b=fp+jCnQ/ItfHQ1hBwegHh+Ldz7J5kAwEOruTIPovevlje/32kxnh/US3StTNaYN0hk LBjV0xdxA2kKiZ7glZAtjn3ihomHLymWh2cSyoDhKTDoMt0iZjgAys3zXeZ2SIK1lC6N FW7ALONcIV5nxv9CvyCeLgNoZFZ3ZWcMX0q24= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:in-reply-to:date:subject:cc:to:from :user-agent:references:x-gm-message-state:from:to:cc; bh=mVLib6+KglGWzrVB//L7ezE4how+oky3wShDacSr+Rk=; b=JUPTBP6A6HkCr7AqsRqd3+xJ9lK3AuBmkP4ObtaEMXfmrJxEHC60LVCLm3BXduDoGS GyaLl5Mw9H1i3izp3gyrjpg4r4yuFOOGln1eyM3lffBLXXF5Ep4fhOIvczHYe0fBhDf2 qtCIEgUoB9yxFlsSllroAZCQ1ItD1ZFyCcnvzByIiz7IyQn/g2AjWqerOuKbPbnk/8IG DRBVIhni4nHjrygZ76fsHfhhSV1vftKcbm9I9rFXQb9DnqUGat73YIKzNHQVQOLrzVS+ r+szz3FHMpvXNgkug2CSoWIajcN4ADWD6JQ8i5DLmuN8+50sXDtjMzR9xO4vkt2nyr9f 1RiQ== X-Gm-Message-State: ACgBeo0ZzSOY5jAaUbfmy3aYpD3pXBRpIf4DG+ATn3SrnzzZhxtoAX93 oGPT1LIBgff3i0DDt1rlhSNRlw== X-Received: by 2002:a17:907:1deb:b0:730:81ea:1d09 with SMTP id og43-20020a1709071deb00b0073081ea1d09mr3464726ejc.183.1659345362041; Mon, 01 Aug 2022 02:16:02 -0700 (PDT) Received: from cloudflare.com (79.184.200.53.ipv4.supernova.orange.pl. [79.184.200.53]) by smtp.gmail.com with ESMTPSA id ky1-20020a170907778100b00722e52d043dsm4984008ejc.114.2022.08.01.02.16.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Aug 2022 02:16:01 -0700 (PDT) References: <00000000000026328205e08cdbeb@google.com> <20220730085654.2598-1-yin31149@gmail.com> User-agent: mu4e 1.6.10; emacs 27.2 From: Jakub Sitnicki To: Hawkins Jiawei Cc: syzbot+5f26f85569bd179c18ce@syzkaller.appspotmail.com, andrii@kernel.org, ast@kernel.org, borisp@nvidia.com, bpf@vger.kernel.org, wenjia@linux.ibm.com, ubraun@linux.ibm.com, daniel@iogearbox.net, guvenc@linux.ibm.com, davem@davemloft.net, edumazet@google.com, guwen@linux.alibaba.com, john.fastabend@gmail.com, kafai@fb.com, kgraul@linux.ibm.com, kpsingh@kernel.org, kuba@kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, pabeni@redhat.com, songliubraving@fb.com, syzkaller-bugs@googlegroups.com, linux-s390@vger.kernel.org, yhs@fb.com, 18801353760@163.com, paskripkin@gmail.com, skhan@linuxfoundation.org, linux-kernel-mentees@lists.linuxfoundation.org Subject: Re: [PATCH v2] net/smc: fix refcount bug in sk_psock_get (2) Date: Mon, 01 Aug 2022 11:09:23 +0200 In-reply-to: <20220730085654.2598-1-yin31149@gmail.com> Message-ID: <87wnbsjpdb.fsf@cloudflare.com> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Sat, Jul 30, 2022 at 04:56 PM +08, Hawkins Jiawei wrote: > Syzkaller reports refcount bug as follows: > ------------[ cut here ]------------ > refcount_t: saturated; leaking memory. > WARNING: CPU: 1 PID: 3605 at lib/refcount.c:19 refcount_warn_saturate+0xf4/0x1e0 lib/refcount.c:19 > Modules linked in: > CPU: 1 PID: 3605 Comm: syz-executor208 Not tainted 5.18.0-syzkaller-03023-g7e062cda7d90 #0 > ... > Call Trace: > > __refcount_add_not_zero include/linux/refcount.h:163 [inline] > __refcount_inc_not_zero include/linux/refcount.h:227 [inline] > refcount_inc_not_zero include/linux/refcount.h:245 [inline] > sk_psock_get+0x3bc/0x410 include/linux/skmsg.h:439 > tls_data_ready+0x6d/0x1b0 net/tls/tls_sw.c:2091 > tcp_data_ready+0x106/0x520 net/ipv4/tcp_input.c:4983 > tcp_data_queue+0x25f2/0x4c90 net/ipv4/tcp_input.c:5057 > tcp_rcv_state_process+0x1774/0x4e80 net/ipv4/tcp_input.c:6659 > tcp_v4_do_rcv+0x339/0x980 net/ipv4/tcp_ipv4.c:1682 > sk_backlog_rcv include/net/sock.h:1061 [inline] > __release_sock+0x134/0x3b0 net/core/sock.c:2849 > release_sock+0x54/0x1b0 net/core/sock.c:3404 > inet_shutdown+0x1e0/0x430 net/ipv4/af_inet.c:909 > __sys_shutdown_sock net/socket.c:2331 [inline] > __sys_shutdown_sock net/socket.c:2325 [inline] > __sys_shutdown+0xf1/0x1b0 net/socket.c:2343 > __do_sys_shutdown net/socket.c:2351 [inline] > __se_sys_shutdown net/socket.c:2349 [inline] > __x64_sys_shutdown+0x50/0x70 net/socket.c:2349 > do_syscall_x64 arch/x86/entry/common.c:50 [inline] > do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80 > entry_SYSCALL_64_after_hwframe+0x46/0xb0 > > > During SMC fallback process in connect syscall, kernel will > replaces TCP with SMC. In order to forward wakeup > smc socket waitqueue after fallback, kernel will sets > clcsk->sk_user_data to origin smc socket in > smc_fback_replace_callbacks(). > > Later, in shutdown syscall, kernel will calls > sk_psock_get(), which treats the clcsk->sk_user_data > as sk_psock type, triggering the refcnt warning. > > So, the root cause is that smc and psock, both will use > sk_user_data field. So they will mismatch this field > easily. > > This patch solves it by using another bit(defined as > SK_USER_DATA_NOTPSOCK) in PTRMASK, to mark whether > sk_user_data points to a sk_psock object or not. > This patch depends on a PTRMASK introduced in commit f1ff5ce2cd5e > ("net, sk_msg: Clear sk_user_data pointer on clone if tagged"). > > Fixes: 341adeec9ada ("net/smc: Forward wakeup to smc socket waitqueue after fallback") > Fixes: a60a2b1e0af1 ("net/smc: reduce active tcp_listen workers") > Reported-and-tested-by: syzbot+5f26f85569bd179c18ce@syzkaller.appspotmail.com > Suggested-by: Jakub Kicinski > Acked-by: Wen Gu > Signed-off-by: Hawkins Jiawei > --- Since using psock is not the common case, I'm wondering if it makes more sense to have an inverse flag - SK_USER_DATA_PSOCK. Flag would be set by the psock code on assignment to sk_user_data. This way we would also avoid some confusion. With the change below, the SK_USER_DATA_NOTPSOCK is not *always* set when sk_user_data holds a non-psock pointer. Only when SMC sets it. If we go with the current approach, the rest of sites, execpt for psock, that assign to sk_user_data should be updated to set SK_USER_DATA_NOTPSOCK as well, IMO. That is why I'd do it the other way. [...]