Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2350516rwd; Fri, 16 Jun 2023 02:45:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7k2q3MZ2IXK0MoEfVrXFEum5pXkpNP3BWwpHBRgqyiEZq8EqbS1484U010qTXAE+ZNLGi7 X-Received: by 2002:a05:6359:21c:b0:123:46bf:718e with SMTP id ej28-20020a056359021c00b0012346bf718emr1109557rwb.1.1686908721721; Fri, 16 Jun 2023 02:45:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686908721; cv=none; d=google.com; s=arc-20160816; b=IJwsuz+NHWXRmlbB1ncVNPK9bmd3OSbd4VbH8yyVwXVxvplhVEcptDzMI9DD9wqx32 OY20M6BMukMBHCv1SZs9OjcL7eGQxcvGFZtj2kv8D7ahIU0Kqwx8O7ouasSV/JJu9qrg jRoDH6ZhEwfoFPjZg84OINoB2dZWdEgHp5klUL+PZi3PbmDCgsSh/pUBw7CMYNeWvkiy LmJZw7OSfuQg3PL0S6b4AlrEoPm8B8Q3kvuWH+ilbqx4rCDJnuo4axntX0UF6wGe1k3o 2kuqz6bxsM80s5wedT6XlCXi8V/QltPSJ6/fJtdt3DErYGKN6KOnaBPUX6tNmfS5QY9c I0Tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:dlp-filter:cms-type :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature:dkim-filter; bh=oWIj79E/6JkqBTQXFwgb0y29I1jook9TSDLjz17j/Ro=; b=DUhqdU+KnRDwqmglZcIqj15yIHIuGAui+15mrV2J2b0kIYzZjQPk6B64lcWJCDdxwj 8lYQ8ogOwthDJ8Il/Y78wNPexWDZkGDVvEsmUv/vU4bB8KAX2CXgzSShiEaQ0zD5L61M Lsv65mNNzUv2nYiVlC2+xPmTxhFYZg7ovcefWDD/s9sQqwm1FIA0O0RYckM0gkBeZLMB /mgz1jBqaicIRgmPz6MjGhmswwUqWG3Ez20Md7RrfdtBd6WTTDdgs5vRa/6pnl6F40/Q 8R2R4UXe3pw2YXNKmMiQW3phzd14JaB0HAb0TIhY8DDGfewRKHIANBOYimZnwND60N3e OrqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=VKb4aXSV; 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=samsung.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g9-20020a633749000000b005344b60f7ddsi14101709pgn.117.2023.06.16.02.45.07; Fri, 16 Jun 2023 02:45:21 -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=@samsung.com header.s=mail20170921 header.b=VKb4aXSV; 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=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234250AbjFPJnx (ORCPT + 99 others); Fri, 16 Jun 2023 05:43:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344275AbjFPJnR (ORCPT ); Fri, 16 Jun 2023 05:43:17 -0400 Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A7D23A8C for ; Fri, 16 Jun 2023 02:42:53 -0700 (PDT) Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20230616094228epoutp02f7f00e7a32764bc4813cddf0d00b5658~pGmMhG8Lr0507605076epoutp02R for ; Fri, 16 Jun 2023 09:42:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20230616094228epoutp02f7f00e7a32764bc4813cddf0d00b5658~pGmMhG8Lr0507605076epoutp02R DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1686908548; bh=oWIj79E/6JkqBTQXFwgb0y29I1jook9TSDLjz17j/Ro=; h=From:To:Cc:Subject:Date:References:From; b=VKb4aXSVZc9k3hJBzqeYBeG7+XKOFSN5N/eVoqfediswF8ecOHmqax5OJ5nOeGWms JdCzREtPdGaQFnlfOip+6iS4u3BFt4xY1UBEq44yqypQ9PGi6sb9FiR2OSZ/1AUGVd 0+UA+M7xlvCS2/a0bXeL24H9Xl3cksCaqGMOzo9o= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas5p1.samsung.com (KnoxPortal) with ESMTP id 20230616094227epcas5p1217672b323c59851039ba2dfe2d8f871~pGmL4qk_91222412224epcas5p10; Fri, 16 Jun 2023 09:42:27 +0000 (GMT) Received: from epsmges5p2new.samsung.com (unknown [182.195.38.177]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4QjDhy06FCz4x9Q1; Fri, 16 Jun 2023 09:42:26 +0000 (GMT) Received: from epcas5p1.samsung.com ( [182.195.41.39]) by epsmges5p2new.samsung.com (Symantec Messaging Gateway) with SMTP id BB.6B.44881.18E2C846; Fri, 16 Jun 2023 18:42:25 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPA id 20230616092054epcas5p340e977377808d2df7210dc4a7d6c1d8e~pGTW82UBX1047010470epcas5p3F; Fri, 16 Jun 2023 09:20:54 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20230616092054epsmtrp26644f7cb738c71b1ed4143127792c838~pGTW79WFv2884728847epsmtrp25; Fri, 16 Jun 2023 09:20:54 +0000 (GMT) X-AuditID: b6c32a4a-c47ff7000001af51-3c-648c2e8129e4 Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 44.DF.27706.5792C846; Fri, 16 Jun 2023 18:20:53 +0900 (KST) Received: from ubuntu.. (unknown [109.105.118.54]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20230616092052epsmtip1d15b5cc6acbbdd82906312bf2bf4a6d1~pGTVi4F7l2879828798epsmtip1k; Fri, 16 Jun 2023 09:20:52 +0000 (GMT) From: "min.li" To: axboe@kernel.dk, willy@infradead.org, hch@lst.de, dlemoal@kernel.org, gregkh@linuxfoundation.org, wsa@kernel.org, vkoul@kernel.org Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, "min.li" Subject: [PATCH v3] block: add capacity validation in bdev_add_partition() Date: Fri, 16 Jun 2023 17:19:13 +0000 Message-Id: <20230616171913.13045-1-min15.li@samsung.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrBJsWRmVeSWpSXmKPExsWy7bCmum6jXk+KwcdXphar7/azWTzYb2/R vHg9m8WN4++YLea+vsRisXL1USaLvbe0LS7vmsNmsXxVB5PF2QkfWC123jnBbPH7B1Ds7v65 jBY31l1lceDz2LxCy+Py2VKPTas62Tz2z13D7rH7ZgObR9+WVYwenzfJBbBHZdtkpCampBYp pOYl56dk5qXbKnkHxzvHm5oZGOoaWlqYKynkJeam2iq5+AToumXmAN2rpFCWmFMKFApILC5W 0rezKcovLUlVyMgvLrFVSi1IySkwKdArTswtLs1L18tLLbEyNDAwMgUqTMjOaOycwFhwibvi wOyNzA2Mazi7GDk5JARMJLbcvczYxcjFISSwm1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rosb666yOPB5bF6h5XH5bKnHplWdbB77565h99h9s4HNo2/LKkaPz5vkAtijuGxSUnMyy1KL 9O0SuDIaOycwFlzirjgweyNzA+Mazi5GDg4JAROJp9uKuhi5OIQEdjNKrPjzkrmLkRMoLiFx ft4vNghbWGLlv+fsILaQwFNGiS2LxEBsNgFVielPZzCDNIsITGKUuH/hNSvIUGaBJIn+mdYg prCAl8TJVlOQchag8t89K1lAbF4BS4m3Vw9BrZKX2H/wLDNEXFDi5MwnYDXMQPHmrbOZJzDy zUKSmoUktYCRaRWjZGpBcW56brFhgWFearlecWJucWleul5yfu4mRnDIa2nuYNy+6oPeIUYm DsZDjBIczEoivMtOdKUI8aYkVlalFuXHF5XmpBYfYpTmYFES573QdTJeSCA9sSQ1OzW1ILUI JsvEwSnVwHQm8tXP0L4bphNmJ7UF3pySovPcbWfVZy+XH4yp87xDbv+8mtm1sOXVwxUv8qd9 Co26mNx3X3vy+/Ifon7s5UJzr69f923f3enu+ZO3BqdlGDzl7BcILu778/DEKVFNq78LueYu PDNLkTOr6xi7/qJWb/8NW9+XV8w/finGwuBD7EF513T5Z3cOe/jasHvFbUnumzxxb8Gj6pX7 3kRembftW+fx043CHTc23vz32G75Ok0rj3MHC6etTohlWnVwq7vTg/574q+C/2t7pgetNLoS Wvsl4WKop9DkgJVLldcsX3Nu9TaRZ9NTLyz58/JWm8KL2VlXi3YLS2vNlhc74N8WMZszjk3G awG7zIJL6skHlViKMxINtZiLihMB9JJBaOgCAAA= X-CMS-MailID: 20230616092054epcas5p340e977377808d2df7210dc4a7d6c1d8e X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20230616092054epcas5p340e977377808d2df7210dc4a7d6c1d8e References: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DATE_IN_FUTURE_06_12, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=unavailable 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 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 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; -- 2.34.1