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=1796118729; b=4WPAm47sMJmX5/XQGngrKOXTOI1Nh426zkq9CVV/hjd+g0ERYUBrVklCJngfD+d8kaT/ b35xq4fVoz0+3wgpzAUQbGgRfbdN7RCpg7zg7G5YSboDXnLo5slY7AUC6bUWRM8UCWlAL rDvTPxkpjON/hJlL0qHJVCjZ0zJACo50nyy3kvIdOW1YFvriGauWyMKoxi1YDCvRZMANk afZjm0SQHIIdPGV1AO6a6Hrkye5YYV3DOLPGmaZoIOjZLxXUlnOczmhjtqHL5C6IbzuTv S/5QPNnmGR0XWZuoL6jSOc8PaEdZLzlI2/BWXWfk7H7tqTTvNxSSVYKc8wttqkBsiqA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796118729; 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=MHHmRRFmJ/as2YfIU8Xp+qNKaVQxq9vawiZVZQQZMLCCTNjih7cGROUIGbs+7TjPwDnt 4d0Tk0MeaL6f6+10RDMhTJSnJn1jDAEfwEmxyccHjOLJwHddwe1Nc2/uVTGb176OXGFns RFomb13MwKO7zmNrpzK3zo92Xq0lVBNqsY9QplSTp7S6ToD+Si5tCR3EyZ9ZO5jPLvs1a 2fy7SE9U/m3bdYZCQjCug9LiE2U5E6wlRjKskElNvVyaIZr4fOCL0NDVdhcdNDUwGNbjj cjA2o/vaKiz3Fo5GZYfKx0GH6gNAETS9YMS4AlLbYoBZ3D9FyShBG6KnolS7Lzdu7kQ== 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.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 B7F69606A33F for ; Tue, 1 Dec 2026 09:52:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B7F69606A33F 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-f46.google.com with SMTP id 006d021491bc7-717080a2d50so10636473eaf.0 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=BecnIZI4wBckCE0uRxM6FxuUWOrZWstYBvRLH7W5Frm+7M8tx6gffKi+LSN2VpKw80 KoF9HiMsVr9MtZWB4eEPJcZGEUp+V7G24lqJ89i5FVrI6pUNMZpVaQ1xFxO1LLYYljCx wIsKApTuphklOWb+DbF1MJV53FWEkx3xcupOt11OEfJg7PX0dF/okmlzMqUXEbuYel56 m0judIFY00B/A5wqPeJcnl8lsjrtEfQz/QBMzCavJuphJKAxPmzdhuXCMi5GqJiTvsY8 p7MwWAIZALWQdJlDKv3oGlAI5jJ0KZ8klN1N82kBt/qHfrWje7BC0DEkYmrh4LwoiXrM I6OQ== X-Forwarded-Encrypted: i=1; AL+hErFfi0ttUepjmeXElX3fyFdWZpkgEOellBX7cSJrejux9WSPYkDSBeC1jAo9u7b2GRugflrtQnw=@vger.kernel.org X-Gm-Message-State: APuU4Z9km5KwJOqSV1WGRuV4gbUGyc0UwAq2XhjsmGyEhSAoWtKb1zYY 88G+DXaHpPF+rakkfoCD3wvSu2ylGDnHeKUZ43o06N0rpCmHEuhYeRxs X-Gm-Gg: AZFdTZcvlbgf56El+Iu6LB4UJihPaHpaFRl3ZLVBME5iE9GurwDUourHjCNK6pEK/IW 8v0bam8thEuu6kRp/XTiBsD9y0r4ae7EYYiKxWEAW/ujkLdWu86D+EEOXlqGkzyYD2rruAx/Y7l lbdPg7l0X7UVtcPs5UtpNqmrnDuvcEKsEsMFoc4J4gUOfaUmBt3YN+2R4DRG02r4HNRzkxRACdp OMNWEfYImAB0iXsfudlDAuXNQVhxIUiwvrEcJsijnl87Uwwp1UivIwa7L9NITsokKNwO63neNtP u6FqQnsGvrPJ89ZSteUuwlIon7KRx8jjhzBZYxCu6xPdu5XzYOLtS6KZZAo8h/vMzvYtKjmO8yX HjOaOTys0KMhcY6uSHZnmL0iNXdYk5WxsYWXD+sqQ25r8m82wmjHInPn+nf+Cf9eH65VM6yxcn1 YN2m2ZIdUFTPlge5VKxp76IBHmmBEpDuvYP27JEsnDUl8IbB4OSPD45ymeSECGkRXDS582VUmPc GsySuLpNcD2S1c4EL/CDo9maXWJRwnlJz+rnmAaVFhCyse3qC764NxyZ4WY+wnkG8FLa9Y+l32k txByOcNn3JiAS89lBk4IZTQnJF1tbWzDOGQsmWaGprFas7wKas96/ACAZ4Lodgar/gRXY8W3kNw ui7Vz4QkIRGG8okrlNQkkfEif/ZQu6e9lUv/Dss1B4shlnmKdWr9/FKtq6pw= 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: 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..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