From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 73F3E346797; Tue, 17 Mar 2026 17:00:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773766810; cv=none; b=D9rqA9giV/XqoLkrHH09WN8h9npubtR0TLqknGmCjbndMWKBYXhGh3lD0a/41sR3i7ss4NWa+Qp0s7mG8m0Agya+HlBeNAecU8Q+4fRRZyv7c96Tf6jVkkp9plMPPFC0o4PPv4+b5xRDvieTKEoU6bEpbH1QwuL/qTyHzWs4U88= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773766810; c=relaxed/simple; bh=t0iqsZRHz/04VDuPtEkM2aKOZnJQaDuF8gHb7XbF41M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nuvKHJilhg9KmHH2qg08tpsdnDeBlYy8b61bAthKws65WbUoE/1RGRtcnhCzdxFxAF2OIAVgDUdIXwLalSFMlPPaneSO2ByZUBjoEJzwAym5a9bTGYRdICt6XPvHvVG9lOFrFNKb74hVHyNFYCiLJZumnewy4QcWyzYIYGm6w8Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Q0lMtK0g; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Q0lMtK0g" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AAD61C19424; Tue, 17 Mar 2026 17:00:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1773766810; bh=t0iqsZRHz/04VDuPtEkM2aKOZnJQaDuF8gHb7XbF41M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q0lMtK0gd+UdFXlMtw7KSXbCzlutAsTfqxjpLAFmSaNsLVPnX0Mpmi1PZPhaFa9EB vH1/XMaEcMEkl2H5RvVoq7G3InLw33GsjhIvTuK584HHnZwmz7SYjMuSiw+pJ8i5Pq /jqsZcMAJvYbxTKcfB6LIA55QpMLMPJxMkNcRqUw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Mehul Rao , Ming Lei , Jens Axboe Subject: [PATCH 6.19 326/378] ublk: fix NULL pointer dereference in ublk_ctrl_set_size() Date: Tue, 17 Mar 2026 17:34:43 +0100 Message-ID: <20260317163018.983282084@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260317163006.959177102@linuxfoundation.org> References: <20260317163006.959177102@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Mehul Rao commit 25966fc097691e5c925ad080f64a2f19c5fd940a upstream. ublk_ctrl_set_size() unconditionally dereferences ub->ub_disk via set_capacity_and_notify() without checking if it is NULL. ub->ub_disk is NULL before UBLK_CMD_START_DEV completes (it is only assigned in ublk_ctrl_start_dev()) and after UBLK_CMD_STOP_DEV runs (ublk_detach_disk() sets it to NULL). Since the UBLK_CMD_UPDATE_SIZE handler performs no state validation, a user can trigger a NULL pointer dereference by sending UPDATE_SIZE to a device that has been added but not yet started, or one that has been stopped. Fix this by checking ub->ub_disk under ub->mutex before dereferencing it, and returning -ENODEV if the disk is not available. Fixes: 98b995660bff ("ublk: Add UBLK_U_CMD_UPDATE_SIZE") Cc: stable@vger.kernel.org Signed-off-by: Mehul Rao Reviewed-by: Ming Lei Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- drivers/block/ublk_drv.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) --- a/drivers/block/ublk_drv.c +++ b/drivers/block/ublk_drv.c @@ -3534,15 +3534,22 @@ static int ublk_ctrl_get_features(const return 0; } -static void ublk_ctrl_set_size(struct ublk_device *ub, const struct ublksrv_ctrl_cmd *header) +static int ublk_ctrl_set_size(struct ublk_device *ub, const struct ublksrv_ctrl_cmd *header) { struct ublk_param_basic *p = &ub->params.basic; u64 new_size = header->data[0]; + int ret = 0; mutex_lock(&ub->mutex); + if (!ub->ub_disk) { + ret = -ENODEV; + goto out; + } p->dev_sectors = new_size; set_capacity_and_notify(ub->ub_disk, p->dev_sectors); +out: mutex_unlock(&ub->mutex); + return ret; } struct count_busy { @@ -3853,8 +3860,7 @@ static int ublk_ctrl_uring_cmd(struct io ret = ublk_ctrl_end_recovery(ub, &header); break; case UBLK_CMD_UPDATE_SIZE: - ublk_ctrl_set_size(ub, &header); - ret = 0; + ret = ublk_ctrl_set_size(ub, &header); break; case UBLK_CMD_QUIESCE_DEV: ret = ublk_ctrl_quiesce_dev(ub, &header);