From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.54 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796118733; b=1HX1XyYLOuQ3XYwRYTJSKVl282uSTqiripdpPQ1Ed7npZpvb3+ifrk+yZWj23fzSDR6p RRZD84mE/EnKfAUMCM9Bgm/5GX2eb32RB6b0eaKeJYg1K8CuMZmZfAiqL/c+eOK31k8Z8 vnPBqnsQQGg3PJeQxSL2hH7mmxeTbVG9NYFvW/LG0PtJ6gk3v5uVJ2F7tfvrWUHzIkPlv OO2u+VgDWGNXhaLa5XPK6eTQdRbldaPG0xORFAPKM9IJyagHADI8Dhbg9VR0rH1x+2AWi HXJzfPcJmB7gSvLmMg4M3P62E17Rjf0A9xxi6/iTqvBAulABP31rM7Jlo+hBCEJUoiA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796118733; 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=mCYanBVyJAswkJyuCSqy1JtMOYsKaqIa9CfUcTx3cb4=; b=2dB/Rhl5RCEYbCYZyMSD8vO4XCi3TCAumf4boZK3H4fpylFCITKWrifk4oStnj3ZbZxe EfWOFVxLAkDA2xqMuALSTOHW3ZwiaXtugEKrw/7+Dq32VQlZC2mFOkZeiVyF9qM5VhPJs O38G6TmNR/C75zoSjS7CmH0+TI56w0jcL+A+FxS0cofaQBg6rKuteokDBNFSsQtRdsnN4 2yABEd8X/GoMvj+5hbPgbb4+4eot6kFF0DIds/fzixRuMO2qRB1qmMmID1ESYeOWRzl3B H8WepbW1ru7qMHV+v0wRnzW1PRdK1yLP1B1RSYLH0Afb9K2ZqQTWIefgF9Xd+taPXBQ== 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=r6Nhg38j; arc=none smtp.remote-ip=209.85.161.54 Received: from mail-oo1-f54.google.com (mail-oo1-f54.google.com [209.85.161.54]) (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 B66A1606A33A for ; Tue, 1 Dec 2026 09:52:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B66A1606A33A 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=r6Nhg38j Received: by mail-oo1-f54.google.com with SMTP id 006d021491bc7-71b45386310so5565527eaf.3 for ; Tue, 01 Dec 2026 01:52:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796118728; x=1796723528; 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=mCYanBVyJAswkJyuCSqy1JtMOYsKaqIa9CfUcTx3cb4=; b=r6Nhg38jAKbG3b86HrP1/APGcEBAEcRnQTHaE+wFqGqShP3ZIhIHzDcJy04CaItm34 fEQgRqGrSY6501QjJ1z/HUWE00fud3sECx6Rtt4IVgheiG/HLBje/os/bH9qh8xSG38g RWKVy+TStBPF28JuTu2rYwN5Y3J3t9tS+b044fmIuN3yQtwbj2wf29myBYwa2ry3u50g LW4SJ5VcG7FzTARwGDMumXoyrWttgX9G1VBZESHZeebnFm+dQbmMcHDugyc01bBHPhXO keSYTA1LWmaLxRodhxKa9hC+NviavE5pDQzIuwIPX5ZI60OjXOA3YHH5Cg+dm9qWv+kC RMHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796118728; x=1796723528; 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=mCYanBVyJAswkJyuCSqy1JtMOYsKaqIa9CfUcTx3cb4=; b=q9dgSYRQZyfUoHK+Z858LTRowejUOCnj1S9C+iFF620B+5k+3+XzqJaNUcDamNukP5 x9r2w0iVRdzQ/LftDozcDL5zCBp0bvNEQ+PL7ig362qB1+J2V0SqTvncfuHb5kow0FDS AG3589nr/a5X6t2PNvQ1EfoiZ6f5TsRL4CmkN/VRVTdE3LmXtz8PH83fGtEyxYA55PoO 69nr+hH/ac7SMTbUrvMS8d3Ey1RNT7gzS9KuBIYeYi4Qv2p49FXsZpteEKmmAuoNNi5y q5RT00RuqubjSZsuQuMQIKR1Tst9T49xCI9wmx8Kcs4rTLntqW5wwbsCYGGjF24ITFgq 6KWQ== X-Forwarded-Encrypted: i=1; AL+hErG0Oi1aBa9qZ16hHn4Vx53gWikYSSV4U/42zQT17GLXvIRQNT6UlWausO+JV9MF4BU8I41ZOpzoC/2Tag==@vger.kernel.org X-Gm-Message-State: APuU4Z/QvJ1GL77FZHdKvMXEYxj+I2YDqN3lUL+A8k/f3N8sKv3iz87L N0LJPfSJdkRhPmn+lbX7uAMX8vBMIC80OzE3KhgItwgpNqnhzjeflhRL X-Gm-Gg: AZFdTZcTZ9OcbSACQjJN+m+qwk+UJ12apn0Sk5lEgLJseRpoVhaANK/uEUBS6bcg6D7 Ps8aP+POxEbwnUZzQhuIK2wXT8wMx1VPalQDAbRS33Z1MfwFuugrlsrbKmMlZT7xKPr3gXNQPjs n/ku/WFIR09ge9p/K+dSyjYTAohS/e159J6Kw8AqtuV4dPyuYQx1dNIVc6dstqAuFT9/eOI9DkX HiJ5Ad+kIe2dfjtm3m9Qd3Mo5HrkvseJnoi9YNkaG9SQC1tMJIF2M4rebma1uLYQCy/C5lqDgBy 8cDLBrBvezgeHB2W3vhaxfPLL6Xu6CEB9yMs8CD1c4QggieDcH0jP9tMPdPlQEgu6T1e2tgrkDC W1aozoS2CcHoNsG2YnGNQKcNQ6D4jBvxfXqYnHUlwY0E/ROk4pMW+DgQvA7vefehT8aoin9ZQsY tFeLx8aiRk3ZDuFWH2VsyQHL+rqn7zo9RlQnWxoRTfMn8IpN1rGZgtj6qRlE3AcLalD1tkL4wTT ywtl27ALfq0cElXRy3z7nUxhpnKFb+/Hm8kyNdlFesa4HbErL2MMCT67h7pm0nxOE8SY1M9XPwm GNxOFpzOQjR7Cq+O11erGvK8xHrstQct+ZuWAz+noE0Ap2P3z9gehT+MFDzzrsmHUHr2JaHJDXi SWE7TDWssyUGa0OCqyCIJVAEJRf1+luir4B4mHHjsH9ksSg2GSffM96Epzok= X-Received: by 2002:a05:6820:8597:10b0:71b:87e7:4f7b with SMTP id 006d021491bc7-71b87e75971mr10883340eaf.89.1796118727686; Tue, 01 Dec 2026 01:52:07 -0800 (PST) Received: from fedora-laptop.tail348456.ts.net ([172.245.82.59]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-71b380b6f82sm22698287eaf.10.2026.12.01.01.52.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 01:52:07 -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 v2 2/5] ublk: fail READ/WRITE if the result from the server is invalid Date: Tue, 1 Dec 2026 03:51:48 -0600 Message-ID: <20261201095153.1012606-3-tom.leiming@gmail.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261201095153.1012606-1-tom.leiming@gmail.com> References: <20261201095153.1012606-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..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