From patchwork Sun Nov 5 22:30:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dylan Yudaken X-Patchwork-Id: 13446151 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F2391A715 for ; Sun, 5 Nov 2023 22:30:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Bul0YyWL" Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C782ADB for ; Sun, 5 Nov 2023 14:30:25 -0800 (PST) Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2c6b48cb2b6so54793701fa.2 for ; Sun, 05 Nov 2023 14:30:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699223424; x=1699828224; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7C2CzeiGE+2knhPabDRWXJ9QnU85q1JAUGHIfJJn7fY=; b=Bul0YyWLm/6L5lPNbAnadLusLDiuqr5SYNWOV4c5LAiCWRyl+4y6Kc17yHCiC0KifA h41hpZ9MWVCVJ/HBmfyy/V6ONfCpyC9IsIOg5Iq0vUGCYIzcQ5yLs/Rf93p67NGPczzT 0DEXx94d7rCwl+pVmo+pxGgHgz3XIe8Ubju5AgIIjSAjo7dTzAWFGQsh08xgKqPDE5m/ NQBx2v9MjD7xb/5qgnjbR+5hjLacsd3zA8Q9d/ZPgdVbNUusScowWTAeb+Avrg1TRqxQ Y2bsuy38dW6DZuITDbQJ+H7RI33HPXsHqTrVTdYD2tRBHhzPEf07wPQKBxAIMF+eZM2x yayQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699223424; x=1699828224; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7C2CzeiGE+2knhPabDRWXJ9QnU85q1JAUGHIfJJn7fY=; b=U8Odtl7hzYfwvmPtTf5qcFYw9noQpB/e+avgJRgoBHh60jNPQwBw+gVqCc2AZ9ttD/ lLhpr6UD1f0s1WqagXZO1D4vXk6cSldLoy5FNGZeAOfgQ4BGxD+QkF3k0abO51DWgzoQ zH1ugEIMJ45gUIZjOxSxkyR2BuoOqMd9OyVqQVAZOsxIt6b7YfYinHnlIU+ESffmVHoE qLBXIatg/NtVHSykcigXy0BuVm4iXZ/6uviCBXvdH2UZQpz6+J1K+7kCPfSPSGjI84y7 iPPwjiWdoDtcb0WATfeiVpNT3LfG77c/N1MHAYvlLvN3Rvotx9G7huCTSb/hZKwxlGEH EbqA== X-Gm-Message-State: AOJu0YxACBZJ7+42svisBYkMfXz6Ew4xaucjVf/tbxAgJYm+pLyw/DYW MU9eXfexJSrqdxX240WBE6kYZBakdRo= X-Google-Smtp-Source: AGHT+IGt+6xB6iJYaxWOLPcMYgZsxbwUFDkxrrqsw28dCvm00eJwd6mWkdWGJ1KLc4pV1Yly0EiUyA== X-Received: by 2002:a2e:880d:0:b0:2c5:380:2a10 with SMTP id x13-20020a2e880d000000b002c503802a10mr19091269ljh.25.1699223423462; Sun, 05 Nov 2023 14:30:23 -0800 (PST) Received: from puck.. (finc-22-b2-v4wan-160991-cust114.vm7.cable.virginm.net. [82.17.76.115]) by smtp.gmail.com with ESMTPSA id m26-20020a05600c3b1a00b00407752bd834sm10244267wms.1.2023.11.05.14.30.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Nov 2023 14:30:23 -0800 (PST) From: Dylan Yudaken To: io-uring@vger.kernel.org Cc: axboe@kernel.dk, asml.silence@gmail.com, Dylan Yudaken Subject: [PATCH 1/2] io_uring: do not allow multishot read to set addr or len Date: Sun, 5 Nov 2023 22:30:07 +0000 Message-ID: <20231105223008.125563-2-dyudaken@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231105223008.125563-1-dyudaken@gmail.com> References: <20231105223008.125563-1-dyudaken@gmail.com> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 For addr: this field is not used, since buffer select is forced. But by forcing it to be zero it leaves open future uses of the field. len is actually usable, you could imagine that you want to receive multishot up to a certain length. However right now this is not how it is implemented, and it seems safer to force this to be zero. Fixes: fc68fcda0491 ("io_uring/rw: add support for IORING_OP_READ_MULTISHOT") Signed-off-by: Dylan Yudaken --- io_uring/rw.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/io_uring/rw.c b/io_uring/rw.c index 1c76de483ef6..ea86498d8769 100644 --- a/io_uring/rw.c +++ b/io_uring/rw.c @@ -111,6 +111,13 @@ int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe) rw->len = READ_ONCE(sqe->len); rw->flags = READ_ONCE(sqe->rw_flags); + if (req->opcode == IORING_OP_READ_MULTISHOT) { + if (rw->addr) + return -EINVAL; + if (rw->len) + return -EINVAL; + } + /* Have to do this validation here, as this is in io_read() rw->len might * have chanaged due to buffer selection */ From patchwork Sun Nov 5 22:30:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dylan Yudaken X-Patchwork-Id: 13446153 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 54EFE1A726 for ; Sun, 5 Nov 2023 22:30:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Wfsk7Vrg" Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE23CDD for ; Sun, 5 Nov 2023 14:30:26 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-4083f61312eso29984875e9.3 for ; Sun, 05 Nov 2023 14:30:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699223425; x=1699828225; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TjbxQQROHn5RaXhXiYTu3jRMDbxVpPecsYg591f68Bo=; b=Wfsk7VrgKAOFwtqJa2NsCEIp9JvXySPy4kt6oVbqpdsZbA0fUtHBMxQt7j0UrY3lNi FyUdW3q/87ibZMuokEEJVSUvwhGpYw6SM38xMHyvUhkbMfPxARRubHcCJlgfIYpC4n6k jDJ+hSND1yPZRNxloTmOk67vhxqn9QxMJ105KlmEZqQuhdXhZa5ECLk6cEAzbeGuG6Nc llZtoMF84WlTmHfQL5Pt8KUpx/jmZEW5ERjDblfcMm8Mc1/ZpUN29vr1C2uFEmy6fRXm ZLZ3E9I9BwbVbRsA6JjgXtkysel+aG9ySBzSqOFycS9Vmk2Iz5M/LW1e4SobYHNW1/Y3 S1Lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699223425; x=1699828225; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TjbxQQROHn5RaXhXiYTu3jRMDbxVpPecsYg591f68Bo=; b=w+N6qM7APbu+L8l4BepwXi8oT/KXwOxGyt0x/3CyFnwLne9g8lc/7zVA1EX6TBrFKz PzgBo+3eZ76vJ9CtnbhPfktZtUWbHCH+m6GPt7Y46x216Q58aVVhiVQhx2zizuVh6KDi kJXs59yiyYf3avySXYoL0oUN0v0Ye8YSi/QFQ+03pVSEeHDaaOnbYfsCwXjChMJvOqMw 3ai9I1FJR/RLPS3et1IqclL+WxARe8J253TOdOym9k+M0LgwNq5AFQJPTi5ITrR22BKK ZMRU3Jk7GT9cR/R8ZZ2zH5kayOuaktq2av1F9iMubQgObTTmVUO31BLnCYW9I8GtxL+I qAPQ== X-Gm-Message-State: AOJu0Ywp3qF+PAdHP/v4uHmSz7Ggof5LOHC49YmqAaB9UzU2Qt9M6qO0 t3hofCGnb5a7FzuG6i5OmmnUaX6NpPE= X-Google-Smtp-Source: AGHT+IHSbWcqO6Upd4ctzD0hW15unzCqDJY4vHDqZObY1jmcT9eHludIvisAkYOtkGlVOdSI/9QwKw== X-Received: by 2002:a05:600c:1f93:b0:40a:25f1:7a28 with SMTP id je19-20020a05600c1f9300b0040a25f17a28mr272822wmb.40.1699223424836; Sun, 05 Nov 2023 14:30:24 -0800 (PST) Received: from puck.. (finc-22-b2-v4wan-160991-cust114.vm7.cable.virginm.net. [82.17.76.115]) by smtp.gmail.com with ESMTPSA id m26-20020a05600c3b1a00b00407752bd834sm10244267wms.1.2023.11.05.14.30.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Nov 2023 14:30:23 -0800 (PST) From: Dylan Yudaken To: io-uring@vger.kernel.org Cc: axboe@kernel.dk, asml.silence@gmail.com, Dylan Yudaken Subject: [PATCH 2/2] io_uring: do not clamp read length for multishot read Date: Sun, 5 Nov 2023 22:30:08 +0000 Message-ID: <20231105223008.125563-3-dyudaken@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231105223008.125563-1-dyudaken@gmail.com> References: <20231105223008.125563-1-dyudaken@gmail.com> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When doing a multishot read, the code path reuses the old read paths. However this breaks an assumption built into those paths, namely that struct io_rw::len is available for reuse by __io_import_iovec. For multishot this results in len being set for the first receive call, and then subsequent calls are clamped to that buffer length incorrectly. Fixes: fc68fcda0491 ("io_uring/rw: add support for IORING_OP_READ_MULTISHOT") Signed-off-by: Dylan Yudaken --- io_uring/rw.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/io_uring/rw.c b/io_uring/rw.c index ea86498d8769..b7f7fbc28032 100644 --- a/io_uring/rw.c +++ b/io_uring/rw.c @@ -417,6 +417,8 @@ static struct iovec *__io_import_iovec(int ddir, struct io_kiocb *req, if (!io_issue_defs[opcode].vectored || req->flags & REQ_F_BUFFER_SELECT) { if (io_do_buffer_select(req)) { + if (opcode == IORING_OP_READ_MULTISHOT) + sqe_len = 0; buf = io_buffer_select(req, &sqe_len, issue_flags); if (!buf) return ERR_PTR(-ENOBUFS);