Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp3687957lfo; Mon, 23 May 2022 11:28:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyD4IXr64J9VenNMLlsjp9tqrrZu2o1pUQtIEqN4la109tiUmfp4quvSj3iVlUTIDw8vh55 X-Received: by 2002:a17:902:ce02:b0:151:a86d:dc2b with SMTP id k2-20020a170902ce0200b00151a86ddc2bmr24375734plg.57.1653330526666; Mon, 23 May 2022 11:28:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653330526; cv=none; d=google.com; s=arc-20160816; b=y+DF8AwmjXtRgItUc5O0vm5mYcgywHAWi7bhZUakGLilz7M+j6/GZr1Rmb1iyfGdIn hy+vmGb7jaIRov0s+PdmOpE/+Hyz3nY7wmdmCZkkoHy5OBwHXvljrM7zz8QzqIv+NopL Pr4Gyn2RD8noeXlWT2ux91PqlvpgMkSIjR+6Q/wZwyemZD+h72QekZHbkTThWaPbsHGq 7dytPoRIKtWWuZPkwTSd5ovgFTgCr1uEXr0uqq3hG6Qqv0Klz4YW/7FGUkonroIkFPP5 txQXMtYZYro91IRdgNSx+rmUpMyHuVvq074nS9Xgxn/Z0E8bKyKzOUBMdYUGT7fqNJsT SAgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5/4tfe72d+dRsYZQ0PJLT1wl/gLiPoNBGo/vkQiJNb0=; b=JJASpH2qcgc9OSR8fY/JvoRmClTkGkh3aJ1774zzEGan6OJXEaBJ3JzGVkyY6ni4xy ViPVZYqzMXnH4wGAW4d5AnFfDM3atEbpnXLUcb4veTVrQ6eDwXhEpAZjGWUnz15ae8IJ c1vh/tqhnWPnA2YfVaoXK290aW8I3PcMbx6FNUif0L1Tdiw5uF4HIRYMD0RUdS+Hu4np IqtXc8LVu4V8dq3yoc9dvwkKf6hkh9KMTbg9Oxsu4VgbKsuvCcVWy2xVyjBs/kF1VHeb mLW6yg3ZSuf70dc9iYilfF0qO+0D6LqGofrwLwyO+7MwWRH5nQr+NNC2y70TPO+GoiDq lDLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=G9oaFD2f; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id by3-20020a056a00400300b0050cff7b2666si11564258pfb.241.2022.05.23.11.28.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 11:28:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=G9oaFD2f; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CFF0B111B97; Mon, 23 May 2022 11:28:16 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240597AbiEWRYx (ORCPT + 99 others); Mon, 23 May 2022 13:24:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240561AbiEWRQ3 (ORCPT ); Mon, 23 May 2022 13:16:29 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C162571D95; Mon, 23 May 2022 10:15:45 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 7AE8CB811CC; Mon, 23 May 2022 17:13:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B9B86C36AE7; Mon, 23 May 2022 17:13:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1653325989; bh=V4ztirCZvI7TkmIHEYzWcBUTEshg8t47dAxHMOJ2Es8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G9oaFD2f+Cc7ioqIJmk4XVTSpCelnQze+jbpkAkPDUkU5Uje8kjvza7lNQL3njHmi VyNIib60gK5RlqMIntkTX75MiB/FqGpHfrxNcxSWLvwrxWe5u6IMitS+pDtlsri2pI GGuPANI43pa3zv0hoQJfYGC7NhXmhWLGek5BANPo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Felix Fu , Al Viro , Trond Myklebust , Meena Shanmugam Subject: [PATCH 5.4 25/68] SUNRPC: Ensure we flush any closed sockets before xs_xprt_free() Date: Mon, 23 May 2022 19:04:52 +0200 Message-Id: <20220523165806.781218013@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220523165802.500642349@linuxfoundation.org> References: <20220523165802.500642349@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: Meena Shanmugam From: Trond Myklebust commit f00432063db1a0db484e85193eccc6845435b80e upstream. We must ensure that all sockets are closed before we call xprt_free() and release the reference to the net namespace. The problem is that calling fput() will defer closing the socket until delayed_fput() gets called. Let's fix the situation by allowing rpciod and the transport teardown code (which runs on the system wq) to call __fput_sync(), and directly close the socket. Reported-by: Felix Fu Acked-by: Al Viro Fixes: a73881c96d73 ("SUNRPC: Fix an Oops in udp_poll()") Cc: stable@vger.kernel.org # 5.1.x: 3be232f11a3c: SUNRPC: Prevent immediate close+reconnect Cc: stable@vger.kernel.org # 5.1.x: 89f42494f92f: SUNRPC: Don't call connect() more than once on a TCP socket Cc: stable@vger.kernel.org # 5.1.x Signed-off-by: Trond Myklebust [meenashanmugam: Fix merge conflict in xprt_connect] Signed-off-by: Meena Shanmugam Signed-off-by: Greg Kroah-Hartman --- fs/file_table.c | 1 + net/sunrpc/xprt.c | 5 +---- net/sunrpc/xprtsock.c | 16 +++++++++++++--- 3 files changed, 15 insertions(+), 7 deletions(-) --- a/fs/file_table.c +++ b/fs/file_table.c @@ -375,6 +375,7 @@ void __fput_sync(struct file *file) } EXPORT_SYMBOL(fput); +EXPORT_SYMBOL(__fput_sync); void __init files_init(void) { --- a/net/sunrpc/xprt.c +++ b/net/sunrpc/xprt.c @@ -868,10 +868,7 @@ void xprt_connect(struct rpc_task *task) if (!xprt_lock_write(xprt, task)) return; - if (test_and_clear_bit(XPRT_CLOSE_WAIT, &xprt->state)) - xprt->ops->close(xprt); - - if (!xprt_connected(xprt)) { + if (!xprt_connected(xprt) && !test_bit(XPRT_CLOSE_WAIT, &xprt->state)) { task->tk_rqstp->rq_connect_cookie = xprt->connect_cookie; rpc_sleep_on_timeout(&xprt->pending, task, NULL, xprt_request_timeout(task->tk_rqstp)); --- a/net/sunrpc/xprtsock.c +++ b/net/sunrpc/xprtsock.c @@ -989,7 +989,7 @@ static int xs_local_send_request(struct /* Close the stream if the previous transmission was incomplete */ if (xs_send_request_was_aborted(transport, req)) { - xs_close(xprt); + xprt_force_disconnect(xprt); return -ENOTCONN; } @@ -1027,7 +1027,7 @@ static int xs_local_send_request(struct -status); /* fall through */ case -EPIPE: - xs_close(xprt); + xprt_force_disconnect(xprt); status = -ENOTCONN; } @@ -1303,6 +1303,16 @@ static void xs_reset_transport(struct so if (sk == NULL) return; + /* + * Make sure we're calling this in a context from which it is safe + * to call __fput_sync(). In practice that means rpciod and the + * system workqueue. + */ + if (!(current->flags & PF_WQ_WORKER)) { + WARN_ON_ONCE(1); + set_bit(XPRT_CLOSE_WAIT, &xprt->state); + return; + } if (atomic_read(&transport->xprt.swapper)) sk_clear_memalloc(sk); @@ -1326,7 +1336,7 @@ static void xs_reset_transport(struct so mutex_unlock(&transport->recv_mutex); trace_rpc_socket_close(xprt, sock); - fput(filp); + __fput_sync(filp); xprt_disconnect_done(xprt); }