Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp788655rwd; Thu, 15 Jun 2023 01:58:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4sPiBFRXwWYuxjMVYGKz1gQp8NxNS8ruiGQOGw5rmQzo6Hw2aNYsbLkEFZCv74PK/jDDY7 X-Received: by 2002:a17:907:5ca:b0:977:e2a6:47ce with SMTP id wg10-20020a17090705ca00b00977e2a647cemr18182374ejb.35.1686819532544; Thu, 15 Jun 2023 01:58:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686819532; cv=none; d=google.com; s=arc-20160816; b=eD8QPLz4ydK4rLlp0xQ3xBD+s+m4As8ZMfpNNN3BFIDmCcoCPlfLnTSqy2t9lscR6e nFQaOn5mM3xO+5b8cnptiYF+lkFR0WG1esdvPDc9CvO9DIrPq0/2y9hh9EUqRZmPOE2W Q/+wzXCNmITM4kvZFk1d/V+1I1nIlbfVsz6CVhR9q9ruES1hW7ZQ6/tqD8D4FEPXmWe6 0mo6vaQq7oMRd94mnpa8JbIOk/hXZk5T/07q+6F7nYHJ/q0z5swt69WhXglggA3qkWu/ qaqndYRtMjmGSO34xJ9CtfW14ADBsVexZ115j0AwFZELRHWfF1VZFbO1/hnJ0W5DhbrH gWcA== 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=XoWgZcMGjXIe6m3cLHZsxGgP64oO9vRmz1nYDpgwyug=; b=kxUFFogPHq8D9deZDQEnEOvoPaB0g2oxb1+7x8X2S4Jy51dj+hRXxGFGT7d7zNDWq2 nVez5vpYtoi16r3/EZEKo973aILWJKEuSRoFIpJP+whEiBI1Eq8dm9b/NZynaJ9hPK69 l6Z/9svVPnEvRFSavxGKkAi1Ngx1CniatsmQoUVlOAvrYMqJXdVOLv0TfSdqX9G1MXtu npSRqzaJK29VVAXGK4aV2PBIGc5GEXjPbGxfffAFUz+D3Yo4DsPpY6Ka3NzloK4w3niE DNR3+qGK6D5nBX7FgvV0aUpne7NxD8DlZVXB/eD4Y7y0L33cg8vc0/wyM+xpWBVJfXps kx2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=E3D3MvTx; 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 oz19-20020a170906cd1300b00974619b1bc0si9299970ejb.161.2023.06.15.01.58.27; Thu, 15 Jun 2023 01:58:52 -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=E3D3MvTx; 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 S240838AbjFOInW (ORCPT + 99 others); Thu, 15 Jun 2023 04:43:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240859AbjFOImy (ORCPT ); Thu, 15 Jun 2023 04:42:54 -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 CD810294D; Thu, 15 Jun 2023 01:42:51 -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 62F7162C20; Thu, 15 Jun 2023 08:42:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C2563C433C0; Thu, 15 Jun 2023 08:42:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686818570; bh=Kk5Cv8hJcuoe/LCGdg/cP74GAed73Sgd3BjIVq+pCak=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=E3D3MvTx+nnd0OMgQ43XF0zLmIL3G2wOj9bFYBZQoHfq/g6WUAKPnWgRCJHvBKMrp okgZq0m2qy8tTj/iFhnWsLUUQcp6KIdYjtHhJ38yhN+L8TzL7qZ940tAbdCbTaFp+k PUmpegmN3fEg3AnXu/KKgBZWO9MD3MDdlt46bJspcddikcnEsyrL+4fbq3avHkXH+n iU+BmPF2LM7pcM0LNj1vQu4OdKU6XC06EjEtVxwdjGOJbmjzDYb+AEvMtIvs2AeFKH Fs6E1DNaKNiaH8wiD8pmxcOHnXCw0G+loMnoDap5ZMKju3kf964ZFF69iTfVKJY5US lcKg0EHd5+3aw== Message-ID: <621fecd9-52ee-b5ba-6702-c283658096ef@kernel.org> Date: Thu, 15 Jun 2023 17:42:48 +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 capacity validation in bdev_add_partition() Content-Language: en-US To: "min15.li" , axboe@kernel.dk, willy@infradead.org, hch@lst.de, gregkh@linuxfoundation.org, wsa@kernel.org, vkoul@kernel.org Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org References: <20230615160929.9240-1-min15.li@samsung.com> From: Damien Le Moal Organization: Western Digital Research In-Reply-To: <20230615160929.9240-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/16/23 01:09, min15.li wrote: > In the function bdev_add_partition(),there is no check that the start > and end sectors exceed the size of the disk before calling add_partition. > When we call the block's ioctl interface directly to add a partition, > and the capacity of the disk is set to 0 by driver,the command will > continue to execute. > > Signed-off-by: min15.li > --- > block/partitions/core.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/block/partitions/core.c b/block/partitions/core.c > index 49e0496ff23c..9806a804e1a4 100644 > --- a/block/partitions/core.c > +++ b/block/partitions/core.c > @@ -445,6 +445,12 @@ int bdev_add_partition(struct gendisk *disk, int partno, sector_t start, > goto out; > } > > + if (start >= get_capacity(disk) || > + start + length > get_capacity(disk)) { declaring: sector_t capacity = get_capacity(disk); at the beginning of the function would make this check prettier and fit on one line. > + ret = -EINVAL; > + goto out; > + } > + > if (partition_overlaps(disk, start, length, -1)) { > ret = -EBUSY; > goto out; -- Damien Le Moal Western Digital Research