Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3698361pxv; Mon, 26 Jul 2021 09:39:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvQlRT/6ZEt2NeKrQ+PgcgqIBHYAdsbjpvC+xblI0KdbWKkGoZR8PY6tgAqMzcuo1NC/ed X-Received: by 2002:a05:6402:1d4d:: with SMTP id dz13mr22688550edb.67.1627317581361; Mon, 26 Jul 2021 09:39:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627317581; cv=none; d=google.com; s=arc-20160816; b=Q0SFvcrdqxs18A2xfotf4A0bG/otNCU7A0dVv1wSQB6YaHJgiOLrYpPtYW6t/4CPTQ Q+zbOaF6BMqQICH1MIRZONan6FCab2I/MVuXf1GtJFsI42ZwDgRiWfEOLPf1MGhvKwN+ xRiYTTlUUjbKvrheQvvSr5xi0cWv5Cod9nNi+FpmgG7h8GD5+D9h9yRS49LEkqnsq6B6 HVoHB0RryArhj7PM3i1bDgN0YscCkQKEyzi2alq8ltzi7gcTlF8srUA+gocgDIIOf/Dn RFM0GlhyzFPAp9w3qp23VULyipSwFQB9NYiJiwdlt+hnV3MDWP9hpW6KFrclTsTwYL4s dxlw== 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=uUE3ektQ0FYiAiAiGJWARr7aj12i0hgIN0tMCzgoWOs=; b=zAhnj+Klp/p4cWBx8b8G+7sS9h4B6sXvVsg5Edno3+9gTZg9zOB6BLQPTjghsgrdnF SAxxhLw/nUIstXvITjZmcy1teI23uiT2NFsU7wv0SQDpdf2CEH4faxGHxRMJpeEXQUWC qOndPMxjAr9MO+JFr7cypZOSmcL8fEOx3kzB4Zar1fgDir/Mv0ErA+VTM29fvlGLI0lP kAxTE5vpW1FxpI0hSzlV+TSxi1nxYuQzWPSso1/GPzzrrdUREDQS/UU2kIhY7YPbhu5D 9ar+H6Mpc/dMBXgLMknibboqsQ9Emt6NlHR4CsxMMXVywASZ7A1dV1PiMUgb3DHQ0QjV MpuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GLq9ImDK; 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 os14si363814ejb.696.2021.07.26.09.39.18; Mon, 26 Jul 2021 09:39:41 -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=GLq9ImDK; 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 S239161AbhGZP5L (ORCPT + 99 others); Mon, 26 Jul 2021 11:57:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:54386 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237349AbhGZPgI (ORCPT ); Mon, 26 Jul 2021 11:36:08 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DDC2960EB2; Mon, 26 Jul 2021 16:16:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627316196; bh=MwopbsRfygVLJ/vVysBHtklxj8OtoAX7NjADgmtNH6U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GLq9ImDKcxH2Tub0owGuymv2ivdgbtSjO3JVLOIX8nD4kn4kcA3VABMGUzVPkKG5K G5Cs5Aj9+DZB/qq1yIYfJ0Xp67fg0JUMZoQFe6ZxEYVpJYASYswyz3EBOAG++wnYCo FQLfwh6Uha7O8nmG8iIym39nPV48Eh4yxpRkTAv8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pavel Begunkov , Jens Axboe Subject: [PATCH 5.13 192/223] io_uring: explicitly count entries for poll reqs Date: Mon, 26 Jul 2021 17:39:44 +0200 Message-Id: <20210726153852.478104432@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210726153846.245305071@linuxfoundation.org> References: <20210726153846.245305071@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: Pavel Begunkov commit 68b11e8b1562986c134764433af64e97d30c9fc0 upstream. If __io_queue_proc() fails to add a second poll entry, e.g. kmalloc() failed, but it goes on with a third waitqueue, it may succeed and overwrite the error status. Count the number of poll entries we added, so we can set pt->error to zero at the beginning and find out when the mentioned scenario happens. Cc: stable@vger.kernel.org Fixes: 18bceab101add ("io_uring: allow POLL_ADD with double poll_wait() users") Signed-off-by: Pavel Begunkov Link: https://lore.kernel.org/r/9d6b9e561f88bcc0163623b74a76c39f712151c3.1626774457.git.asml.silence@gmail.com Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- fs/io_uring.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -4805,6 +4805,7 @@ IO_NETOP_FN(recv); struct io_poll_table { struct poll_table_struct pt; struct io_kiocb *req; + int nr_entries; int error; }; @@ -5002,11 +5003,11 @@ static void __io_queue_proc(struct io_po struct io_kiocb *req = pt->req; /* - * If poll->head is already set, it's because the file being polled - * uses multiple waitqueues for poll handling (eg one for read, one - * for write). Setup a separate io_poll_iocb if this happens. + * The file being polled uses multiple waitqueues for poll handling + * (e.g. one for read, one for write). Setup a separate io_poll_iocb + * if this happens. */ - if (unlikely(poll->head)) { + if (unlikely(pt->nr_entries)) { struct io_poll_iocb *poll_one = poll; /* already have a 2nd entry, fail a third attempt */ @@ -5034,7 +5035,7 @@ static void __io_queue_proc(struct io_po *poll_ptr = poll; } - pt->error = 0; + pt->nr_entries++; poll->head = head; if (poll->events & EPOLLEXCLUSIVE) @@ -5112,9 +5113,12 @@ static __poll_t __io_arm_poll_handler(st ipt->pt._key = mask; ipt->req = req; - ipt->error = -EINVAL; + ipt->error = 0; + ipt->nr_entries = 0; mask = vfs_poll(req->file, &ipt->pt) & poll->events; + if (unlikely(!ipt->nr_entries) && !ipt->error) + ipt->error = -EINVAL; spin_lock_irq(&ctx->completion_lock); if (likely(poll->head)) {