Received: by 2002:a6b:8b52:0:0:0:0:0 with SMTP id n79csp7527702iod; Wed, 11 May 2022 07:55:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxCyqkGbEfldyiuDYJCIsJPzHuNxc0+Z2TDIAseLpHqa92AKMscmVJ+yGFwscllNcnCUV0S X-Received: by 2002:a17:907:2ce6:b0:6f4:7e8e:af40 with SMTP id hz6-20020a1709072ce600b006f47e8eaf40mr24436486ejc.211.1652280906334; Wed, 11 May 2022 07:55:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652280906; cv=none; d=google.com; s=arc-20160816; b=gwmuusOpKEoT8glYay+kA5HkwrB/iCpk27tdufxP+AoAv55atfgj0FzpfTLxL3zHlG nRcYfvEW0lSK/ALO53cljzNjN4zMixta9/qjhGKYmMI1r+8DRbgMq6CdxLhg0zLnxOt9 JiXEH8r12rKA0U+CpbTdnLWVAGlwDSnVJ5lY6d/87jqUL0kDoK6XO0PbxdC6JYjItA3O bvaRD/L8Z6zhtg2l2qsnGmPU+nCDPzPwOOyFA9fppuV4A3wrLsYH4t9Wccih+h8FOF+e HyxuNJnEgKlcCBkLni6p8i36FPIKcjCU765/fqgeSdK7pKQEsSL8guYDNv4xYlzLld9G nZXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=lOzAQ9Nwf+upu14YU9kdkj8fD/CjqOgLQXVJD7Hj/Lk=; b=tf5kFBHHr2OMpAXNtL/uwQIbXIZfPJsMYIUTbwPzQWa2vMfsDOftIY8JlViYXlSpA7 TZdWl4TN3720fudeqoFEk/9CSaHNri19B9I79BamhP7ucCER6vVVlfJHOmktiMONF4Ki 8rGK5UJmJPB2QA+Lq9PbdmzXWTqKLbOETaKTGa+DY+kcy3uXnx+nGI6lhbr+TcCMrtTQ tQJ1gq4yCqpacGCIwDlmXPTxk8a90cpQr7oI6y2SgyNkS83BUBSGi5JngBwIC+GVJgR1 fgaI6tfGlG6bBQaw+6QJMqEeWR3CVbTn/ZeaQ4XHZ469oHfJRVP0fSRBWd/AK4tJX3sV IX+A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b14-20020a056402350e00b00425ef577dc5si3058602edd.498.2022.05.11.07.53.27; Wed, 11 May 2022 07:55:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-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; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243098AbiEKNE1 (ORCPT + 99 others); Wed, 11 May 2022 09:04:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243058AbiEKNEQ (ORCPT ); Wed, 11 May 2022 09:04:16 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8878233A6A; Wed, 11 May 2022 06:04:13 -0700 (PDT) Received: from kwepemi100014.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4Kyw3H1n2DzCsbX; Wed, 11 May 2022 20:59:23 +0800 (CST) Received: from kwepemm600001.china.huawei.com (7.193.23.3) by kwepemi100014.china.huawei.com (7.221.188.106) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 11 May 2022 21:04:10 +0800 Received: from huawei.com (10.175.113.133) by kwepemm600001.china.huawei.com (7.193.23.3) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 11 May 2022 21:04:09 +0800 From: Wang Hai To: , , , , , , CC: , , , Subject: [PATCH 3/3] SUNRPC: Fix local socket leak in xs_setup_local() Date: Wed, 11 May 2022 21:22:32 +0800 Message-ID: <20220511132232.4030-4-wanghai38@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220511132232.4030-1-wanghai38@huawei.com> References: <20220511132232.4030-1-wanghai38@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.113.133] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemm600001.china.huawei.com (7.193.23.3) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-nfs@vger.kernel.org Add mechanism in xs_setup_local() to safely tear xprt down and solve the socket leak problem. Signed-off-by: Wang Hai --- net/sunrpc/xprtsock.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c index 25b8a8ead56b..7b9a62750571 100644 --- a/net/sunrpc/xprtsock.c +++ b/net/sunrpc/xprtsock.c @@ -1264,6 +1264,18 @@ static void xs_xprt_free(struct rpc_xprt *xprt) xprt_free(xprt); } +/** + * xs_destroy_xprt - close xprt socket and destroy it. + */ +static void xs_destroy_xprt(struct work_struct *work) +{ + struct rpc_xprt *xprt = + container_of(work, struct rpc_xprt, task_cleanup); + + xs_close(xprt); + xs_xprt_free(xprt); +} + /** * xs_destroy - prepare to shutdown a transport * @xprt: doomed transport @@ -2891,7 +2903,9 @@ static struct rpc_xprt *xs_setup_local(struct xprt_create *args) return xprt; ret = ERR_PTR(-EINVAL); out_err: - xs_xprt_free(xprt); + + INIT_WORK(&xprt->task_cleanup, xs_destroy_xprt); + schedule_work(&xprt->task_cleanup); return ret; } -- 2.17.1