Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2718731pxv; Sun, 11 Jul 2021 23:43:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxGtZfC5+AFgXJ8C+s7gwRKwv/D0v1bGSg8xGbcEivDp5IO9csJG0LulPZhemgcRVXW+krt X-Received: by 2002:a50:fe97:: with SMTP id d23mr1212250edt.169.1626072200375; Sun, 11 Jul 2021 23:43:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626072200; cv=none; d=google.com; s=arc-20160816; b=f1+db4cbJm+NQzrLl31ahppcWnro7K07sRFR74/yrVA++/4gVAg52HDGYcVH2LQliQ e/1Aq6CjY6j426O1eJWYcdsMyT3e/zpzyo9FUZvF40ojzD5CIKIguJHrUCqEhO481TmL gLEP0lJI5Q+SzBfG7XHAi5kvq1Ji7Uyqb4C8+FCYf87FKJdhZmj5pp2wBRRmZK4HNTO5 nJEWSplIC7SbxTxQ5piNpX49jwu2Sxfwibu9QJ1nyRiqNvDxoX43IeLfmEdHF1DRn+uG 2DkAu+SMJgVV3fe4drga54w3sYSMnLtBosFeN2HMFABS5ee2SZ/MnTpmffwOiFA4aIgm pg1Q== 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=xgTQcQFkQVmZhi5LHkpVEtxDeDU0BP845PliJxfBBu4QGsvgD7mXdQky+3NewRRqXr kT+ljOoyGrNX4P0jBchHLIxAWy976faBsJIoaUBYOhToDa7Abp+/a5voQCfu/PlJ/eM7 4XrULiUvg7Zs0lojOhvFMbXD/BUphrFx++9FJyyYqqL4/nLQ6Px3U9DnNtgeEiqk3bh+ oRLG7WgZvDcRca5mCLR3L0sBkUYqFgtt0VxSC8LMaYru97Bj32GFg2HlIBtWdEGhmUR1 VBORErbLEjd6xvV37nBhMuhBQ1olLGgyzWT5MyfLHx/R2Nucfx75kUXUZPrU2rcZrSzv V/Qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=M2l6lchD; 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 7si15927098ejh.506.2021.07.11.23.42.57; Sun, 11 Jul 2021 23:43:20 -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=M2l6lchD; 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 S238959AbhGLGob (ORCPT + 99 others); Mon, 12 Jul 2021 02:44:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:55158 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233634AbhGLGds (ORCPT ); Mon, 12 Jul 2021 02:33:48 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 119876101E; Mon, 12 Jul 2021 06:30:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626071408; bh=H7K8QcNfcYG76IHBiBB1NtHUrfWLWgRNm3vfLuoBcwA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M2l6lchDdPp0QouJj9gHLilXnOa2FKZWz8TUSIFj127GtankdL/X9iaFubk0edyES PT9r9wtXfVWGBlrcoRYIA8jyv+oTGCfz1TkqL+vFSwG2NAVQTARMa8nL/AJiOS/GUn Vhlwf4W60ckXyUKijzn/lfNu5soV96d6ppZvHwZE= 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.10 056/593] SUNRPC: Fix the batch tasks count wraparound. Date: Mon, 12 Jul 2021 08:03:36 +0200 Message-Id: <20210712060849.267058422@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060843.180606720@linuxfoundation.org> References: <20210712060843.180606720@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; }