Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2663718pxa; Mon, 17 Aug 2020 15:56:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+81rUbeGG9zllIsCjDOKtuw2moYqP8LWzziPzkO05l0H8LGARXlHhzO3cw51fChx1JfnZ X-Received: by 2002:aa7:d948:: with SMTP id l8mr17372311eds.371.1597704967575; Mon, 17 Aug 2020 15:56:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597704967; cv=none; d=google.com; s=arc-20160816; b=Up1EkXFetpufIO8ZG1Xhb0AihCst7GYID+DcVwKD33yXQzSs4tqfhOnFrZbP8ktvQd LiEX8GW+4EO8Mbpf9aST37vcq3CwAJtpjUiobIs6DyXIpF1n+nvRqAgG3pATw9EQxepx dT5rkDPdS/RcVZHLvJ8rR2s4I5wwi0DLKCiQHuIUNNYrp9g0kHpK6d5HGGewdaKxSxqX SE33v1z/ZzJWz59I4AFvePW3r+V+/X2celDvvnCW/VfwIvTTG4lKq5lN1djMN9aJyqNa tm70ZnW4j2BvUillE/dJsttobtRE2IHqptE+9TwwtT48Of9JQ2qub/4KL1proC1PY/vn esvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=oKCWxq3/TI1hxlOE+v7zcchl08R//e7jMjw6MiiJD5s=; b=RwJEcRI/EBniykRAR0b+z8fO8MOQnSyIcuadEa5L7RWeu2mco1FR96nmctAzZEczKC R8OWlYphAExgu1SSXuECiL9+9xQlyI90XiahO1rNXZ4BeTZuLgDu6EOCooPg9Hdkak/Z +PpklG9+oiFPouj6GLsnTLutpvIT7fLnoR0xvtfvBKuVJytkhlXC5cEZpS7OIdx94jXB 94nIBqwBUdpe7O4S27Eljtnwu/rxMk8RMZGnQkkJQCTQ/t1qhGZjoGbl1qKIsajEPNLN AVlGEen0n/KipQFVxMN6ezHcXYnyWxPYboRFHh/Uv8RWrX38q9meyuTPqtHHFKHjw1X5 AcrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0khGRhWu; 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=fail (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 y21si12116603ejj.370.2020.08.17.15.55.44; Mon, 17 Aug 2020 15:56:07 -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=@kernel.org header.s=default header.b=0khGRhWu; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732350AbgHQTmP (ORCPT + 99 others); Mon, 17 Aug 2020 15:42:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:54744 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729339AbgHQPYY (ORCPT ); Mon, 17 Aug 2020 11:24:24 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5FA19233E2; Mon, 17 Aug 2020 15:24:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597677863; bh=Jptlc0QXE/ISLzp4b1//9H8rIqEhyvUeWJqL+PW7trA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0khGRhWu5P60XRiaLyb26j0xB+QPHRNX9fq2JjbY3AaC67rYU4jfRiwlEBUolbWzL i0BSCssfNF3r/I1PN742uJQO3WtQ3jyJ5KhpqR6yLS+R14lg1Ras96ZNokjYjefCRZ Z2fb+qNum6qjIfrpCx7Gu/phmz4EAaEH04oLqihg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pavel Begunkov , Jens Axboe , Sasha Levin Subject: [PATCH 5.8 136/464] io_uring: fix racy overflow count reporting Date: Mon, 17 Aug 2020 17:11:29 +0200 Message-Id: <20200817143840.330114797@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143833.737102804@linuxfoundation.org> References: <20200817143833.737102804@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pavel Begunkov [ Upstream commit b2bd1cf99f3e7c8fbf12ea07af2c6998e1209e25 ] All ->cq_overflow modifications should be under completion_lock, otherwise it can report a wrong number to the userspace. Fix it in io_uring_cancel_files(). Signed-off-by: Pavel Begunkov Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- fs/io_uring.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index d732566955d37..1d8761a9f3b88 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -7536,10 +7536,9 @@ static void io_uring_cancel_files(struct io_ring_ctx *ctx, clear_bit(0, &ctx->cq_check_overflow); ctx->rings->sq_flags &= ~IORING_SQ_CQ_OVERFLOW; } - spin_unlock_irq(&ctx->completion_lock); - WRITE_ONCE(ctx->rings->cq_overflow, atomic_inc_return(&ctx->cached_cq_overflow)); + spin_unlock_irq(&ctx->completion_lock); /* * Put inflight ref and overflow ref. If that's -- 2.25.1