From patchwork Tue Jun 21 23:00:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12889907 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 987BBCCA47E for ; Tue, 21 Jun 2022 23:01:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229575AbiFUXBR (ORCPT ); Tue, 21 Jun 2022 19:01:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354570AbiFUXBP (ORCPT ); Tue, 21 Jun 2022 19:01:15 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 533691E3F1 for ; Tue, 21 Jun 2022 16:01:11 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id j24so202736wrb.11 for ; Tue, 21 Jun 2022 16:01:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0bWN01KDsEtX3px5S5dycuW8Av5BE9tOjbj4Zfv5AN8=; b=YeVjH9CPFWBiPpKKP35U4UyXqK5bs/aCplRrCY8Pau0oprbJdQRrazlN1/UiaD0Aef ysBxXyLBG+pnr6TR8tfYjWINONXyNphQPyd4bGYFGiHKGJfU+DToyhlCnFLIy4qK54N1 glxukjXpvTUsjb6LZ1ibDnEY8fash3pxNNoMm8h23ud+Bc+MZ3bG7qSpNOp0w1gs+SXJ QJqDzKib4dzqZowZ7vTcsDahnaQiRqTxcF8joACgPMlK8pevyq0adrcyxPMwkrrGODvl 4z3eTXNvkupGHZIjVifODxRSzSr/sRW+6KKwc7d3T307lVmicRofHBLlFYK+GYMj2XEH F7ZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0bWN01KDsEtX3px5S5dycuW8Av5BE9tOjbj4Zfv5AN8=; b=drfyZBOOwvwlVit9K5p4ACp1Js6yRYVlMLTN8Dfj4pqM7OQpDkc0BnRCxIRERC0HoQ zCy1ecZjWDvLl9SPSC7ZmpFa4LucSFPRSWbQ4OCBgty3v/IHIeLjrxgSIQRcLYNWu2nj eSxO+WOcd25q/BTqg3qXKxtZnPUFdrUhOzxhQjKA5rlxuDcEq+3YrHVYATP615QdotnL gh3BFHiwK2D+rF5FSa/ljbMCorfia+RnAld33J4aQuvvGkqBedEm6hRlUnPuM2oOaU03 UC386ySOQd+1usm7k7qvQld4UonInj/2PeKuYs+NeLmZlzwI2EmtwadE/7GtXkR03YLf ndgw== X-Gm-Message-State: AJIora+jNIspLSDKqkO5o1Gt9h1hXf7J6iBsUQIIIlaBjKz8ArYdV3mc 6JmSDSYzhgVA7ptmM0W62RBTvbKeNew7MxEb X-Google-Smtp-Source: AGRyM1ssh9izaB49b/HERb/lzllvntfVZSo3Pt5gzGWFudaeLvApG3aS/y8OEO/Tadzq4QIN9T6aag== X-Received: by 2002:a05:6000:1542:b0:218:549a:2a8e with SMTP id 2-20020a056000154200b00218549a2a8emr297171wry.314.1655852469598; Tue, 21 Jun 2022 16:01:09 -0700 (PDT) Received: from 127.0.0.1localhost (188.28.125.106.threembb.co.uk. [188.28.125.106]) by smtp.gmail.com with ESMTPSA id q2-20020a05600000c200b0021b8ea5c7bdsm7630462wrx.42.2022.06.21.16.01.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jun 2022 16:01:09 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH 5.19 1/3] io_uring: fail links when poll fails Date: Wed, 22 Jun 2022 00:00:35 +0100 Message-Id: X-Mailer: git-send-email 2.36.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Don't forget to cancel all linked requests of poll request when __io_arm_poll_handler() failed. Fixes: aa43477b04025 ("io_uring: poll rework") Signed-off-by: Pavel Begunkov --- fs/io_uring.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/io_uring.c b/fs/io_uring.c index dffa85d4dc7a..d5ea3c6167b5 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -7405,6 +7405,8 @@ static int io_poll_add(struct io_kiocb *req, unsigned int issue_flags) ipt.pt._qproc = io_poll_queue_proc; ret = __io_arm_poll_handler(req, &req->poll, &ipt, poll->events); + if (!ret && ipt.error) + req_set_fail(req); ret = ret ?: ipt.error; if (ret) __io_req_complete(req, issue_flags, ret, 0); From patchwork Tue Jun 21 23:00:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12889905 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 591EDC43334 for ; Tue, 21 Jun 2022 23:01:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354574AbiFUXBP (ORCPT ); Tue, 21 Jun 2022 19:01:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353965AbiFUXBO (ORCPT ); Tue, 21 Jun 2022 19:01:14 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B9C02AE31 for ; Tue, 21 Jun 2022 16:01:12 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id i81-20020a1c3b54000000b0039c76434147so10048760wma.1 for ; Tue, 21 Jun 2022 16:01:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3n8cR1jyiLtvKt85781uU9I+x3oanxTHrlGgjHJZt0U=; b=j8oG2VNzFN+F2fEpSxXK/CPjjvzRM+e67WWlKhjcGjtuYePO1WcGdzzbvAj0IO8Bso QgE4yN/WIvnJ1hmJt+VADuGBV8HLrwwYMP/EOSlwYIii3k2qxIt3pai4xOtDv3O5RGTO ltpRcHWaQyTOkVLs4GI356xpU0T4g4h5PDWhrlL4weYyf13WDLmOU42pRaIwahGWR96Q HQUPCLzL29MPA+e/AeJLrKb9kgL2yvyQMOzqArsYmq58KpJbDCGlcpbTlLktgXYeOnuj CIt5/vI5npJUlXEDRhS9rMIaPC2Dv1nYlujtyKQQh6W2oaS1IPh8zIyq+AcSkaFXmb+f AaZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3n8cR1jyiLtvKt85781uU9I+x3oanxTHrlGgjHJZt0U=; b=di2jm0TNj1L2zsmwNwj1ZkqIQejTQ1AnrbKowB3mK4PFYUl5ayA8YUtS0qVzdc8dk5 pciI2TTENOGGF0hUcFPczwj2Mhaj+fnZIUIWoUjdHphtzjo0PQpRuvJHxyqIKz2z4gNg rBlsgmM4PPOpiKHA3rb6c5mvDpZXj8yiLEjuEx8eW9KAn67btDwC8+QprU8R1PaX4ww5 2LG4fJISile7EBmRIqXAgT8ipQtEb4tJ9DEEQNsSbtSpV0DfB9w8yHzLZm0MyZ0t9/ko +/58i6xOc/f/3l5KRQRRgde9AM+MkpNaLJ+SOEPA5zDUFKOzTlXkr0Syu+VbbwxZwSwU RJTg== X-Gm-Message-State: AJIora+5dIMbirGI3hST7jGrAOJ4P1uzF9NuVxqEC+ALbidVFP4VnWaG qsp5IB+duCkfagT+q6P3zWInaOc6vFo1MRG8 X-Google-Smtp-Source: AGRyM1uYzpGWX9uTK1SAfTqtu+sA2EYJ+CjOcrwUnSKjuPGEdHDhQTD8QOfnBjkT45B+e6bisd5sow== X-Received: by 2002:a05:600c:1e0b:b0:3a0:2965:b315 with SMTP id ay11-20020a05600c1e0b00b003a02965b315mr235559wmb.125.1655852470601; Tue, 21 Jun 2022 16:01:10 -0700 (PDT) Received: from 127.0.0.1localhost (188.28.125.106.threembb.co.uk. [188.28.125.106]) by smtp.gmail.com with ESMTPSA id q2-20020a05600000c200b0021b8ea5c7bdsm7630462wrx.42.2022.06.21.16.01.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jun 2022 16:01:10 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH 5.19 2/3] io_uring: fix wrong arm_poll error handling Date: Wed, 22 Jun 2022 00:00:36 +0100 Message-Id: X-Mailer: git-send-email 2.36.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Leaving ip.error set when a request was punted to task_work execution is problematic, don't forget to clear it. Fixes: aa43477b04025 ("io_uring: poll rework") Signed-off-by: Pavel Begunkov --- fs/io_uring.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/io_uring.c b/fs/io_uring.c index d5ea3c6167b5..cb719a53b8bd 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -7145,6 +7145,7 @@ static int __io_arm_poll_handler(struct io_kiocb *req, if (unlikely(ipt->error || !ipt->nr_entries)) { poll->events |= EPOLLONESHOT; req->apoll_events |= EPOLLONESHOT; + ipt->error = 0; } __io_poll_execute(req, mask, poll->events); return 0; From patchwork Tue Jun 21 23:00:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12889906 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E91ACCA473 for ; Tue, 21 Jun 2022 23:01:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353965AbiFUXBQ (ORCPT ); Tue, 21 Jun 2022 19:01:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229575AbiFUXBP (ORCPT ); Tue, 21 Jun 2022 19:01:15 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54C942E6B8 for ; Tue, 21 Jun 2022 16:01:13 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id w17so20891800wrg.7 for ; Tue, 21 Jun 2022 16:01:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nn2a2KKHnEW+tenzPHxmOsTwnVub8z9r9JtzehG3s78=; b=LmEWgMlgzvM5CoW3RtNLGBNeDDtQdWQdoKE2VE4MWv5AJtAJj3k/NQ1OM38l5a2u+f b8PYQDPssWrZjV86OtGG59nOeQ5H1hRE2JevwpUX4auIIGgMDrGc1No289YeHtnTboO+ ycIrlMwNKAxBMQasNFB8xO7+FBq+bPjW+opyTILAmaNcVbU0e9ohTbKZGljzHRBul5fJ yWTw9Rpr6etv6Zac0dQJ2EVQpb3K4cll3/XzuFh5Pplg+dg8f1DJ1dmeFGHQGKP5bLZP arsVgMy+Ku2JL8iXYJfqkDTJQMIbGN1zzOzjsnQUnXug6jEFpQmmV6psR1oHhByInw6u DlbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nn2a2KKHnEW+tenzPHxmOsTwnVub8z9r9JtzehG3s78=; b=kuhF7Q0YnY5jYkqZTPOcnuLSbO/WPdZ6sJaJvxUdIeozKatLHNtqZ/NPDK0YoHF69T AaHJ1+QuWw4jdCPb0/3f042d9mPyKoAobGmxQYXuM+ceOPKhvnudqjF0q/eMLwaUp19V dl+HIjYLdbrmHD7n/cVggxmdnX430tcjuZazjK3ohPUcRtd5beTmeL3BfbswWMTSHFf4 5RukEW31EXo3evZ5TiOyiQbZ/ZBZq9ebmzyYkbdwawJrUqK1gdhiDnhbS7ta0QX0um9X n9a/OydHbjsqCxjh7EosCs84+N2m7ZikzU2t/756TMnNu0Z0sZbV1z6I9LAXk+JsgEV0 99+g== X-Gm-Message-State: AJIora9XsjWa5FFzM9piQzGBvq3l/x+Q5vtrhgtw+C9RARJVIrMHPQyU wQimpMEeIA1wy2Moz7HFNK2w7+J/Xmq+askQ X-Google-Smtp-Source: AGRyM1sYEHLf9fkLYZFWZCYQXyfSlQW6y8gudqQ06j9IBtoE5sLScSE1cVZfr6IMkYnajclOuwz3Mw== X-Received: by 2002:a5d:5234:0:b0:21b:829c:3058 with SMTP id i20-20020a5d5234000000b0021b829c3058mr286200wra.13.1655852471632; Tue, 21 Jun 2022 16:01:11 -0700 (PDT) Received: from 127.0.0.1localhost (188.28.125.106.threembb.co.uk. [188.28.125.106]) by smtp.gmail.com with ESMTPSA id q2-20020a05600000c200b0021b8ea5c7bdsm7630462wrx.42.2022.06.21.16.01.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jun 2022 16:01:11 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH 5.19 3/3] io_uring: fix double poll leak on repolling Date: Wed, 22 Jun 2022 00:00:37 +0100 Message-Id: X-Mailer: git-send-email 2.36.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org We have re-polling for partial IO, so a request can be polled twice. If it used two poll entries the first time then on the second io_arm_poll_handler() it will find the old apoll entry and NULL kmalloc()'ed second entry, i.e. apoll->double_poll, so leaking it. Fixes: 10c873334feba ("io_uring: allow re-poll if we made progress") Signed-off-by: Pavel Begunkov --- fs/io_uring.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/io_uring.c b/fs/io_uring.c index cb719a53b8bd..5c95755619e2 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -7208,6 +7208,7 @@ static int io_arm_poll_handler(struct io_kiocb *req, unsigned issue_flags) mask |= EPOLLEXCLUSIVE; if (req->flags & REQ_F_POLLED) { apoll = req->apoll; + kfree(apoll->double_poll); } else if (!(issue_flags & IO_URING_F_UNLOCKED) && !list_empty(&ctx->apoll_cache)) { apoll = list_first_entry(&ctx->apoll_cache, struct async_poll,