Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp62123iof; Sun, 5 Jun 2022 21:10:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvrKBdIA5snPtQx+plizuypdJBUx5tC0XM9UtTrKf4hgvQHEf1nRZ3Y2YAnt7oEAHzuNyT X-Received: by 2002:a17:902:a50a:b0:162:3488:27c4 with SMTP id s10-20020a170902a50a00b00162348827c4mr21683054plq.109.1654488611963; Sun, 05 Jun 2022 21:10:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654488611; cv=none; d=google.com; s=arc-20160816; b=Kao8SrkBV9zLfdGQ9KjfhD3atIwg67dsh5fxaMgCyhvHoFIk2U/rDaXe2ZpbRRJmx4 23XukFqqRNQDIts6VZg6UA/8yMN1OgtViEbCWq19wvzBcWv97Sw8pMIHihNlBZw/dJrv qOmgJquBy5bqU/z+GwIZ4XgNmuPqmgdXiF6q1HhMcGvArgxJ6QoTv12ItAzXaJr2rvSX OEFbVcLJ6xT8Oc90lv5datsvClly0awf9e8A3nXboZZaI9qSmLvLxT7A727mQB91sqpw USaJD+7zN3qKZxikimFZdSZz1+TM5V+RlS5i4mOYzZmVOQ293hl6kqGW0mgxu3qag/4U 336A== 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=TJGkS+FMgEG3phkLT16NrQCImEonVfV9Vj/Cwjx7yTU=; b=nFgRimsq0iSgbW/MbcYpZ1ADJUcFeY5XjFvzDn8aSaJXIJV+Nf6LDCllnMf6p7hCKK /7vNfLYUlx3Vz6lZQZFka+2lkSoR7fOLZaY7ZZ1HCeRuQdloTBwvPv+H1wsx9+2/U90+ RVGx2Gpx6eRIIRkVQqWoga4rmTVp+v/lCXyTBhVIuB1n4yUNv7aVvXkdRXjK5Om3zJSh a27zGz4Xh52a9o12fOTlRIr7v0AKwTYvRDCBxVIv4hMZYPIsk2BVRX1vZCytIyTFJqER id5yR2vMf9tonYnEWJWVD/7atbNfRQzAjiref0fDf3AR7tSotmW3z5vjTDIClJdN8kbQ GcUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="vUEmU1/h"; 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 h4-20020a170902b94400b0015e6330c0ecsi18043249pls.330.2022.06.05.21.10.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jun 2022 21:10:11 -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="vUEmU1/h"; 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 B7FF56FA1B; Sun, 5 Jun 2022 20:49:42 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344373AbiFCRqJ (ORCPT + 99 others); Fri, 3 Jun 2022 13:46:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345350AbiFCRpG (ORCPT ); Fri, 3 Jun 2022 13:45:06 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAA7854686; Fri, 3 Jun 2022 10:43:04 -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 475A3B82430; Fri, 3 Jun 2022 17:43:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B85BC385A9; Fri, 3 Jun 2022 17:43:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654278182; bh=6QIvA1w7D1nVnT8dKZwTmw5fYgHUVDhCMA2ObrGVwiY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vUEmU1/h/1nnRXHAj9xmlge20BM4D4+e+ncBed9BTc3xeMHWXA6CaaPODNeOvDYJk 0awP8+uIcHkKUObwYSEE9oDh+BMFomwaEUvPscGUb4n5Q2lqtZYwwFWrSFW9HbvONI P5YuS0ZtquDEu5oEMEoF6Ql3C5cpk0UrXgspXVGw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dai Ngo , Chuck Lever Subject: [PATCH 4.19 29/30] NFSD: Fix possible sleep during nfsd4_release_lockowner() Date: Fri, 3 Jun 2022 19:39:57 +0200 Message-Id: <20220603173815.947907478@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220603173815.088143764@linuxfoundation.org> References: <20220603173815.088143764@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 @@ -6401,16 +6401,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; }