Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp664909lqj; Sun, 2 Jun 2024 16:59:23 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUohy9+kGGSesgrX4Dg9kzposaotEGkVXzpRE4NatBKOooSg7z0D6zCNkMCjJRtXG2SqVu3u+h3llxiwa443CX1rPL0H2n06KhWJIRRgw== X-Google-Smtp-Source: AGHT+IGmYLDdQiGUqOJPK3YNRkU7Weu2xTTRUt4WR8NfXkFi3vOOmmbU1fknHJ6Bi3vqqo29dj45 X-Received: by 2002:a17:906:66d4:b0:a68:c86b:e0ca with SMTP id a640c23a62f3a-a68c86be1c2mr231355566b.18.1717372763204; Sun, 02 Jun 2024 16:59:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717372763; cv=pass; d=google.com; s=arc-20160816; b=Hj9HNmK7WBig/9UperqV6OhyQWwF7UzqZ2+/PtCnthXRDyKFnc+tvKI4XgotEUBlpA 5qCTN5Z8nejV+PQldN/6xeQAmlXT+USQp0TYnD/fC3TNSwisAfdPMwvv/nN/TMzLWyq5 lHPrnys8bdHWuiKzzARN+Z8dW5s2tJeTYRDtWsPvRQBmprdKniJ+3ust7MZLCeDPHRMC eOnRmOxSicmtT/eothzM+Q/tgk7ZrgoqGkv1c7KfmJKojTxnouWqxqlFC6ZahRxbxTe7 JraH4eeGyFdMWlMU3CDgPAlhM0lmb1I3gW9cHa9x82DJMgiTVfcEE/3KfpDaX8TNURuD bogw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:organization:content-language :from:references:cc:to:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=lM6aSpFZntK/QhxTBTF8ANzGFQwoO8o2nkqKpjElFAE=; fh=FXGsVp+eN5oqtsuhGV5/G5G1pNf1SafN8ZfFnot2oJ8=; b=N01V2TWcwqIAmFCWy7zTOec+kaVY0BYtk5/vlGflKS4NJRk6pYFqD4lrUVIeCtuzWo w4QKr0+++HwQ8QdKTJ+jPYOV/aNPvHIW9SF2Crb58QMuwKkCJMcXY+8hLKp2VCtxZD+1 kdxujMAd50hyXs9tUp3sPFX0xQmmWAUT+1P1J8e/dyYOhZsgqCGhBwcOnUmjbCt28NQm 36Jc62EzzV0JNCfXzDZTOtRpFbd2T/g6eePDGV9JDXGNQabCdBlX/NS/XumqKpUWRx+U DFXweWhiRwwdBQ1vTTOz8gPyacEh06VM1K9tJn6tuJFF0yM8aQHMTxO2VKvTR2bg7Ypp VWDA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lZ4cfxlM; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-198494-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198494-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a68ff4689easi77886366b.409.2024.06.02.16.59.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Jun 2024 16:59:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-198494-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lZ4cfxlM; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-198494-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198494-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D0BE81F21D96 for ; Sun, 2 Jun 2024 23:59:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D9F297F7D5; Sun, 2 Jun 2024 23:59:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lZ4cfxlM" 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 097BF7E765; Sun, 2 Jun 2024 23:59:12 +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=1717372753; cv=none; b=Z2thakL7TgxXTlBk3cuk85FVkuUC7Y8v8mHLVIxO9l4z9Ge9s8+XtY2rMgdD7yzylAJ6O+lx1fui5M7px6JWKgkLqMx/blmYDcAHz6W7Y4hYdRRyzjpddOPIWOy3rdHlZb/beuVAFPHsLOxfVAFRN+9DZGF6l2Paze/S5+yjRjg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717372753; c=relaxed/simple; bh=f9O5QybcaMD2WnAIw2zJMF2wywEOo5ijEP+aNWm+CN4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=IiVGFslJfd7h3bcqG6w+UCji3ROPX+oJFNRhreaLcbrHBQKk/VMLF1L8x/nn+ZLN5p1yMZq2ZYrBhxZdEKSorCZgFBVmAJKTp5ZeEne4e0941VzhQxcYnE0HT+c7VW7KDiCInhLFirpD4Q2BIen/LvV+Oq4SU/G/u6Rnb28ueLQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lZ4cfxlM; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 81146C2BBFC; Sun, 2 Jun 2024 23:59:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717372752; bh=f9O5QybcaMD2WnAIw2zJMF2wywEOo5ijEP+aNWm+CN4=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=lZ4cfxlMdcwhOVhbqsf9w4uFBEq+LN8pDb0XkjLabo/Zy97mJnI9UreSoibY7uHl7 3ZpWy1VJOLx3FpzUmjzhhsXsXRpzoFTlA8q3sp+cXgdrSBw8DRZcStV9JGQ37KhzVh RJ4N/06Hcvml4sBrmT2zbaXVJoo3Xif7/7QLvtYSTuU+AEBV2WWTlz+FKseOz6w4zC JW79RueDt6DIdpx0uwHAgcHV1TCJtLDWZJ4mhHO1Jd0vvRKbQI+DvFFnsn8XD4wmwq zuLmEogyxrmCesQe9NSvRHAf3mKQCNFKx6ZQRFNlD0Jkk7ZKrxHAHGsyemQDXFcc8U F5ZjC0rwW0a1w== Message-ID: <9d68c7c1-b1e6-4f42-8d4b-8c986ab688b5@kernel.org> Date: Mon, 3 Jun 2024 08:59:10 +0900 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] null_blk: fix validation of block size To: John Garry , Andreas Hindborg , Jens Axboe Cc: Andreas Hindborg , Keith Busch , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org References: <20240601202351.691952-1-nmi@metaspace.dk> From: Damien Le Moal Content-Language: en-US Organization: Western Digital Research In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 6/2/24 19:57, John Garry wrote: > On 01/06/2024 21:23, Andreas Hindborg wrote: >> From: Andreas Hindborg >> >> Block size should be between 512 > > >> and 4096 > > Or PAGE_SIZE? PAGE_SIZE can be larger than 4096. But most drives are 512 or 4096 LBA-sized. > > and be a power of 2. The current >> check does not validate this, so update the check. >> >> Without this patch, null_blk would Oops due to a null pointer deref when >> loaded with bs=1536 [1]. >> >> Link: https://urldefense.com/v3/__https://lore.kernel.org/all/87wmn8mocd.fsf@metaspace.dk/__;!!ACWV5N9M2RV99hQ!OWXI3DGxeIAWvKfM5oVSiA5fTWmiRvUctIdVrcBcKnO_HF-vgkarVfd27jkvQ1-JjNgX5IFIvBWcsUttvg$ >> >> Signed-off-by: Andreas Hindborg >> --- >> drivers/block/null_blk/main.c | 6 ++++-- >> 1 file changed, 4 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c >> index eb023d267369..6a26888c52bb 100644 >> --- a/drivers/block/null_blk/main.c >> +++ b/drivers/block/null_blk/main.c >> @@ -1823,8 +1823,10 @@ static int null_validate_conf(struct nullb_device *dev) >> dev->queue_mode = NULL_Q_MQ; >> } >> >> - dev->blocksize = round_down(dev->blocksize, 512); >> - dev->blocksize = clamp_t(unsigned int, dev->blocksize, 512, 4096); >> + if ((dev->blocksize < 512 || dev->blocksize > 4096) || >> + ((dev->blocksize & (dev->blocksize - 1)) != 0)) { >> + return -EINVAL; >> + } > > Looks like blk_validate_block_size(), modulo PAGE_SIZE check Not PAGE_SIZE... > >> >> if (dev->use_per_node_hctx) { >> if (dev->submit_queues != nr_online_nodes) >> >> base-commit: 1613e604df0cd359cf2a7fbd9be7a0bcfacfabd0 > > -- Damien Le Moal Western Digital Research