Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp1314234lqj; Mon, 3 Jun 2024 18:28:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUfJ9uLnIJYNPT96jXDgsGUopHKqkk9noHVf4umgYWVr7HPJXXvMfuOSGyA7bItuSHDRjDs3bYfKXMYx07L2r5M/YaXd7wil17rdfnmPw== X-Google-Smtp-Source: AGHT+IEijhkG1w5PgoQHBsNLyQqGPzHpF1xATFYAVgROJBU/Ake7yXMar4+8tiVMUxdH/4wYL1aF X-Received: by 2002:a17:906:280e:b0:a62:5094:817 with SMTP id a640c23a62f3a-a6954260d38mr75594066b.11.1717464500390; Mon, 03 Jun 2024 18:28:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717464500; cv=pass; d=google.com; s=arc-20160816; b=GISPU84HMkPfXK5X+iRTel5ZO/kuibzItaq983+XvmT5+668SZp/p6JSXKSrAag8v+ xoklStveXKFGrSTA+c0RBzybursFc2HtNhQvoUzB5RsqMQuaCHOBJiLy119M1aPLgimt 2163hy4y5aM7Wju3raGSahrNpEUYhvOAFx+W8a2laVj0f0UkSr/FlBsp+R+xrAaHtu5J uwU63Ck4yhrI1dDXKJ7fZb6z5l77ZlXgGvVgdLDPf7HU1yLCXeeYCM1lUs5RLx80gys0 lw+O5rrM0jMSJtB0Pcp4JU5TuXiRDgHAsMSLjXY7PxGhSduEOXbZWvOcGQ9PSRXWWTdY S0RQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=7Z7SRvzAMckA3XNXJwgjMYaITshj7fSHWjmozr7eVY8=; fh=fsJUtINxYLNq+2M+moruG1On42th7VqR9NceAIs+MQI=; b=bSKZvnqYR5N+f3lgtgwN1sK7DOJwSVQ86fwW+bj470FfpJQ/JSYLnoBWJrNPgkPda2 PnetJP+HdtrWiNaW9RtyhXDSInRay579wdZRBVk/u+dF5UZfE8ohrMg1FVarRa89v9UA kzFtWIeuyHEStsuOtGkqW9PyZTdXHZ7745ET3z5j9G85NlHTtwlw5dvqwL3PJ1Bhz7MK l7bTY57jXWM3I2DKBmj6UiZDfViVeZmFARkvl//yhNg4dD5siUu+/erov/YZViSX64Zz ZKg8z8gS+eHtzLpdO20fcK12b9GupvIKx285uFcxkcObNYhrUOjTSTTGj2T3ScDGhwIS K/eg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fxmDvlsv; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-199905-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199905-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a6939ad4c54si54024966b.103.2024.06.03.18.28.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 18:28:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-199905-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fxmDvlsv; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-199905-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199905-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com 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 1B0261F22745 for ; Tue, 4 Jun 2024 01:28:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 55E2F1386B9; Tue, 4 Jun 2024 01:27:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="fxmDvlsv" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 285CB135A46 for ; Tue, 4 Jun 2024 01:27:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717464474; cv=none; b=H5l/11xcyaTg+Ru9qQTfd0k2Q01rhbv5HGagXcV/A1MmUwQwDtHLSD9cyq7k/kDnlXDIC3vvpR+VBOj0FnHZR1YNxCVh8IUqBqSuCb0N7cvZ1OdwEJcwyyYw7ig3BrJZHH7CI13J/xODeJDO4aWKTr/yua4ZcKMFcEQqR+OMTSE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717464474; c=relaxed/simple; bh=90tuKrUWcNjEg3Qnxq7XEyrl7dqi8tX3BxxtJmME1cI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=eCV9VYXCZXea0wG+11eN9xkZfcsHinW+3Mve47OrVOKaEbar5Hu7Ap5I3t4jd0Td4LXIdbLjey8EUh09l+V7uP+UxAH5iy8jpzFjgni7+8VkPVTX04m9pdxR4zt6UoKb21kB8QsfiFn0f95x71bfnPbhpAGhTp2FemTEBrd1/94= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=fxmDvlsv; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717464472; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=7Z7SRvzAMckA3XNXJwgjMYaITshj7fSHWjmozr7eVY8=; b=fxmDvlsvFuZzvhcZCdKa8Vj8a5Ycwae/bQ0AL2NysxBSEJKIKXFdiaMtxBAjAHnrnbY2tU O67OF7wgN9rQ78Dcvyz2qWTJnTrnNcxjPFMoRZykONDSMf0ixdfPbGxvuySFDRJ5bEaz6k BceGyBSAPw9+DCvKSww1NwVn6CL+mAc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-28-RGD_dGosNgWi7FEPvIMLBA-1; Mon, 03 Jun 2024 21:27:48 -0400 X-MC-Unique: RGD_dGosNgWi7FEPvIMLBA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CD671800CAC; Tue, 4 Jun 2024 01:27:47 +0000 (UTC) Received: from fedora (unknown [10.72.116.69]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6AD641000552; Tue, 4 Jun 2024 01:27:42 +0000 (UTC) Date: Tue, 4 Jun 2024 09:27:38 +0800 From: Ming Lei To: Andreas Hindborg Cc: Jens Axboe , Andreas Hindborg , Keith Busch , Bart Van Assche , John Garry , Damien Le Moal , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] null_blk: fix validation of block size Message-ID: References: <20240603192645.977968-1-nmi@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=us-ascii Content-Disposition: inline In-Reply-To: <20240603192645.977968-1-nmi@metaspace.dk> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 On Mon, Jun 03, 2024 at 09:26:45PM +0200, Andreas Hindborg wrote: > From: Andreas Hindborg > > Block size should be between 512 and PAGE_SIZE 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://lore.kernel.org/all/87wmn8mocd.fsf@metaspace.dk/ > > Signed-off-by: Andreas Hindborg > --- > > Changes from v2: > > - Use blk_validate_block_size instead of open coding the check. > - Change upper bound of chec from 4096 to PAGE_SIZE. > > V1: https://lore.kernel.org/all/20240601202351.691952-1-nmi@metaspace.dk/ > > drivers/block/null_blk/main.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c > index eb023d267369..967d39d191ca 100644 > --- a/drivers/block/null_blk/main.c > +++ b/drivers/block/null_blk/main.c > @@ -1823,8 +1823,9 @@ 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 (blk_validate_block_size(dev->blocksize) != 0) { > + return -EINVAL; > + } Looks fine, Reviewed-by: Ming Lei Thanks, Ming