Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp15924353rwd; Mon, 26 Jun 2023 03:22:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6eEaaeGrIzmvYg4MENZ2m/AbKCLsblbAp34pfi8G4bPwFT075vW4dezDsXfyv+XOnyzxEQ X-Received: by 2002:a17:907:6e18:b0:98f:450e:fc20 with SMTP id sd24-20020a1709076e1800b0098f450efc20mr2773863ejc.17.1687774959696; Mon, 26 Jun 2023 03:22:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687774959; cv=none; d=google.com; s=arc-20160816; b=CUouW7Fr1xlYKkis/sM1TKt+CDgROQd/PW49UyYmgVltrDDlvmjY63uEivgwJfdgGQ vuBlZbtLOsVqMYMnStZEHehP0+diZ847eiang6SLWuL5L4xsjqkx/2QpjO3PU1Ze9eb0 6N0XhM2q7by4mWR365ejXWm7Qx/No6OE5nkDh5+B75KFE5i0eOs1Jy939bwHrhgZm3EO f75VYNKOY9yjQQjI+9oRrSgFQLPOtHxQXFRc+MV/oZ7K3i8ZpDvSkXmfWYaMzmhfa4VP JmZ79ZGUpnHk0vNiecRkoYly+Gm2J0J4W1LpOp/OVEpAVFq8xGScZtX2jjah2krOOgEt iAjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=GAXkraOZbDUAAubo8lJ28Kb4hsJTY8tLx74eBFjzsUQ=; fh=mJnCXYFMqecBMQI57EvjKn2MprVEzJK0wMM1ycvi8XM=; b=J8828wTM3EmJpR8Zvgn2ny+3OYYrW9Daf/wgfAv0a0k6x+h6LAP7+MSH0jHGkeBErO 4TxTxxuJi5J0YeFkQ4e0B63qWIMEkkMyh8NZvV8eGtkrq0TIxpi8Skdg4+rGDv6/2i1I cbhJ65Cogx3WONpaDEilw0VzNMg/I5OUAX+p4XjXBZa9eNIW/CCGmBAn0HvRk6zWaFFi deg4ycVoZvnNtGlCDtSxfyxbl/FOocEieRY8BQ/B6b2KxGWZWVE3JQMpz2gUSCwDSPy7 0m7Ru8mnEvjDWCg2X4bRNolhhQwcbANsrkWE19uW+9dz8EpkBPo//CsRFEl7OAEX7C6s Up4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EzmjwqC+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a11-20020a170906244b00b0098e24139521si1744823ejb.743.2023.06.26.03.22.15; Mon, 26 Jun 2023 03:22:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EzmjwqC+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229523AbjFZJia (ORCPT + 99 others); Mon, 26 Jun 2023 05:38:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229997AbjFZJi2 (ORCPT ); Mon, 26 Jun 2023 05:38:28 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8132DDC; Mon, 26 Jun 2023 02:38:21 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 151D660DBF; Mon, 26 Jun 2023 09:38:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF897C433C9; Mon, 26 Jun 2023 09:38:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687772300; bh=ahzSom5WrWgfJ+H+CGnj7o11RaZMEt1ei4pjJwpiac8=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=EzmjwqC+Fcup+VoqKVVAT3fE4dvL795jxiqSzrFguEbCBK75+A0kYb07HTlp+GBNu WZPqjtXhLn6SLqS4aVn4aypOCfVm8nLZLgl351Y0xrQRFG+SgIznZ9q4FcmlHoLzS7 TbFVKvkD7lEdDAdoBtQPp/hIXgrm4QN0wQqAkEpMcIKQHzeOH17RNoWxaFhwNZMP+s Pepe5gzBM3Ghrep/HE0NJILpCq659Tdr4Pra0xt7fO8uvJnwXvMvHmK2Y9+8HnIXR3 Dj5c9bbF7jVfq5hsfqWhwbl3lkJJw9gt+igOCFbu+u74shtniTn+1ycaP8pGZRVXTk STbPLjT+0LnCQ== Message-ID: Date: Mon, 26 Jun 2023 18:38:18 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH] block: add check that partition length needs to be aligned with block size Content-Language: en-US To: Min Li , axboe@kernel.dk, willy@infradead.org, hch@lst.de, gregkh@linuxfoundation.org Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org References: <20230626171021.5895-1-min15.li@samsung.com> From: Damien Le Moal Organization: Western Digital Research In-Reply-To: <20230626171021.5895-1-min15.li@samsung.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/27/23 02:10, Min Li wrote: > Before calling add partition or resize partition, there is no check > on whether the length is aligned with the logical block size. > If the logical block size of the disk is larger than 512 bytes, > then the partition size maybe not the multiple of the logical block size, > and when the last sector is read, bio_truncate() will adjust the bio size, > resulting in an IO error if the size of the read command is smaller than > the logical block size.If integrity data is supported, this will also > result in a null pointer dereference when calling bio_integrity_free. > > Signed-off-by: Min Li > --- > block/ioctl.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/block/ioctl.c b/block/ioctl.c > index 9c5f637ff153..aa95b5561169 100644 > --- a/block/ioctl.c > +++ b/block/ioctl.c > @@ -35,6 +35,9 @@ static int blkpg_do_ioctl(struct block_device *bdev, > > start = p.start >> SECTOR_SHIFT; > length = p.length >> SECTOR_SHIFT; > + /*check if length is aligned to blocksize*/ Please add a space after /* and before */. > + if (p.length & (bdev_logical_block_size(bdev) - 1)) > + return -EINVAL; I would move this check before the "start = ...;" And while at it, I would also move the check for p.start being aligned out of the "case BLKPG_ADD_PARTITION:" together with this length alignment check. The p.start check is not needed for BLKPG_RESIZE_PARTITION, but it will not hurt either. > > switch (op) { > case BLKPG_ADD_PARTITION: -- Damien Le Moal Western Digital Research