From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.48 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796118730; b=47zl6Hk1xy3lyN/ZobXvz8aQjpnx2aQ/f8XXSvo03aPg0d8HzxUMNjRV6zt9Uz6xoA4F OljqRL431RSzTda6XR/F1SvUavBqv9aOWUre4fBuUFOfICq+70oHqycSfR/BSoUXJ3maP F8ETEEao/c6+fXTaJo/SEdPMcEnVtMf8+NiAShzuKWD5TJUo5sKtzXN4askIMLI9FAcX3 0DrTBeJawHWjTnco7pS+LR3o1AZ5QdefZLzmxCyxhRzXdF3QJObxuyLqbW0AOEMyg89kH Ywfnq0kwUnoSlhp9FuoGIC9DzAJE7eH8kfsMv+1QVfHRgQPCZTsCeZ2dMN8ZgetsOYw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796118730; 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=gi1g9jeCxGc1vVaDaYkAMUC1Vk+ERmhtFYRWE2ZgCfyLQ0XLLGlLlcY8kHVg2UKZzX+2 f7rLm7BvenoJob8qob/6UFJytoFZpgFtYR/Tc/fWxPRJIJe5dON3te1AFQlle7O8WZE5G FDJem3pSsOgfIyJZqOEv61onVDzxdcXbii8+rHUABKDi8BUIJPozzY5JfKKBiNcWMI0Tj d9ZqjxAY3w5cFIPyQ4oEygazCH0g1XjkoNHuH96iYBiqSIv1qv6bP1ryX1jW7S7txvjHA /0N5dW6wMZ4gjv/e+4U10UNaO6QEvtlP/UZXvpwlrn+fl/mtAh+bOCxmvPRLkJhKTOQ== 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.48 Received: from mail-oo1-f48.google.com (mail-oo1-f48.google.com [209.85.161.48]) (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 AB6EB606A339 for ; Tue, 1 Dec 2026 09:52:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AB6EB606A339 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-f48.google.com with SMTP id 006d021491bc7-71aea92f666so7452555eaf.2 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=efzudP9FS8lzBEg/u5c5Sg4txfuuRNomnaMs0sIFlsjhs7NyrYre29a3OgXm5JEbOt GuKDeBfixZF+rKnXYgpInyIs5K1IoaLtmgPiSd8nKO3jZpJ58TAWTRaGpURQZPY3c7xK z0lY16ZJxCMi1yny5JbdZnvCYI2zhnLs9SQv3sfZMM5ci6013O7DKtOdgiMGT+0F8q9f Wr+fTpy/y+MyG90UiNSw8bn+zix/gmYRnwn3KI7LjRQOG2OQhmyHQIHY+GY1dtCJwnz3 9HVh7UtXgAh3JfI5QKfn1876H7lhkPqlYGrOtJ5oCEr7aZnwnBONUMphOJfbqHOg8ZWb FiYA== X-Forwarded-Encrypted: i=1; AL+hErHkJPugZrI1xR+eKiNQjpHSkf15PQtqyYA95XGSIQAxWuuXXp3KAjPpsyULh/pm8zjuIIWvxrHpL+Vgmax0u64=@vger.kernel.org X-Gm-Message-State: APuU4Z+iZcaESSRdWcfWN7yzR8MlzDv1wPZF0YBFPwwhgTFWVoJr7Sr6 v997V3MGDEIsv3xTR4Bkf4in2wQy1ciaDnO8iMMCQJ7JeKtQU9Y6V7+V X-Gm-Gg: AZFdTZdgJ7wj7dP5NwUjuKUIs1CiLG/qQuUHsIjH1ohaN1+tryIjad4UC55E83gf5P5 rHt+pS4PcNLGbB2KDmPtNs0uQFqeXvkcwSZYWUp8YZCbwXa2XbfjuGWKjRQh+uKrNfXmjl4lidt SUwFCeAzfbbhYKCvyjkFfOgTLRuGS30eyjR0XcMQRH6qlFvMEiD0MHzHJDP+chT6nIS7g04Ss3s CMp7snToBuDb0ULKuNBPz4e3y3f2+8wwNhDYwgUE7k+1v4ZxhKJMdoSdpxoSEOZ+6WqA8tyd/bw 2qUjT5GtpywCE15wKYBE22xyss5prjVWnRj+7auk0dysOY29iZX7IhvgCezTrelC76WffYFNJpn sbJ3HI9qqMpQzaT7EQKd3rcbzcs4MOkOFSReBGNR571z1QotxssVdpIqDWBNEtabGxGaDGQOFq5 CMbhK/x90Nf+T6gfKbZtr4t5YtNM/giM1isWB+mPfSmTN9/j6K0TKDSDwoBFLoubKmUFao9mFh/ 8Tu3Yp+HLtS5yVei4lWU6oxI6mZ36GZI1nPmw/z8R7V8QM5OHaIUUDLzSQ6133coIyu5z2d7tlU bHBsSevaH13wErqiRTkJ3ZBo8Tnbrabhc5EV1z99K8omC5l1IBhSk69GQcIjT4M2ZxDUOJHon8e YKximEN+GonSPAoUt0mL7GiLh3ztD3YFwix3vqoddpS+3pJ3RfbADIXxkpKI= 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-kselftest@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