From mboxrd@z Thu Jan 1 00:00:00 1970 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=1796306218; b=PxTg+Pss3Le6LC99ph43NP6B5YmJnMe25JzApHp+pEP0CXA9cHQOqlI+BxMe50skKe6i Wp440HDf6V2w9aWlpQ4XSylsOtdu00Na7xl7mR8m2Y1uSr5F65x8aBJETDOGO7AdqxSHG jOVyyZ8EdDYFndjx4LGrcfySyYrqTF4degDqcR2bdgbAcuvh6xEkTchOym3Y7QTmFYhM4 8VOwfT/rHIkQei8zeoAZ0KEPCgWiLUELzlHO5xq4D2ICIhl+nMm1GgvnGsuqdNmD2K+14 GTj6Ud7v+XP50WirIq/YHLmG4jeHqWe507Fsgr2+W0ox2tfsQ1pcnzvn1+/4dsz3Isw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796306218; h=Received:DKIM-Signature:From:To:Cc:Subject:In-Reply-To:References: Date:Message-ID:MIME-Version:Content-Type; bh=CH5SqRETTmpd9oJSicVZyFzOPeQcBBndSjSn5+msCQ8=; b=etrYBxSopOu/rQhV8DsmUuvZxLpUqeKGPuaRfDmbHrb11p9y5pA54fwO53vE2nxEGi6j H1T/VygEUEuH5q4PjmrzFq922pHy1MuZ3FyCzsLMRWMo59xj8+Z/MQqxRut/GWlxNmynC iGPoBUTJDgOSzIFW9mjl6oXfLFwW7BB3LHFOulwOh7dIiFp7NreplCvcEw75oTMxgN5P1 LzXJD4767TZEqYBU8pzTCAwKHeslw132GCGFkwjHr9TYM/oR8zBQj8D8SVdeKsBzw7hr1 fiZtkOiyb/Ct4QubRuI+CxYpT1+CIRjGqkKUbDhQUCgk0dK7gPOf8106r4w22uqc2EQ== 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=cM75Zb34; 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 A3EEA606A32D; Thu, 3 Dec 2026 13:56:58 +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=cM75Zb34 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C3861F00896; Thu, 3 Dec 2026 13:56:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796306218; bh=CH5SqRETTmpd9oJSicVZyFzOPeQcBBndSjSn5+msCQ8=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=cM75Zb34GQDOSE/VBkVUYvLTjLEXVsM1LEQw+HFasnOVTlN9l1FWECFIs2s/KtCe6 Xvbb1vPN/emwnVfaThDwwhqjPu7a4maUgy2kQkYHpFgt5+e+JVLphxkpHAj4f/cZUC lTDfMULOIWPmMp4wdfc+s7HVUsEJNobwmow6Gh5k9RhW1WXmNe2DzGb+Ch1j2Tebqe NUNK0s2wcE7xZT/tsism6uCW8Nyp71V159PNliOzTaEISJsbTz7cEWv3f8brPiQNQR 89I5QSTisny3RFWLex7NQQLfhQImG7BGwNLmFGLfwZY/T98NIEPbvRdlV3fUAn/Uje y5nDpg2GH4HTA== From: Andreas Hindborg To: Poil Zero , Jens Axboe Cc: Boqun Feng , Yingjie Wang , linux-block@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] rnull: reject device size overflow In-Reply-To: <20261203115742.384873-1-poilandgginchi@gmail.com> References: <20261203115742.384873-1-poilandgginchi@gmail.com> Date: Thu, 03 Dec 2026 14:56:50 +0100 Message-ID: <87ecbyzcv1.fsf@t14s.mail-host-address-is-not-set> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain "Poil Zero" writes: > The configfs size attribute accepts any u64 value in MiB. > NullBlkDevice::new() converts it to a count of 512-byte sectors with > capacity_mib << (20 - SECTOR_SHIFT). Bits shifted out of the u64 are > silently discarded, so 2^53 MiB becomes zero sectors and 2^53 + 1 MiB > becomes 2048 sectors. Smaller values can also exceed > BLK_DEV_MAX_SECTORS and are clamped by set_capacity(). > > Reject sizes above BLK_DEV_MAX_SECTORS / SECTORS_PER_MIB in the > configfs store before updating the saved size. Also use checked_mul() > and check the resulting sector count in NullBlkDevice::new(), > returning -EINVAL if either limit is exceeded. Validate capacity before > allocating the tag set or queue data. This prevents a device from being > created with a wrapped or clamped capacity. > > Apply the same overflow and capacity bounds proposed for C null_blk > in the linked patch by Yingjie Wang. > > Fixes: d969d504bc13 ("rnull: enable configuration via `configfs`") > Link: https://lore.kernel.org/all/20261201140214.346038-1-x-professor@outlook.com/ > Signed-off-by: Poil Zero Thanks for fixing! Looks good to me, but I think we should move some of the constants. Please define `MAX_SECTORS` in rust/kernel/block.rs based on the C define. I don't think `SECTORS_PER_MIB` exist in the C code, but please add that to block.rs as well. It seems generally useful. Best regards, Andreas Hindborg