Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3760914pxv; Mon, 19 Jul 2021 08:09:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz1FHVfe3iXHKIlmfbk6Ts3Xyxmy8wwyHM80mNYuFnK3n0YMDRIVxzPdjcRJRWIpTLtekT6 X-Received: by 2002:aa7:c956:: with SMTP id h22mr34504378edt.378.1626707350637; Mon, 19 Jul 2021 08:09:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626707350; cv=none; d=google.com; s=arc-20160816; b=SVRmJc91SMDN03r8qu/GlkOFSEgvbJz3CjBBJe4g6rtwAyrx5xPdtPQNn3CbxlI8Jg kvcikKXStUdqGKGMq+Uf/S6L6QzPj96I1eK9Z/5dyhxjtOUchjfywYsz4DktqAK+5ZH0 ihGtgwBRQONzpaPDb1U9Bow/2uTc9qdMDGp2GD1wYt5umqA4BMhdHhoGSY1sfxNDq+2e MjKcAe85+UsaJmNfQNzunlBhGPhcfe3QoyNrUiGkG5W4LBsgyu8588/lxl0Zb8dC1ULU RWBhJocQHgWYMGJ0e1xfowls7P3+RDuVUPL+VQT6iFJWQzRuBwhp6Xm8ZCHlZ4WLyB7g ncuw== 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=BtMfJOtZN8pJDfNtGBSgEFk5pqESt7j9ZRj2vfGc8Mc=; b=buJ31Yd6ht9C3HCAKYliy+5u4u6bAGfSkjvZySi8vVfoFjKS+omG/aro8+Dzi1N8PU HsTen8VnLP3TRvWv7sx51ciDpDWAfW33PWEL3l5VqF9Q0Ugh96ZrC3UwDlQ0BvMGjcWN InRn+KZ6JkpbS4IKJKByLx7bQ/dftNBOFMOvianchbPFd2McsLYrPHaUwnzX6/5PGQgz o6sV2mFZNWMtwDSX1UbLS7kV24gXUso9vNGbUQzfJ06QqNduaFuBB+hlp3/XQsjG0w8K G454YQYjjifEyMAyZq7ZnXwBNEQL5sDVFcH6kwXaXA9AkuzC/ga7O/duyIryXNTAPtxZ BA1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sP1zy07Y; 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 hr2si21619749ejc.132.2021.07.19.08.08.47; Mon, 19 Jul 2021 08:09:10 -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=sP1zy07Y; 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 S242609AbhGSO0t (ORCPT + 99 others); Mon, 19 Jul 2021 10:26:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:37040 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243880AbhGSOYd (ORCPT ); Mon, 19 Jul 2021 10:24:33 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 954226128C; Mon, 19 Jul 2021 15:04:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626707061; bh=FmAVlWNamuC3GE2YBzJqk0R5gjzAnQP1bm5KdpmSjkA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sP1zy07YTY+cvbz04QAAKVUXdEIpJYfJmLCqiVcqAxSPWoNMrr5tRpvzE0XGfq6ds HccEy7NJteLDv9KCrwgKEp/GsrAFZpwf57/NX3JV/x2G/cfNr8J0xqw47ymAo45XVx wQR6Xxthvg1WNbk3QliFhINQ3U2DfzaH75ZXtTKw= 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 4.9 016/245] SUNRPC: Fix the batch tasks count wraparound. Date: Mon, 19 Jul 2021 16:49:18 +0200 Message-Id: <20210719144940.913158919@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144940.288257948@linuxfoundation.org> References: <20210719144940.288257948@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 @@ -490,7 +490,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; }