Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp62201iof; Sun, 5 Jun 2022 21:10:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyueInWBBrTP4zXto0nRMbYfNFutB8ZHa+U34gC7BIYmd0zzQfWEWv1lUb5EEilJMNdbXF/ X-Received: by 2002:a63:2160:0:b0:3fc:b8ac:1976 with SMTP id s32-20020a632160000000b003fcb8ac1976mr19724761pgm.453.1654488619952; Sun, 05 Jun 2022 21:10:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654488619; cv=none; d=google.com; s=arc-20160816; b=BOd1vxfOBjZpOHQFhSb8MXfTEooX+LCsbOBsd2XsbFj1RYoU8VBQ9YPfgtbmrQco7R nvtp6wMMYaZ5VnQqNvr1Kl4EYHEHYssmV+AGkgpzd/HWEkd1VkKFfZj4W5734Kx5GtBp J2UYIEelEGJIOztwJyK8CVjNIqFmO5FcrUmxibFTMrVge61GN3MQMKym+Ufohr9FMZ5W CuGPwNhYbrsymNn65x4rYNVDYkwp7npor/3O1ccxPE/KoqO8eApYcRcEMMxJ28xmtBRu gpwHglsWkVBk/lFTUblCVzCQ9uajjM0NAY21P7XKGgKOILSQkm3+yp48lnL5oEwv2lj8 ZKsw== 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=pRcOPnbdw94/31JGhbFnkBAK1K58CuoSdW5va08HgpA=; b=TlMhm5IHB7kFQXprBJQOUZmlMRMRRSvRUHACL5HXtoRPT8N0/k49VLRg1yoVDk+2wx +cL5xUekS1N+7KxHmaJx0AukcRNDlZvh9IuJQja+Vo8pneIx3qpnBe6/gk7xvCUJKA/r 2YYxJmaiH2ShdoedbiWKiAFfPZYZJq/nauMZVyQE+G2RqmizL7m+DVitCNboP6eFVPu5 hcl3Q7pAmJI7B+gjUcVg314KLtstCfbPKJ/mUu/Aco6OjUtiqaMQW7G3oVngIYtIlQ11 VQgGLYwidJxWkgwI3VzGwkk7CdFlvkPT/4annf9awtuEf8bi93T9mtET0FPFYcOPaXSV 8K8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Vlo3XtAA; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id t17-20020a056a00139100b0051b9c2baa8esi20493695pfg.44.2022.06.05.21.10.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jun 2022 21:10:19 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Vlo3XtAA; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 AA7D070342; Sun, 5 Jun 2022 20:49:48 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345415AbiFCRwf (ORCPT + 99 others); Fri, 3 Jun 2022 13:52:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345391AbiFCRsu (ORCPT ); Fri, 3 Jun 2022 13:48:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0203F55227; Fri, 3 Jun 2022 10:45:36 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 4E2D2604EF; Fri, 3 Jun 2022 17:45:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58B36C385B8; Fri, 3 Jun 2022 17:45:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654278335; bh=aRK5mDGZGC7naJL9YgFD6E9gV4OjjB5dfajnjI3ZvRI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Vlo3XtAAp+dVXHhYeMtJ+cZpvl+6gaPUa8RQT3T6MfXbfPxZuWSKhd8ZZeSFZ8lpk Mr9zerOzA5Rt74VDGKJ1AH4VK5QeZ/7/QGiM68rvwnXAHzt7xyPw/ZZY0bVWTYmdJj B93mmNaGTfdHNXgers2ogJRb5aIGiTeFJQX4sndo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dai Ngo , Chuck Lever Subject: [PATCH 5.4 33/34] NFSD: Fix possible sleep during nfsd4_release_lockowner() Date: Fri, 3 Jun 2022 19:43:29 +0200 Message-Id: <20220603173817.144471150@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220603173815.990072516@linuxfoundation.org> References: <20220603173815.990072516@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=-3.1 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: Chuck Lever commit ce3c4ad7f4ce5db7b4f08a1e237d8dd94b39180b upstream. nfsd4_release_lockowner() holds clp->cl_lock when it calls check_for_locks(). However, check_for_locks() calls nfsd_file_get() / nfsd_file_put() to access the backing inode's flc_posix list, and nfsd_file_put() can sleep if the inode was recently removed. Let's instead rely on the stateowner's reference count to gate whether the release is permitted. This should be a reliable indication of locks-in-use since file lock operations and ->lm_get_owner take appropriate references, which are released appropriately when file locks are removed. Reported-by: Dai Ngo Signed-off-by: Chuck Lever Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- fs/nfsd/nfs4state.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -6894,16 +6894,12 @@ nfsd4_release_lockowner(struct svc_rqst if (sop->so_is_open_owner || !same_owner_str(sop, owner)) continue; - /* see if there are still any locks associated with it */ - lo = lockowner(sop); - list_for_each_entry(stp, &sop->so_stateids, st_perstateowner) { - if (check_for_locks(stp->st_stid.sc_file, lo)) { - status = nfserr_locks_held; - spin_unlock(&clp->cl_lock); - return status; - } + if (atomic_read(&sop->so_count) != 1) { + spin_unlock(&clp->cl_lock); + return nfserr_locks_held; } + lo = lockowner(sop); nfs4_get_stateowner(sop); break; }