Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796014326; b=1Ggezkayq1Qggrr4o70Mx4erP+QzIo2MVVEgn12JQrswPdMNIn9LbFjVYiz4p1+dTmIi t3OjUAfrvYzRxfw80dJhgGsQ+Mztq8ezRjAJUlxh1JETGdi3myY+g2MP4ydpFFzK5BKWo +TOcBL3wN8W26kPs9Gitgcmcr9YuDWh1bkUYRSYy86a9rnmQ9YczsNKgLtDkxQA+h5DOm w3Nb+KKKyKxeEWCGpzQs97IzjnW2jqX/i2Cdf5nlVc1WqEmqykpQl6Yo3GjRbDq6SIZvr 0OcNK8j700pfztuhhYAA/TRD/ow5U7+oRjjd6KCAM0ikthFVtHECv9ZdqdX1x9ZFokQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796014326; h=Received:DKIM-Signature:Message-ID:Date:MIME-Version:User-Agent: Subject:To:Cc:References:From:Content-Language:Organization: In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=oakPGSB1A5cApp5uKw4Iox3Wk+ctuiqw5lv1afF3b+I=; b=fvKqaoItBQvJdGKPkVGGnEuOjuvWPBU+CksicgsFx+1La8FA4F4RGrtQ1ehw+/vZfwen vDlCtO38yfiHR2v6QyGq8fUDlGqucCiUYWDiMkU4s9FSRV1DntBvx1F6zqi94ju/1lthF 4Xso1pDsDon8BkhR8ZhNVc/c8cMSO5gSvb1ifbXetuG6slb5fjKPOwZfQDlRhOJ1BErRt scZ4zuxGj+hoMS1bMw+E6BK2zNA1vGiengEL/1Vaz8mxw+z/d8/enmRUhi3gppv/uKwy5 MEUaFi0hOTkEDGUcXhObVZLbOQTNPSrdzcOTyMdKXvkBDWpxiaHBWb3ADvndgEpPvvg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=cgA8SKnm; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6895D606A331; Mon, 30 Nov 2026 04:52:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=cgA8SKnm Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7A26F1F00899; Mon, 30 Nov 2026 04:52:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796014326; bh=oakPGSB1A5cApp5uKw4Iox3Wk+ctuiqw5lv1afF3b+I=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=cgA8SKnmBAUlh2rAkGLwrjQgWpvwJcxiGnDE3s6xel8nORkgVVUTZeVMaRugpgsrB DF+ykZZfoXsZSnX3z8q2OcrKdcHJj9hdLCwG0bv1afx/jfRpjz4HCueEY7xmzAmIul qheBx3jdjkXzeLZQspzp0bF9s5yMQNGCIYzv7CQg3hyLjhlEZU51jLgAXKhSKby40Q 5s1q6UkIWW74Rhpz5Z/lMxGzWYF0+weuHE+QB9yVpHsZ0jOUUPSLlrqEl9mdeJCXLb TdKW5z416IWZJPPQNkjs91LnBVkX1yxNtA3By49hWYu7ik80hG+e6ru4zOciED5mhD bLAgRJsWLvbTQ== Message-ID: Date: Mon, 30 Nov 2026 13:52:04 +0900 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 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 2/4] null_blk: reject device size overflow To: Yingjie Wang , "axboe@kernel.dk" Cc: "linux-block@vger.kernel.org" , "stable@vger.kernel.org" References: <20261127125738.1654012-1-x-professor@outlook.com> <20261127125738.1654012-3-x-professor@outlook.com> From: Damien Le Moal Content-Language: en-US Organization: Western Digital Research In-Reply-To: <20261127125738.1654012-3-x-professor@outlook.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 11/27/26 21:58, Yingjie Wang wrote: > The configfs size attribute accepts an unsigned long value in MiB without > checking whether it can be converted to bytes. Both null_add_dev() and > mb_to_sects() multiply that value by SZ_1M before converting it to > sectors, so on 64-bit systems a size of 2^44 MiB wraps the byte count to > zero. > > For a zoned device with the default zone size, this also produces zero > zones. The zero-length zone allocation returns ZERO_SIZE_PTR, and the > conventional-zone adjustment underflows zone_nr_conv to UINT_MAX. The > subsequent zone initialization then accesses invalid memory: > > null_blk: changed the number of conventional zones to 4294967295 > BUG: kernel NULL pointer dereference, address: 0000000000000030 > #PF: supervisor write access in kernel mode > RIP: 0010:lockdep_init_map_type+0x1b/0x230 > Call Trace: > __raw_spin_lock_init+0x3a/0x110 > null_init_zoned_dev+0x5a2/0x1270 [null_blk] > null_add_dev+0x15f5/0x1e70 [null_blk] > nullb_device_power_store+0x29d/0x350 [null_blk] > configfs_write_iter+0x306/0x500 > vfs_write+0x6a4/0x1030 > ksys_write+0x12a/0x250 > > Non-zoned devices can instead be registered with a wrapped capacity. > > In null_validate_conf(), convert the size to sectors with > check_mul_overflow() and reject it if the conversion overflows or the > result exceeds BLK_DEV_MAX_SECTORS. This happens before any device > resources are allocated or zones are initialized. Only checking for the > wrap would not be enough: set_capacity() truncates capacities above > BLK_DEV_MAX_SECTORS, so null_blk would register a disk smaller than the > configured size. This check runs for both configfs power-on and module > initialization. > > This bug was found by a fuzzer. > > Fixes: cedcafad8277 ("nullb: add interface to power on disk") > Cc: stable@vger.kernel.org > Signed-off-by: Yingjie Wang Looks OK to me. Reviewed-by: Damien Le Moal -- Damien Le Moal Western Digital Research