From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.46 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796006392; b=Y1oZjrVYmsh1WtfIt3bx67uJT3csrP5r96dxWS1EQVMbxDCJCHRfcnGGAKmuKDsGoL2m IGqrQyxGAfyBPMAj5R26T65Zc2kzhe7auIh0xcyP0Hjb3AuigCFZeMqkX8KrbPjbDh3UK SfxI/KsmUEmuaKfK7xfYJHC6iNmMitfimZHptw1h04FI6o8LCmLJt040gO9iakSXyYtMC mk5snu1p0AHLkfUzcsgbeN2cdJmNxenDGyhoWpEm0pcYfWDpRJqss62VktCD8AyOI9C4r VwUOvuRy1oaS6YC+KPeTXSP1NiEt0xAGw+WLCrm+3wR/aqsLMjuYQm8g+TNwTu3GUtA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796006392; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=FNPcls7hx3APRre2iO7yGHX5VKNaVG/i/796bnfhJYU=; b=j/vu+e6z8xkd4SEF7tjf5CNzO5LD2fp+eGUpb2vI84IMz4w3rrDmofNANRJJ2T4v5tK/ lsKHpULBCEbdVq+0uRd/7uyF3Tl2KvUkbEo98M2n7AlBR0u6cdq0EvIdgUWyapWDz66hc MiZ+dVBBfvJMYMNZNpsbwPo7zwIXEWdjOV15aSjvXO4lIG+zlimowzzZCZXHq4/k398i3 WfJHv9mf5lp/L3Tux0oV6AfBHF/l7fk/dkNVP5p0mVdmI3dTU2gRUB5+KoVQJGJqQCQ1U FJ3R1CnjOVKp0HppKYzLFaWj/3OBaMSC7u/Qt1nuoBcZasGQBf+cQJSZr8XNKEbR9zg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=KCMY6YVH; arc=none smtp.remote-ip=209.85.161.46 Received: from mail-oo1-f46.google.com (mail-oo1-f46.google.com [209.85.161.46]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63AAA606A325 for ; Mon, 30 Nov 2026 02:39:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 63AAA606A325 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=KCMY6YVH Received: by mail-oo1-f46.google.com with SMTP id 006d021491bc7-6de2f213b7aso4030724eaf.0 for ; Sun, 29 Nov 2026 18:39:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796006391; x=1796611191; 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:content-type; bh=FNPcls7hx3APRre2iO7yGHX5VKNaVG/i/796bnfhJYU=; b=KCMY6YVHhPhsy1WmWKIjummERpmp7/cDAajLLZ/btQXCPgO7XC1m5a+VD0eF5QGB91 cF07EL36fyC3b2h31BjwHYuDJyc/FxY+ynumSYOHU1n27UCrCEbfC/mCM6Z2QfG/eUZW mcgOyNoEB+qBh9hst+PpvAw9ajAsZzpRNbZSgqgHlQguomK0vz5F/A1OAVro09Ipi1i3 Yj9vdLb29GphX9a7pU/EcQ52C3ZRYVT5aBEyxSsW4MXiQ+uReP9ZLQlkjd1KU/oopc7h Tcsfk00cXgZu6Rh5kMXW+NYSd26avSrvAAPpAR9WlrO+7kn+IWUJhe40Bn+lXRmFt6xg sJGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796006391; x=1796611191; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=FNPcls7hx3APRre2iO7yGHX5VKNaVG/i/796bnfhJYU=; b=PyVDiotQM1FE+p/UINo30G5I5PQohpJyw527e50NIbkL0EVIjILST8fYipHxIRxWgi Qnenq3HhM/iJle8koqJJ1iCmC6Y2kYZrztFuPCepIDtZCDsjPWkal9/qskDy6q3AZ5B3 865nqunkwsd3W3qgpYzYrin4yimk4J7fZu70NBbj5sIAcs5LRYxTNWaMGf+t2T0xgZDz VJ+IBYQj0ND8UEeDEK1cESgZBFTC5pTVx10fb/MTD44ISTzz2ecJNqTm7K5OWq0C4Tgi gbdP87Ux0wQF3iQa6ZWf9e1JLL1k972PYxMZO7wTmJyduuc0dCBvqKX65t5sm07Ginhd Mn6Q== X-Forwarded-Encrypted: i=1; AL+hErEvVZyGykrzBB+guyWmIdZtx+OiaPVsvjlxnWGEkoaRRVsjHgK6pd0lMTpZM7i4/7PKXnBlxUEBU9LxIw==@vger.kernel.org X-Gm-Message-State: APuU4Z+PyuNzg3FH0DP41sOxZmwT8ZYadKr/WiitgRNuWz4CPnOwRgyJ HxHfY8gc4IxJBGbgLxAry83IrjxJ4WmmczyEWtrfxs2JzdKrn0Ml8rQF X-Gm-Gg: AZFdTZcsLmkYu/vrHbV2rEx5qFluEl/3rALb0RoGkl/G7helvMFsfIJCik9XhhGwlOO ColW2H0i3znSO+yIw0qg+6l8bbjSHCffkjThvZ5OPnOyfA9H/qVA+CFbf/2hxEDEv6jjzzRwQUm McjTuIuOJyN+uqs/i7QDKCW5+PrG2oGi9h/6N+Q+Y5Ot0uOwPK2C4Pba/qTrDTEMkpP3F6WzU2w SfPetPKiqKeKd3uD5+taze5Hw9cOAKTLUTfXWb4Qqbj0CtBLzZFdcbk9fzrBeupuDWI1NyCjO+M g6x2gruevcAW8P7kUXuJTJxaxIEEdGMNMEK4G61o3I8Bt7HnZIqzXzFahHdClTkma1bPA2Eyc0T aYAR/Gl6yIYsKnY28nD5Hj49ujp7UoDa2WfXRJQvgAEbELGeslO6pot6h1dd5Ex5mGVyJK7EC2v jFIL1/Iv9ZhbKw0IjxGQIpimoLStKb03ur+2qn8ARF5E9JAhYndV2ZTV2T5JIxY2LPjPgmMIz1d a23b/Bbhepn/rIQYTxYtn8Jei87tgt0oTdsL8+KxjBSKClVKwW/EujHb71h1D5Y20WvGN23gGDF 7Ora0IRJnz9bLuOTGvzJMPrk/Cmp66F+kfglu7BO9/Y+/9zghjcyEDaAbxYDb6ac6I0MIhlsqUm yc4T0I5/ogEwc5tNpVQkoVy6VOLfm9pPrDe9/32Y5Pe+jL0oKuTc/aZh/mQ== X-Received: by 2002:a05:6820:c5cb:20b0:716:d3ac:695b with SMTP id 006d021491bc7-71b3920f5a6mr17738739eaf.13.1796006391046; Sun, 29 Nov 2026 18:39:51 -0800 (PST) Received: from fedora-laptop.tail348456.ts.net ([172.245.82.59]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-86322db2d1asm21254554a34.4.2026.11.29.18.39.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 18:39:50 -0800 (PST) From: Ming Lei To: Jens Axboe , linux-block@vger.kernel.org Cc: Ming Lei , Caleb Sander Mateos , Shuah Khan , linux-kselftest@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 1/5] ublk: fail READ/WRITE if the result from the server is invalid Date: Sun, 29 Nov 2026 20:39:26 -0600 Message-ID: <20261130023937.606428-2-tom.leiming@gmail.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261130023937.606428-1-tom.leiming@gmail.com> References: <20261130023937.606428-1-tom.leiming@gmail.com> X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit __ublk_complete_rq() passes io->res from the server straight to blk_update_request(). If it isn't a multiple of the logical block size, the data moves by io->res bytes but the start sector by io->res >> 9, so the requeued rest is read or written at the wrong place. Fail a READ or WRITE with -EIO if io->res isn't a multiple of the logical block size or is larger than the request, as is already done for a READ that returns 0. Fail a WRITE that returns 0 too, so that it can't be requeued forever once a short WRITE is completed by io->res again. The byte count of a READ's data that is copied only in part from the server's buffer has the same problem. Fail the READ if that count isn't a multiple of the logical block size. Fixes: 71f28f3136af ("ublk_drv: add io_uring based userspace block driver") Cc: stable@vger.kernel.org Signed-off-by: Ming Lei --- drivers/block/ublk_drv.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c index 0699f22714fd..db1b049b7ac0 100644 --- a/drivers/block/ublk_drv.c +++ b/drivers/block/ublk_drv.c @@ -1577,8 +1577,16 @@ static inline void __ublk_complete_rq(struct request *req, struct ublk_io *io, blk_status_t res = BLK_STS_OK; bool requeue; - /* failed read IO if nothing is read */ - if (!io->res && req_op(req) == REQ_OP_READ) + /* + * The result of READ and WRITE is the number of bytes done. A short + * one has to be whole logical blocks, so that a requeued rest starts + * at the right sector. Fail anything else: more than the request, not + * aligned, or nothing done. + */ + if ((req_op(req) == REQ_OP_READ || req_op(req) == REQ_OP_WRITE) && + io->res >= 0 && unlikely(io->res != blk_rq_bytes(req)) && + (!io->res || (unsigned int)io->res > blk_rq_bytes(req) || + !IS_ALIGNED(io->res, queue_logical_block_size(req->q)))) io->res = -EIO; if (io->res < 0) { @@ -1600,7 +1608,9 @@ static inline void __ublk_complete_rq(struct request *req, struct ublk_io *io, * Re-read simply for this unlikely case. */ if (unlikely(unmapped_bytes < io->res)) { - if (unlikely(!unmapped_bytes)) { + if (unlikely(!unmapped_bytes || + !IS_ALIGNED(unmapped_bytes, + queue_logical_block_size(req->q)))) { res = BLK_STS_IOERR; goto exit; } -- 2.56.1