Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp17138948rwd; Mon, 26 Jun 2023 21:45:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ441I5VBiJk5p/SbnbENph2O9HLAjZg7OLRmh4J5ZbS2ojACsO7F//Hdybmbt+GDbiv2+EI X-Received: by 2002:a2e:80d0:0:b0:2b5:9f54:e290 with SMTP id r16-20020a2e80d0000000b002b59f54e290mr4804433ljg.0.1687841120282; Mon, 26 Jun 2023 21:45:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687841120; cv=none; d=google.com; s=arc-20160816; b=VkJhdsp/Khw4SxXAXHRtEURIh9KFV4yD1S5bBEAanGBc6aP2Vf9GR+ZC5yNEfZnLQ8 sdH5hZ0HcnkQaQyUXndsTtWfzpcBBkVaJR31mCi4z99/nA03BWY/CYE4WHPJxjxT/GSu f+Kh971eB2QSOhLfa7PES3JYgIlyVXk0WHmIb/9AiFL938OTbfHcrDdW+TXO/ReA3ejc Va8pGdK0BSra3JGA4EyuLtndW3TXA2P2NJxHWIC67C/3z5TsSzDI2XlGRKAKk5MZT45M B1EKJX+n2Di9MH5LQkxkW8rE6zEXhz2v/jwTGPnIKDzGr9z00gqhkNxLRCtGNmJZ8i1x p3VA== 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=EqRBc0PADGbZDM7sKCQ8u9F+yBp/tzDwMMyGLkJpWA0=; fh=mJnCXYFMqecBMQI57EvjKn2MprVEzJK0wMM1ycvi8XM=; b=YPF6Ty0r54fqDJl/xTr4mjplB+HSO4Yjsp+1llzeMb2j4RL/hPCwCmbXs88vRWILd7 33nfLWWLc8a91omRyuBBxrsu35MihjfpllER+CTl8yHHboh2Ll5i5FKROLxoo7NxRTqS AK7rUrRYUG57r9r791W9hsA3XfLImjCaxuVSSSQ1ajUgUPNU+6mr0b6/RTSiDmygu7LK tKCdG54GBrJwPjhWVaQ/1Rtirf1xMjNWxqKoYvTM8T5xFwvHwQ29Di7s+TlnYfO28k2b D9Wbg+FpovYn3NrrgGfleW/2ujPROFbYxiLTEh4hbElq1beWYSzXtBe0G9CTJ7NYsEPg Gmbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pzchJo4s; 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 p2-20020a056402074200b0051a31360cf2si3570698edy.534.2023.06.26.21.44.45; Mon, 26 Jun 2023 21:45:20 -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=pzchJo4s; 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 S231255AbjF0EnF (ORCPT + 99 others); Tue, 27 Jun 2023 00:43:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230444AbjF0EmT (ORCPT ); Tue, 27 Jun 2023 00:42:19 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93DB53AAA; Mon, 26 Jun 2023 21:39:29 -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 286AA60ECF; Tue, 27 Jun 2023 04:39:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC554C433C8; Tue, 27 Jun 2023 04:39:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687840768; bh=N1xeksPjBTEfFLV5yHQeo/RrVa2KsLpcqtc1W4KXkPk=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=pzchJo4srR1jvJI/1GqOZG7XlCrlK+OgKAUUaKXAutWIpbzg2cu+QlaVSJLZIcmLa QDNuEFVtobR9dfqXRhXLuKj4SltQWyvpQBMkEwbENUtxDRJHtxGUD6UO0D71LE3pTK JC6CmjAvMn4FSIIq1XInRvjwPhQGqBmJPRCRKPa0L7ct0FKygJRHSf1srusOBUdiaY GsEPhLy7MvtD1gDSDom6yuvz5EENriFC1hjdFuWNO0J4bo25PI0TUOBJB0TSN9E1Pg Mghq7pM6GAj4cqC9FrjEDiUYEAYYb6Ti04TT8ySYvzoETgIRXWBkb7KMNWAKfKzdIl u3ABlVI0k+qgw== Message-ID: <8ea3bdfb-f2d9-ee5e-f623-02b2b134490d@kernel.org> Date: Tue, 27 Jun 2023 13:39:26 +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 v2] 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: <20230627110918.7608-1-min15.li@samsung.com> From: Damien Le Moal Organization: Western Digital Research In-Reply-To: <20230627110918.7608-1-min15.li@samsung.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.5 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_MED,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 20:09, 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 See Greg's comment: this likely need a "Fixes:" tag. And I think that the tag is: fa9156ae597c ("block: refactor blkpg_ioctl"). But please double check. > > --- > Changes from v1: > > - Add a space after /* and before */. > - Move length alignment check before the "start = p.start >> SECTOR_SHIFT" > - Move check for p.start being aligned together with this length alignment check. > --- > block/ioctl.c | 10 +++++++--- > 1 file changed, 7 insertions(+), 3 deletions(-) > > diff --git a/block/ioctl.c b/block/ioctl.c > index 3be11941fb2d..c40b382dd58f 100644 > --- a/block/ioctl.c > +++ b/block/ioctl.c > @@ -33,14 +33,18 @@ static int blkpg_do_ioctl(struct block_device *bdev, > if (op == BLKPG_DEL_PARTITION) > return bdev_del_partition(disk, p.pno); > > + /* check if partition is aligned to blocksize */ > + if (p.start & (bdev_logical_block_size(bdev) - 1)) > + return -EINVAL; > + /* check if length is aligned to blocksize */ > + if (p.length & (bdev_logical_block_size(bdev) - 1)) > + return -EINVAL; long long blksz_mask = bdev_logical_block_size(bdev) - 1; /* Check that the partition is aligned to the block size */ if ((p.start & blksz_mask) || (p.length & blksz_mask)) return -EINVAL; would be cleaner and avoid the rather redundant comments. > + > start = p.start >> SECTOR_SHIFT; > length = p.length >> SECTOR_SHIFT; > > switch (op) { > case BLKPG_ADD_PARTITION: > - /* check if partition is aligned to blocksize */ > - if (p.start & (bdev_logical_block_size(bdev) - 1)) > - return -EINVAL; > return bdev_add_partition(disk, p.pno, start, length); > case BLKPG_RESIZE_PARTITION: > return bdev_resize_partition(disk, p.pno, start, length); -- Damien Le Moal Western Digital Research