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=My3WOR3OzL+7g1YmuwjWvBhJag67lCVsoboMWqDeTCE5HMwYV6jHSYDT25snfhYFknKc bOOFBwPajLqq5QMkSiKDhhwVsgHTX16G+cg+h4wvbrIp6Z1g65F3dQtm1JfEzt2xIZ66j LwPOZuOb/n8RnyjqEp11x0cvOtrgio3FoHnjALalX8fgG1jxDG4kTm+KYy6PCHYZkORlO IoqXr1h4ZU9SGaYJ+apIJrHUlz25bru6EWU4ABOwsxLzQaW3ayy0qCf2B5F0ewJID4/3C abNwKggzuJ7lhKlxsXcOTVypKPVu+eSQEL6r99KDavi8140Fsc6I7c0/pOFOQcNbw/A== 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=YzSXuFwROs/v8arTr6FC0cJ5v/tc/CBGKt7+qm+nV+g3d5TWkbF4LlNW71QdHk7U+5gp pyLtibOpfz2e6W0r+1ozjjzYTX86qsRNnW2ZIIfp6Pce8gXKDmDhS0ln7VOWUm2KoLGp4 LlzGIOu02J7/DZcSsk5A1kbbuzx6/jGYqwo1I7I5Esggo4HkSvsFUOQ+jcH62KdsIo4aB 2X6lMfd2XZHa7d+R3wQMt0rLPIbarZK15KhKWnPi+HPfoTWqzIaeKUFO/iU0mNV3VbiJ5 9abfC+o5sgn/yM3VoUC409L4AKtvWNIPd3fvy8op3XjSD5ZVoiRFGXiR1wUuZvYSJ5g== 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 9707F606A323 for ; Wed, 2 Dec 2026 07:27:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9707F606A323 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-862a19300b7so4175712a34.2 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=Ag3EXSkdJUafLtmRI3B4mLAD40hCTmfppgz4niUk1Z0PFvwZ55GT6g+zsJOXfP/sIh 7BTqF7YBqGF1YmeU6GxXijMlwF8Z38p4EMbYyg4WrggJMRcYlDC8Es4jcn2G0L90mm0h D8W+H9ogcNqaafqVBJWOdlbFm8Eg5/9lGzCtdcJDQZJl4wS+LfF0TEsHlqm26MumDwPM f6OPHzCj2+9kDZUbxkijeNnvh5KCmrDtVaRPLoSU6uLORjOgjlW+J6DNOfi9irP6PZ5g B6S/dJ9wVZrOxxlaXZ0UM0beNsL8fCQ3QOYN+Wqk8NqLSMg4C7uDmrUjlw5+O614LFdT EAWw== X-Forwarded-Encrypted: i=1; AL+hErHi06ys+0nFhLUH5QMW2jUVu3UT4oAEQ2l6ZRjvzYu3cNUjDSXDqmMQ8elOW23q7Ox7dstHkGI=@vger.kernel.org X-Gm-Message-State: APuU4Z93o2HaPn/lKPT49GJRod19WxDmU6ehr8jH41Qp95hwPANYDk0P ZcF9lT9YFC+nw5XgRIe0zFpsXUMlgiKn3CfCHKbr38Ei0fESzfUuSPyM X-Gm-Gg: AZFdTZfFBSEJSqcODZDozkTjwfmjXGKdPIovtac5u4m0QDwhQEURP6/1QT2OndGLA0O AcKMrlAS16DGhWWbA3NCs5z+pIZZBdxDse7W5ZiSUkf8uY6q/123haToEss6wKaRGl2wHytYg2e nlxXwnEF/rz79594A7g4if1habW6dUjL7MIpqJ/fXVwU9yT6xYrKw5AjP6QPwd2TIjJppNMVL+N yDClJPB699ucz/Ls7MJOYTCzpkIK1hTUDDtVp/dcFalv37JfLoji+3YIo36h6xMFuLJ2Nt9jfMw 5W0RTx6NX79eT3rWbr4YlupQNMqBz9qvgX6W0whTjjd81xAIdZWfnxuA2DktCc2tcHyAVRcw7uu sgUx8XbPxZMQ/6Af/MrvrPBcnf+uOiL0EkGgC61gkyZZsFkQ7zn3dTrL+9EVKLCRITBdWRwa7NX FJ9VAGoErHhejNQJPkRdBweZvfLKNlTN6rc9Z8vihruDnFCAWcioN0hpfj3LXGRcIVo0OXft3mT A2KROe9mQnF5WXEe+j2VNWgVd5zuNCuEU4rEY8IKG8SC1L8259BPGGB5Cx/hqKgfwSsNRqdWf4n a1/fjlZzOSsaXL9CS1IGWu1ds/AWxaKYwUINUDbAvkAkNoPlJza8c+dUY5Tn0qpcIjMydf2O6IQ N1aL0gg0mRdY7vtUnMUnNbpPN6L2+9/z5ufOcHJxx43Z1uQtyP7EGqxZVpQ== 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: 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 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