Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2524692rwd; Fri, 16 Jun 2023 05:03:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5jnrQLms//i9WVn6UK51P/y0uo3mj7b6qGR3AKTacJEtMn8bNkRZO6dv/qZGTKtckARPx0 X-Received: by 2002:a17:902:c944:b0:1a2:a904:c42e with SMTP id i4-20020a170902c94400b001a2a904c42emr2667756pla.24.1686917029744; Fri, 16 Jun 2023 05:03:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686917029; cv=none; d=google.com; s=arc-20160816; b=ifOi0Se/uPUpdxUBAjQ8LoGw51nvYDqQjpq3DZizZ45QntWH1V8wvqZJjq5C3H22A9 FPHVsi5OVurKwizGui2fG52/AKW/90Qn661rbe1xiwqZclzSCG4Zt0+Hsvcjg/SJ6Mkm JOYnwaGX2wtdjiWjNAxcBSvW9h0lxlDoEGyuqnkr/KnlZ1avw/vEiuAZv1dd/zuaLAk1 U6NTegPZy8Wa7xNo5L4x89eXIZ32JP13SK/FrBRUjCz15fCDNCKHOOJ2/U0Dpv2cBp75 wZ4vQEKSznXdLRWSJ47n2QiiyueDO+fEuQFJa1WdndI3mMfEOJFbLaZBYaFfxTpw/P++ hDWw== 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=GxjFcSckB7aY/pJA5gU1hHAN6oGZyxxfZeQnkZnoWxk=; b=LXXpVOux50rrF2UF9+Q9y+3fA82C3I3o07V+CZBurdODbyPvpFOAAK5H1pomrM79iL etPr4LTNvysornSAQHdSl+TG4PrtLpKZ2NAWEG4lffSGbOCoLb1pwpT2P1UHxe+ZSR3A KV4dXPOmacJlJrp750g2mKifdwzIGPtpLAm6qaN3ZqTxtz5MM6qsXuaB9Pl3WvZ+eLjy Gf0LZzVezaa4KgKot0cvbCidLmJKndu9DNL0L+TvzsghbPsxTrZ9ztfW1WiTQQAHC3ym slDbKh5p5/LLrrTFegbMeqxlTdh1BX+1bfFR8X7CwRvehxunejwxt9/NCidWLPHWBhCy GNOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JZ4veK4E; 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 r12-20020a170902c60c00b001b51c68c828si2726654plr.211.2023.06.16.05.03.37; Fri, 16 Jun 2023 05:03:49 -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=JZ4veK4E; 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 S234801AbjFPLxD (ORCPT + 99 others); Fri, 16 Jun 2023 07:53:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344397AbjFPLxB (ORCPT ); Fri, 16 Jun 2023 07:53:01 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2C55191; Fri, 16 Jun 2023 04:52:59 -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 8799763810; Fri, 16 Jun 2023 11:52:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 538D6C433C9; Fri, 16 Jun 2023 11:52:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686916378; bh=vLi/Ctgz4882UqtH6fdv5YzHK0VG2XkpSMNA82BO34A=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=JZ4veK4EM7+Drhrqe3EyyEUcnY6OgSUIEC7RF1MHwJu+WzBt9DEbjvnkfxJe79VN+ Ou6mweWotByj1Kulm6TEnmAvJkLNzSFElkCx0xCySJShFtFaejz95r8dXwVj6X7HiR lFvLJx1TsvYupHgIbqKsaj051h8g8zA7tzAowgCc/jLmFTHNXzwG3d6dfXAuWMo4bV ipYTECvuzi4e2N/EOKcQkF4BAC1WROnIVxG7p/1zfmOzXQZl7McORump73TNOxkpk6 CYGRPzKA5CBgUKflc2qZm4tOrw0xyr5owilv4yiWPgMMdpj+RNMEeGdhGPTCituBpT JtaEAN/3B8l2w== Message-ID: <5b0eaf1d-60b1-532e-7d12-c67810541902@kernel.org> Date: Fri, 16 Jun 2023 20:52:55 +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 v3] block: add capacity validation in bdev_add_partition() Content-Language: en-US To: "min.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: <20230616171913.13045-1-min15.li@samsung.com> From: Damien Le Moal Organization: Western Digital Research In-Reply-To: <20230616171913.13045-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, URIBL_BLOCKED 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/17/23 02:19, min.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: min.li I am guessing this should be: Signed-off-by: Min Li No ? The signed-off-by tag, and any other tag, must have your full name correctly written. > Reviewed-by: Christoph Hellwig > > --- > Changes from v1: > > - Check for overflows of the start + length value. > - Place the capacity check at the beginning of the function. > > Changes from v2: > > - Place the assignment on the first line and merge the two lines into one. > - Modify the singed name. > --- > block/partitions/core.c | 11 +++++++++++ > 1 file changed, 11 insertions(+) > > diff --git a/block/partitions/core.c b/block/partitions/core.c > index 49e0496ff23c..b511f88bf558 100644 > --- a/block/partitions/core.c > +++ b/block/partitions/core.c > @@ -436,10 +436,21 @@ static bool partition_overlaps(struct gendisk *disk, sector_t start, > int bdev_add_partition(struct gendisk *disk, int partno, sector_t start, > sector_t length) > { > + sector_t capacity = get_capacity(disk), end; > struct block_device *part; > int ret; > > mutex_lock(&disk->open_mutex); > + if (check_add_overflow(start, length, &end)) { > + ret = -EINVAL; > + goto out; > + } > + > + if (start >= capacity || end > capacity) { > + ret = -EINVAL; > + goto out; > + } > + > if (!disk_live(disk)) { > ret = -ENXIO; > goto out; -- Damien Le Moal Western Digital Research