Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp18916665rwd; Wed, 28 Jun 2023 02:26:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5qfSFSFzptAhX/cwR11UgIR8ctumXjJBuNbDleaPoUZQYaGytV8ZHgv/uj2EEmxTHHL3qx X-Received: by 2002:a17:907:72c7:b0:98c:e72c:6b83 with SMTP id du7-20020a17090772c700b0098ce72c6b83mr16694228ejc.45.1687944382580; Wed, 28 Jun 2023 02:26:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687944382; cv=none; d=google.com; s=arc-20160816; b=OZrWTWOvlwk2/fw6qVd6RLMuMhZ7MT13LNPSZKN0xUNitY4aF85a9z58hd/z/ZKghu oCqMdANA2Hb/ZL7kqXRrEEiILXM7aLUqZkYj2KAM6WlZnGul4r4WagW3oqtZKcdIdBLI r8Z197h32lyX6DbVEUOx01a0spa2QNwv6N5xhNaLabHXuTYSP/L7aUHC19zzy9BsK7rg ww5u01fdOfRa2AOcD8AuxVbrZoI+2UVHluuOUOzOILp7lKUbpPWnBrEmJVoRtT61waSE Oh5BQI7vTKZlclSmm4OMhSVniB+dpqgN3jq1gheP84NrP2SwV0WIlJPheM/yYdtzjCHy aB4A== 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=1J0GA8jA4OUCQy/o7Wr1UV/l6aUJqp3vp4GqzSVMq34=; fh=PokdsqQFzAaWg0grpm5U1gnjTMXDhYkpuT7XtozmYRc=; b=IVSyGnzPYHy4zC8IXMd34U3lH4s7MuPJIvLYJAnE9JiFwriID7yAgudT3fWJA4CcmC uUjQ4sA0wbu2os6qFBDTYxI0jwil9VTwsOXkov44LVetQWf2/YqVNbvxZ9O/brEzzIsj n6XROwWZ4FAY3gHKwbRbfNG02z3ItcUVr2Voe/2MGdREHtwK/va5qSU4SUKXy5qBLXHR CRAbItOR0fBypJD131IoD1VC3/EAFY12V20bSEugSfa69QAU0RZDrlRKywrszT6QSVWA k6zuuJPD1qPZCHBMLSa5XJ90tQWzL8sXhCW9rrl/+hpmGrgJVFj8Wffv3QrpJLwC8Gzr xhZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=gHWPpnzd; 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 a2-20020a1709065f8200b009888c105293si4765073eju.562.2023.06.28.02.25.57; Wed, 28 Jun 2023 02:26:22 -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=gHWPpnzd; 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 S235119AbjF1I4a (ORCPT + 99 others); Wed, 28 Jun 2023 04:56:30 -0400 Received: from mailout4.samsung.com ([203.254.224.34]:21520 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233724AbjF1Icd (ORCPT ); Wed, 28 Jun 2023 04:32:33 -0400 Received: from epcas5p1.samsung.com (unknown [182.195.41.39]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20230628060406epoutp046f0a12486222ea8b734c4ca949fbf8b9~svW94rc2j2153821538epoutp04g for ; Wed, 28 Jun 2023 06:04:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20230628060406epoutp046f0a12486222ea8b734c4ca949fbf8b9~svW94rc2j2153821538epoutp04g DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1687932246; bh=1J0GA8jA4OUCQy/o7Wr1UV/l6aUJqp3vp4GqzSVMq34=; h=From:To:Cc:Subject:Date:References:From; b=gHWPpnzdNaowUfBnb8O12Ax06bsrdSv5UTqpOu/v2/Eipj3ml94JDfujC7cyMrDsH QWU1OY1rDWBwDxMFGP3578ovVOn6E0FIHhzSSTODN3+P2+nBIrgIkmMzuX8hWC+54B m2TBewcIXGc5mKgqZkPmP0UrM6viTufHceFwgTQw= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas5p1.samsung.com (KnoxPortal) with ESMTP id 20230628060406epcas5p1b07b2ffdedda603499d565a0c801a436~svW9hDb5i0452904529epcas5p1Q; Wed, 28 Jun 2023 06:04:06 +0000 (GMT) Received: from epsmges5p3new.samsung.com (unknown [182.195.38.174]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4QrWHS5QZBz4x9Q0; Wed, 28 Jun 2023 06:04:04 +0000 (GMT) Received: from epcas5p1.samsung.com ( [182.195.41.39]) by epsmges5p3new.samsung.com (Symantec Messaging Gateway) with SMTP id 93.51.06099.45DCB946; Wed, 28 Jun 2023 15:04:04 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPA id 20230628051122epcas5p45d70f2c36ce91b60863f702de1534321~suo63XkqC1272712727epcas5p4X; Wed, 28 Jun 2023 05:11:22 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20230628051122epsmtrp104a14031214eb43558622326ce5397d0~suo62c5y60727707277epsmtrp1R; Wed, 28 Jun 2023 05:11:22 +0000 (GMT) X-AuditID: b6c32a4b-cafff700000017d3-e4-649bcd5436b4 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 6A.AE.34491.AF0CB946; Wed, 28 Jun 2023 14:11:22 +0900 (KST) Received: from ubuntu.. (unknown [109.105.118.54]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20230628051120epsmtip2557b4491a4e53bf72b782da715fa63f3~suo5chpNN2817628176epsmtip2r; Wed, 28 Jun 2023 05:11:20 +0000 (GMT) From: Min Li To: axboe@kernel.dk, willy@infradead.org, hch@lst.de, dlemoal@kernel.org, gregkh@linuxfoundation.org Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, stable@kernel.org, Min Li Subject: [PATCH v3] block: add check that partition length needs to be aligned with block size Date: Wed, 28 Jun 2023 13:09:41 +0000 Message-Id: <20230628130941.10690-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+NgFlrMJsWRmVeSWpSXmKPExsWy7bCmum7I2dkpBhc3qVmsvtvPZvFgv71F 8+L1bBY3jr9jtpj7+hKLxcrVR5ks9t7Stri8aw6bxfJVHUwWZyd8YLX4dP4Cm8XvH0CxG+uu sjjwemxeoeVx+Wypx6ZVnWwe++euYffYfbOBzaNvyypGj8+b5ALYo7JtMlITU1KLFFLzkvNT MvPSbZW8g+Od403NDAx1DS0tzJUU8hJzU22VXHwCdN0yc4BOVVIoS8wpBQoFJBYXK+nb2RTl l5akKmTkF5fYKqUWpOQUmBToFSfmFpfmpevlpZZYGRoYGJkCFSZkZ2y+MY2x4KxgxZ89m9gb GGfwdTFyckgImEgcODOfrYuRi0NIYDejxOU/a1hBEkICnxglug+KQyS+MUosfHmUHabj7LbV jBBFexkltl43gyh6ziixZMZloAQHB5uAssS2pT4gNSICaRJLO36ygdjMAoUSP751MIPYwgIJ EvNfb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Q0hgN6PEtK5djBAJCYnz836xQdjC Eiv/PWeHKHrKKNF8+D6Qw8HBJqAssW2pD4gpIpAjseK7P0g5s0CpxNbbTewgtrBAHFB4KguI zSKgKtF5rpMVxOYVsJRYu/MoM8R4eYn9B88yQ8QFJU7OfMICMUdeonnrbOYJjHyzkKRmIUkt YGRaxSiZWlCcm55bbFhgmJdarlecmFtcmpeul5yfu4kRHOpamjsYt6/6oHeIkYmD8RCjBAez kgiv2I/pKUK8KYmVValF+fFFpTmpxYcYpTlYlMR5xV/0pggJpCeWpGanphakFsFkmTg4pRqY cl3/3Zhi0nH7hdtxju23HwkdeJ4Ua/ttyrTMnNbny9imbr8nIyP7ZvF2yYlppnemV85TDeOU kNgUs/XX67WBfVn2HDMk95/Z1GpyRVXmDuPFQLkgnXU3gj8vC/56+inXfv3j2/rvXJiZs1FX acM02zO/s+wS/GZdlM60NhGvXcD/t7NbZHaGSOcnm1llYqybnFU3n8jl7473OuCjnv/1ettx Xvu2vcoWXNIpQZmfF+y4/nR2wH61jlUNhp0/yqqX2q1nEQ1ZfXlX1w/esNVNfMvW9hqZCYRe 3d599T+/jrGHip3I/7zjx2qNzHITn109dn7itBJF189me7e8flV9okVT8E/kwn2vTZ8+9Ptg rcRSnJFoqMVcVJwIAFGzsWPkAgAA X-CMS-MailID: 20230628051122epcas5p45d70f2c36ce91b60863f702de1534321 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: 20230628051122epcas5p45d70f2c36ce91b60863f702de1534321 References: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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. Changes from v2: - Add the assignment on the first line and merge the two lines into one. - Use IS_ALIGNED function to check alignment. --- block/ioctl.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/block/ioctl.c b/block/ioctl.c index 3be11941fb2d..1a351132bf4e 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -16,9 +16,9 @@ static int blkpg_do_ioctl(struct block_device *bdev, struct blkpg_partition __user *upart, int op) { + long long blksz = bdev_logical_block_size(bdev), start, length; struct gendisk *disk = bdev->bd_disk; struct blkpg_partition p; - long long start, length; if (!capable(CAP_SYS_ADMIN)) return -EACCES; @@ -33,14 +33,15 @@ static int blkpg_do_ioctl(struct block_device *bdev, if (op == BLKPG_DEL_PARTITION) return bdev_del_partition(disk, p.pno); + /* Check that the partition is aligned to the block size */ + if (!IS_ALIGNED(p.start | p.length, blksz)) + return -EINVAL; + 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); -- 2.34.1