From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.50 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796006393; b=mhftFf96ze2BVgWP9zTubPSu4z5A/ixOGpo/N/ShoPQEB3vQrm56DFJLZWkJpb41IUyG ebhfhEShhFGs50A3faEpTaX32jDexM4G4+BeQNE+l6ezZfADXha5MbEPhgdONPnFSdU1g nIQHB+RwTAWu2x4EJtdlK/ARYDqF7ETiwUU8Wbwg8ETFP9QYLp6ZWJXrIZA3m0vjporLV nzrPE6kDCACr5DryGlCOL34pj/d1tkzuR7tHCLn81fz/ZFThWoZjx5pNAORXpf/1Ex/5M cHfmFxicwTNXaVit709Y+C3aSP19WWOC1mUaLxyPhz5Azyf4KFZn9OJItIp9o/ea7Xg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796006393; 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=w3NqPYHEsu01hyk8zyJdWRxoWGo7c01ZTJwgZgivt/KkdCDclLEGLJ4fNe+KbSyZaDeW B4yvaeRG1BrXEpW8AsmIAkvE3JFS12TeUJLHpj1Hr80JYmdiAyOqdFddWzoa1BDhgtRUX gXvaUKqUi87QPIg62+3ZIe6t010tA1abQxlThzYdM1qsAgtfzn5lFgaQ1pJiFLDUdXEv7 BiCDPK/C3Z/rH1ZpfD/bGVS2aeaQRnghQa2qjDdWjrbxFJc8ii10s0uM8m39qclmUV26j 6uiZZeB0fj5S5AmkwK9ghzEodO0BDUJxZivflCvj2dXbemT4Jox+BSWGZwUoO5eVa6A== 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.50 Received: from mail-oo1-f50.google.com (mail-oo1-f50.google.com [209.85.161.50]) (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 61A11606A31D for ; Mon, 30 Nov 2026 02:39:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 61A11606A31D 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-f50.google.com with SMTP id 006d021491bc7-703be215729so4329316eaf.1 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=f6cIlhMQpiVGi5Qn1eqXtYJ71wWptSR3qNbWuJLarRmFtxu0f+fbCU+QTcZTSCSViq cfHlSQ9SY4I+TNfp/Qm1y+QnZhSQHcCd2uGMe9Uatjc93N8TqDZyMSBPIKUGqVvW1m9s JCXBvp3xp6aTCMPEX9bcn1FMbm61fPIzUl+ZcBOEieiL/oi+ox+d7CDYrR11BA8fxlB5 kLSDiS/vSINIVSm3kYgw4VZVWgXHx6d/YfNMCJRvx+mn90putbBG76pAl3ZCH8RvMcMa yKDtCrpjyvPbHfQ3h5k/qPlpwu8km+wjVc9voGMoMFbZtxEOJCAvtSB3LS+/JFyQu9q/ IgVw== X-Forwarded-Encrypted: i=1; AL+hErHhdG10If4pLVhFUh6sSobA/fWo/IQYkPbocNyR/NSIqun8WkTs5RwPlS3a6zer4uofobvK+IU=@vger.kernel.org X-Gm-Message-State: APuU4Z/jpLYAk3MpuHanZDmv+dXb0hL4Z1NE2pXLoGWWjSad8cDcVD1p yCip8ZLgFNnVf+RSPWuIj0nHBc24D4TfZ370Qgsq6zMvA5mq/upeETNf X-Gm-Gg: AZFdTZcjGPv24cBJ/LT+WXR9D0FM/awaAm3YukRAXsqyqBYLi0yvEvZQgn9aIEM9blS v1xYKme7EIaQSHD6o0iqHW/f9+8PIzDUHPsLNWWeYrL9DIpA9dUEgH/f59EXTnxm7IhwYHMC7Oy 0lfmtcPWvAmMRI+11Jkq7aCXx8xHl0eFtZh6mrUacGc1rAg1AzaRRWbp3G6ZA83g9s/6cqawFBz NubA1q7xPdRMJ5QvjtNHT9E3GumZUHxFmuHmYLI+SnC26ASzRzsicxidNGJdQRCGlYJFd2sdxm7 8X4qfFZFRxSpGrbLd+eo4Z/F08IbSaIN6uXeV9G8i1lZWABMdUEBqwJ+p0fc9L8dQqlZ50SVTKu 23qc81Jl0noqIio+7N//XZlsEWBsHCXzg1ucVHAp9RdUyivc8dGy+DBlUv6zwn0zmUx3fgVHwXH 6S3ygoZrp7vyN3a2ZLibq2Jf7Kpe6HZZWkOTR1n5WJbDvGbIUrqtPtWHWc3KzAi7HCjFYGJN4N9 knycB+7gmdel8iV32o5t0nLJettDBTcoA0vzNjoQ6HI1WWv3ZWejmh7ZWA7Jl9a+/4dv2y3bRSm VuPTa8ccqlTQgjJCynPGC2q/8oICJ42vu6OhdytmKl6OknsNTcqYMBzLOFURDZJH0MAJPvPsBMC kJ0MoDbFzzJ80hvEOy9rYovAP1RH3frAeOp1/wz3A4cbFEGIspsOExBE5fw== 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: stable@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