Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp916064lqj; Mon, 3 Jun 2024 05:07:45 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXXIAcl8rKZxga9IwGs+ggmYhpMLPJxuwKmIKxkEpcI4KnEH3kwCqeWTYTG7IwmrvJ5EapVHfne2hvs4Mme/DF49DMzc6FFDhy7OhTCuA== X-Google-Smtp-Source: AGHT+IGtdQeSxmxmJtmQFWh5D2YTLYgcMDAab3E7bqGpVHk8/3p0z5augOnv/CdaH/JLSilgV1ID X-Received: by 2002:a17:906:7d98:b0:a68:f43c:57dd with SMTP id a640c23a62f3a-a68f43c5841mr304338266b.23.1717416465192; Mon, 03 Jun 2024 05:07:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717416465; cv=pass; d=google.com; s=arc-20160816; b=xuo13OVYGWr05HgfCvzhr78Ue1F3AJP/zlQejZNI8KwxKdTa4fwOgt87J2Fu+adZTO dgdRSJyxNmqSFAVQyYE5K7ryfrut2HzSPgGtqvW2KBnxZTHfzurKWpJvbl1EblmoWD2R 9nRe/NIKhPJK3zFFr89Y6SyyBJ06vWBqHoPkXSdsHer/RCeQrmjoZlLu3qVrNlGkUinr HeGfHBbnp6L69cJPLDfjbd+cPBVMc/JE7gY1mgnKKmKhn7ZrsJM8A6U1xkGV4gEZaIju gxUZArCfQLvh0c7CqLZUcnFua4BMsiOFAwVMqWHnxVoGw82VubXth1/1NQP5UiL1jSI+ 4GOA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=N43+9H6E0yFDxtyEp5leqtS2IT5bU0sKoqZhcVUnDjg=; fh=+sgbPUA7xf4yEvTCmHPc4DCy8L5HPuPfcK4fwdHpyxA=; b=t5TElrvL1cbjEm6FK2eMmcJB/enQSBDe40Rl3Sna9TmSox5N9n7964ecgLal2778YU YhiuUdIvaAxdNME5/jboc1b6G0RQYQ34nxDPSzCofILLd3jaUANuQhTe2tbiaExQ4GhZ oydRmdCQQ7P415xzHo7p0W2rQu1H+dae3/8jtF2O2YDG7Lk5DfFKx2E8pOm6YJVJ90w5 /vZafCklrPUidGyNJ0TF0kgkW5ZX6x3P+DgJzEXQsSSHvphB7UKYu4NPIbyz9u21cYxo U7UITeE+1MJ5JoAnmguDPUHsXhPKtXV4MqKPYhaEa8uKx9uHYywG29L3PwAbmluB6d57 1p+g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@metaspace-dk.20230601.gappssmtp.com header.s=20230601 header.b=tZPl3dxq; arc=pass (i=1 dkim=pass dkdomain=metaspace-dk.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-199078-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199078-linux.lists.archive=gmail.com@vger.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-a67eaf652f5si399417066b.879.2024.06.03.05.07.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 05:07:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-199078-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=@metaspace-dk.20230601.gappssmtp.com header.s=20230601 header.b=tZPl3dxq; arc=pass (i=1 dkim=pass dkdomain=metaspace-dk.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-199078-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199078-linux.lists.archive=gmail.com@vger.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 D8BC81F22A89 for ; Mon, 3 Jun 2024 12:07:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B7D4A1272B5; Mon, 3 Jun 2024 12:07:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=metaspace-dk.20230601.gappssmtp.com header.i=@metaspace-dk.20230601.gappssmtp.com header.b="tZPl3dxq" Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 52B1885634 for ; Mon, 3 Jun 2024 12:07:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717416453; cv=none; b=jE/r28e97QIIx/ismSXtQCsK/0KgJ+oFxU4B6enUmwVA642krPuNsgz4LVEpjKpbdR2FMrjC4r/Fq8v2l1ZkB7qf7M81Sx3XffCbUk1nrIjSwclShDVpFy7B+dhQrwcCSpoKRpx0qTSkrrK12hivfD+ifdi+F3HaUmsJEqvb7mM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717416453; c=relaxed/simple; bh=Y3gF7BbKcqa4JwB0PvnAnvWiJxHmYd92raETWsFFdRQ=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=pZMnpBMznJ5DkoBNAtXAvFOvMNZclmvxsRIAU6QCd8nU/t2MeAkaz0PT31Ddo1tsAXP3wZnurMxXKzcGjBlDKH+k798O4KZ0lDVclBH8iMmX7kW998AA7sQBmDNt/8BVRRZ4eZblWzIdZV85HuGpA54nx0fK1hagnJydvJYCnjY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=metaspace.dk; spf=none smtp.mailfrom=metaspace.dk; dkim=pass (2048-bit key) header.d=metaspace-dk.20230601.gappssmtp.com header.i=@metaspace-dk.20230601.gappssmtp.com header.b=tZPl3dxq; arc=none smtp.client-ip=209.85.128.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=metaspace.dk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=metaspace.dk Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-4213b94b7e7so5944835e9.0 for ; Mon, 03 Jun 2024 05:07:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=metaspace-dk.20230601.gappssmtp.com; s=20230601; t=1717416451; x=1718021251; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:from:to:cc:subject:date:message-id :reply-to; bh=N43+9H6E0yFDxtyEp5leqtS2IT5bU0sKoqZhcVUnDjg=; b=tZPl3dxqYf9d3vwn+V7fPEZEbncNj6gj9Z+Su3MetWZlqYyp/kN//gENoi5IkVapeo 6LsBVU7+0mgOLKMEc2vnXNr4C5T6eXTxiGCP4v1ZWOyoNDoAZtG+3fv4y4qmgJxtWubH +tCAuB2MnzRyffwwlO4ERu2XgWhQoUAg5Y7bF01qHsp+Xl0VPCRhJTtqO8S7MD7nXRw0 NyxMNJPiBOe6ij25a7+UXsmjEjhB763e2YdLrzqSM7Ye5l6SDhyeVVo8ZwMiGgZqFKau AmaNv1jkO7g0OSUt2RmWtz1boULWDZMeF8TQuWN0BlPuhXhuDx7BLK4PcPwvgfSME4X6 p2bQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717416451; x=1718021251; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=N43+9H6E0yFDxtyEp5leqtS2IT5bU0sKoqZhcVUnDjg=; b=lIVtU1TUEkOtH6HiUEDpTisJv5K+aOXAejj3nQD5J2SiXV2vG68VFJ+A7NrlsUpQps m+MOT1zuCb0XEsb+13d57uRhu4oCuzv+TNXdnHhjvtHTTXRmxMQttW/AZltIV7oo2au/ 2XsgliPVhRI8gCsQq1N8p7Rv7cQ8ms2sgDiysewvJlPC5oKDa5IMq2eWM0gsuurTRGEC gIegymBRuLjCBrZItS5QeNeP6FEynNXvxtNkxXrHyBeK/k9PawWCBRpSKqChaUa8Kwpw lhGFyIj4AXG78uqBgS6ZETDCgOTA1pvGMHbXIP1iIyR5CgGS23wRoNJ6Z3FGTl4c0D36 RPxw== X-Forwarded-Encrypted: i=1; AJvYcCWp6wnIm+aHuSa0uixSTmmfcofUEtlDRm+jBWTVlHkNkiPUUdWcjysks5UDXvkreb09xIBGsICs5M9G7A0IAa+Q3AAOsWItLjs3jsEY X-Gm-Message-State: AOJu0YxqpmyYvL02dl7h3548FXuPu9pD50ubpq8ZHVw9kXpPAe4aPGZ3 hi485hCsVCT+jdCnJRiKQrMVbFUKmfNc2zLtGwRSl3LkQQRvXHLcsSWraOl2f7o= X-Received: by 2002:a05:600c:1e27:b0:41b:8041:53c2 with SMTP id 5b1f17b1804b1-4212ddb68d0mr81757385e9.15.1717416450440; Mon, 03 Jun 2024 05:07:30 -0700 (PDT) Received: from localhost ([165.225.194.205]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4213837673csm70127375e9.31.2024.06.03.05.07.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 05:07:30 -0700 (PDT) From: Andreas Hindborg To: John Garry Cc: Jens Axboe , Andreas Hindborg , Keith Busch , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] null_blk: fix validation of block size In-Reply-To: (John Garry's message of "Sun, 2 Jun 2024 11:57:03 +0100") References: <20240601202351.691952-1-nmi@metaspace.dk> Date: Mon, 03 Jun 2024 14:03:34 +0200 Message-ID: <87frtumdwp.fsf@metaspace.dk> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable John Garry writes: > On 01/06/2024 21:23, Andreas Hindborg wrote: >> From: Andreas Hindborg >> Block size should be between 512 > > >>and 4096 > > Or PAGE_SIZE? Right =F0=9F=91=8D > > 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=3D1536 [1]. >> Link: >> https://urldefense.com/v3/__https://lore.kernel.org/all/87wmn8mocd.fsf@m= etaspace.dk/__;!!ACWV5N9M2RV99hQ!OWXI3DGxeIAWvKfM5oVSiA5fTWmiRvUctIdVrcBcKn= O_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 =3D NULL_Q_MQ; >> } >> - dev->blocksize =3D round_down(dev->blocksize, 512); >> - dev->blocksize =3D clamp_t(unsigned int, dev->blocksize, 512, 4096); >> + if ((dev->blocksize < 512 || dev->blocksize > 4096) || >> + ((dev->blocksize & (dev->blocksize - 1)) !=3D 0)) { >> + return -EINVAL; >> + } > > Looks like blk_validate_block_size(), modulo PAGE_SIZE check Cool, I will use that instead. BR Andreas