From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.42 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796196441; b=DWtWzXQp0drVbQlPSk9XRpT5L0gxizdNxd7JgujMdx6aFexS1EsRJ3FE65UgCFwEYShC BPTsT92bCUYCgiYMeKDUxZiTkQwJfkc95UJC+dpDnMxTBFCV9LbgPxqSga7w8x43UVaJ0 NmJq0XGzIrmCuJ14Xs03XaGZeWUOG58pFoAaHS/6qY0K58BflFzBADvMyUwVi+LAN0GV/ wB4qYxfzhBooVyGc2IK0sKTbU2yHGUFPz5kv3zhf0reCowdQGljR0cRjsbQRDN1Mdb3Tj Uhvclqlx1CImT+0FYK+4pIR2Vd/NFQ4ZIFjPt1fNN2UH3VX+S0jQBLdCunrd1dO5sgg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796196441; 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=JFJwC33DnUftZCD5uYkhHWvxday9kwH0VrJR9/khEM8=; b=NAkc2M/UwcGCOxSkCpTFZAMs6vSXdpYJwGB74vWGB36iMO1tvKt1mtArWUjfbBVAlkzd h1RS+aHfhnD04BvuEbCfCxHA4Xk6aHJtWeryYTK5OdzPA5nVPDd7ZYT2AypekApbSmSiV 89WzBtXiXqHXKhd7H4/O6P93FLDfn1GGAH98IER7O3LC4aOvXsdLMiQVkSJcJZJ40Pfu1 ROiJAPEl0jKE8ICOrian86qFHK21DyWjuhNiPn/hmmdH6cP+CQQt69/P0zVt+c8a9lHV/ tyjW1Vq3H9EIB6sPCVO19mU1LkCG+uSPcC0xkiL7WBVJ8NrB7aDz2Z1QEakQLWqwhxQ== 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=zOszOoJF; arc=none smtp.remote-ip=209.85.210.42 Received: from mail-ot1-f42.google.com (mail-ot1-f42.google.com [209.85.210.42]) (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 96FBA606A31A for ; Wed, 2 Dec 2026 07:27:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 96FBA606A31A 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=zOszOoJF Received: by mail-ot1-f42.google.com with SMTP id 46e09a7af769-8470d7d430fso6259220a34.3 for ; Tue, 01 Dec 2026 23:27:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796196439; x=1796801239; 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=JFJwC33DnUftZCD5uYkhHWvxday9kwH0VrJR9/khEM8=; b=zOszOoJFamRfuIPabDN1snkyeuP5TlgrRKbNyJ9BUfVJ3yfCeDynnRbC1kLiuVD/No p8GXNh322KKSt9+fAL9Ie4LVQzYZpliZMAMcMj8w9qY8qvQLj8RELszEOPEAVMx7jeaY K28NWL7Pl1vki9FRiB72Kt6gUBhmySP8M4cTULfw905Qjtbcni134B5UymfstQrTXe5k Wrg+kLkLkMOxxvj4TZEFmtd8A5Ls/RHZUYkTJWftSyJ2+pFmBQ0fZ+p+HhpHcQ3VDF9S tpcA46Scs0h8oBFL2NUZzt9xWd3ieXfI26rgiBs4zgjPNRytLGthWguA0rVZy3G0shVM zKkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796196439; x=1796801239; 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=JFJwC33DnUftZCD5uYkhHWvxday9kwH0VrJR9/khEM8=; b=chdzduYYBVMTOqnD80Ass8MqjF53aynHMRA2yzlsxguLig8QIwd3bEA0NLqUy+Wrbg 4SqND4Mw32ovsEHj5h7u5vB3PLmsXpghhXSn+me4MXLl3dB1/7rkjCla4fC+tytTPYRC N5e7ahMIFKa2DLFlvfYe1iPXQa6fVwwj3gw38bl+J+DoRKmx67IXga8jEf2zCnnTGrjG jCs5AW3NUESrt/7XGfQ7yLQ1nwXIAlTXWAFkVGyqyyNYLHU2O/3ijuU2D+VMkQYc6F0m /ll4RBnHmHCvypg5j2CLwK3QKSWu/QE5m198uGWhSjgnbewgm+N6jzOYP2jDXbE9Tn0V wgiQ== X-Forwarded-Encrypted: i=1; AL+hErGFvxewf/AdOZNwLRekHjUX1aI0aSUlnxNCfdzMdj/rfoA/QvfEmb/eeiXPbOnkq4bV8qFRBT0BnItzLA==@vger.kernel.org X-Gm-Message-State: APuU4Z/tTXg2HYwsQatiaeSboqBEvKjDL4tLjHFFF+Qf1b6/L3yeBNRS Zf0WqAYDB1m82XteYkVtBynP3lAAv9r4RAO5QLQubE14wUUX2SSAeiuX X-Gm-Gg: AZFdTZeA91X8xnYLValTI1sc70s2dIaDj7khteDgZnUG6GuWpoKcVHmb+29GMR1btvc deKdB4ZCEaBwuGk1KxD044EzIYmG0kPLFNeYJqngvNz0at5dAAAqbM6dbJ+an+OL34T19ivnTj6 ruXrRQokjIuZmGXuwym4JsAYH1ELANriiOD+jHN1rlON0AR4UmqcJQBhnbEkkqNsdE44HVgQ7dx uz3ekvPkOJDBa3IZnm1sI9bcNxS9ew2olYikVqe9MfUwHiNEMQOrAs/tYeu7WgE6AJWQQKWV8zK 3DMJl5V8dJqouviC9JCJQnb0bEmdUdUB5tm3cZAJjD6DuMNJVea6tG2PvGRTTvTbjEew0Y/0+Bg 8gkX4Po/sZ+2hR8qVCDbDoA4XR8XoVj/8a6sIhF2l+DyeksVI7ArWIwMy0Kg+H5hGE/5nCfkykQ 5mC5Sz79ggvaCkIXtgS8k4Amqrl3uzDH8JLL1JulgMta/sk1jJKheYfKiS2KJW63IHGe9jnjYSc XR9zrDc+N529OLmzUDbGRqD3qxvIiKD/oG/9eVFG6FmoKuhwN8HaV37Shd/hiBxQEItcsyfwBmR fJI+K+LOH2AB+gmUxo+kI1s0egU/BwBfaIa5qkpRYceeiLeUXIOHXEEaZRqRLWDwZWeNZfPLu4b coGJrBtR4J2Cwn5FwksjsP614SiKIs1k1TIY8pRSxRdba0lOiu3NZcDLX3w== X-Received: by 2002:a05:6830:25d1:b0:829:8a9b:de79 with SMTP id 46e09a7af769-863151bb287mr39819556a34.4.1796196439508; Tue, 01 Dec 2026 23:27:19 -0800 (PST) Received: from fedora-laptop.tail348456.ts.net ([172.245.82.59]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-863168bdaf7sm29355597a34.5.2026.12.01.23.27.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 23:27:19 -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, Utkarsh Singh Subject: [PATCH v3 2/5] ublk: fail READ/WRITE if the result from the server is invalid Date: Wed, 2 Dec 2026 01:27:00 -0600 Message-ID: <20261202072705.1288588-3-tom.leiming@gmail.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261202072705.1288588-1-tom.leiming@gmail.com> References: <20261202072705.1288588-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 Reviewed-by: Caleb Sander Mateos Tested-by: Utkarsh Singh --- 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..1a0cbaf5690a 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 (unlikely(io->res != blk_rq_bytes(req)) && io->res >= 0 && + (req_op(req) == REQ_OP_READ || req_op(req) == REQ_OP_WRITE) && + (!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