Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2862471pxv; Mon, 12 Jul 2021 03:52:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhRBuhHWqnFZwfhlSI8OxrmDW9ccQUeswQwHV6QGPphSg8+lXe4HN13V6M5IYfrMrLMPkP X-Received: by 2002:a92:7d08:: with SMTP id y8mr34827439ilc.43.1626087128434; Mon, 12 Jul 2021 03:52:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626087128; cv=none; d=google.com; s=arc-20160816; b=1BlsKjnJbUNyNPC3+IGxvZ5MPCy4tF1WPssXIipnSFfUfBLfn9FnunZR8gd49wzlzo lgXEg2luSsTFabFGWNjILtto/ncboK/lYOJe4HjSu/E6i6rI3terNRjM15u4kwITR+Bn sN7FlZDEHrRZDRjZzy5xsJ0Mrr/PWRpYHrv/v6KA11u9Vtmf4nmfmXC88U4WiFmaaCj+ OeTNsOENUJGkEYVE0Yyh15uQEJW/RVKmJ9UZOegBo0FBAXuiqOl+K1g4sX1nXqU6EUfu UFWDgSrh/c/XgfnNvKaNhEDy/nxwMvSdvAA/8Z432U9trGB+OKtLfGztVpG+MvaBVHFo w6Tg== 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=lDSdgzofiF3UUOGjVqFOtFLtK+/SSkMIw++bLxRP9eA=; b=mo88fYQiEeg6RryLzHggzXE/4XYl4M+bn9k4TbYw5vXKXSf15x8qr/TQu9jxPS88x+ CXbNzuut3UficfN9XRBJWl4/kzPaFHQb09D7vf/+OPLUsgpHnPfsCfIMsq29x4yvHLQ0 xl2D6v/Cz+MPJ0mLVS1S+nwvCp74CIN6GzbQoQMfIhXJtOKjcdEZ3EMuYVrUiny65Flg DoiWbABkk7/cbRfm2UCK0D0dRXZhdg/rnvhgTS0uGG3nubNzAnzemsBjn+E/o23YixEi vZRDtUmW3Ci9Welshb9Td9s3bATCbukzBlIvgkRf4tTZyMikTLtaftvbV8UN0rlkFC+W a94Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=un0jsxsW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l17si3087483ilk.49.2021.07.12.03.51.57; Mon, 12 Jul 2021 03:52:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=un0jsxsW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357031AbhGLIQ5 (ORCPT + 99 others); Mon, 12 Jul 2021 04:16:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:54238 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241533AbhGLHcz (ORCPT ); Mon, 12 Jul 2021 03:32:55 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0643E61167; Mon, 12 Jul 2021 07:29:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626074995; bh=H7K8QcNfcYG76IHBiBB1NtHUrfWLWgRNm3vfLuoBcwA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=un0jsxsW4F8R0QvPnoq8Ic7n5ECrbxF38vkA34ESo3Tv9pn+i2RVUGfphB2bE/mLo uwnJmuxbKTaRtSGITV7ny/atA5j/kUQTFQ5Qc9/Fqn6XB9ta4d+S33VNpfXletjCpH Sh+bvHgBQ/upHjwrIpAzC2dNy7kChwMyAjupK81g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hulk Robot , Zhang Xiaoxu , Trond Myklebust Subject: [PATCH 5.13 067/800] SUNRPC: Fix the batch tasks count wraparound. Date: Mon, 12 Jul 2021 08:01:30 +0200 Message-Id: <20210712060922.681031243@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060912.995381202@linuxfoundation.org> References: <20210712060912.995381202@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhang Xiaoxu commit fcb170a9d825d7db4a3fb870b0300f5a40a8d096 upstream. The 'queue->nr' will wraparound from 0 to 255 when only current priority queue has tasks. This maybe lead a deadlock same as commit dfe1fe75e00e ("NFSv4: Fix deadlock between nfs4_evict_inode() and nfs4_opendata_get_inode()"): Privileged delegreturn task is queued to privileged list because all the slots are assigned. When non-privileged task complete and release the slot, a non-privileged maybe picked out. It maybe allocate slot failed when the session on draining. If the 'queue->nr' has wraparound to 255, and no enough slot to service it, then the privileged delegreturn will lost to wake up. So we should avoid the wraparound on 'queue->nr'. Reported-by: Hulk Robot Fixes: 5fcdfacc01f3 ("NFSv4: Return delegations synchronously in evict_inode") Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Signed-off-by: Zhang Xiaoxu Signed-off-by: Trond Myklebust Signed-off-by: Greg Kroah-Hartman --- net/sunrpc/sched.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/net/sunrpc/sched.c +++ b/net/sunrpc/sched.c @@ -595,7 +595,8 @@ static struct rpc_task *__rpc_find_next_ * Service a batch of tasks from a single owner. */ q = &queue->tasks[queue->priority]; - if (!list_empty(q) && --queue->nr) { + if (!list_empty(q) && queue->nr) { + queue->nr--; task = list_first_entry(q, struct rpc_task, u.tk_wait.list); goto out; }