From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F946C77B7E for ; Thu, 25 May 2023 08:55:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240469AbjEYIzg (ORCPT ); Thu, 25 May 2023 04:55:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240294AbjEYIze (ORCPT ); Thu, 25 May 2023 04:55:34 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 550FB1B0; Thu, 25 May 2023 01:55:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=K9sG0POcwk6ioMsTPXOQV3eSTLgEBbB2sxvA5LCbWcQ=; b=fdt7VIxbv3TkQRWM91jZwpprV9 ZJ6UeaeNYURZHcPVWl9lz509obvVWnmwXb94DjsnzdOTi1W5NRxUZgm2G3iLTvanTBrrRKA2uUBmW R6Le1Lg0MiA0ZT1X3YX7aEMYsV8Hmk91GojRCW2d3WSGcp15cT8xeI+PBwhD71nTJXrz8Yl75BfiX wDqDKKIlWysLrK0rRjcX0ZddExqgE/5YrnkwxWDzH2gxFiPnx8D0zSdtvNZk/rBZJ+Q+00ABKMECF gp4O0zcjlabod1RTaTrITZTNx6itpSK+cG5turE8dUFqrt8KB4fkxbhUY1mYJ1gyVxHcskP5cHHud qsE4p1SA==; Received: from hch by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1q26kq-00G3tZ-2y; Thu, 25 May 2023 08:55:28 +0000 Date: Thu, 25 May 2023 01:55:28 -0700 From: Christoph Hellwig To: Zhong Jinghua Cc: axboe@kernel.dk, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, zhongjinghua@huawei.com, yi.zhang@huawei.com, yukuai3@huawei.com, chengzhihao1@huawei.com, yangerkun@huawei.com Subject: Re: [PATCH -next] block: Fix the partition start may overflow in add_partition() Message-ID: References: <20230522070615.1485014-1-zhongjinghua@huaweicloud.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230522070615.1485014-1-zhongjinghua@huaweicloud.com> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 22, 2023 at 03:06:15PM +0800, Zhong Jinghua wrote: > + if (p.start < 0 || p.length <= 0 || p.start + p.length < 0) > + return -EINVAL; > + > start = p.start >> SECTOR_SHIFT; > length = p.length >> SECTOR_SHIFT; > > + /* length may be equal to 0 after right shift */ > + if (!length || start + length > get_capacity(bdev->bd_disk)) > + return -EINVAL; While we're at it, shouldn't these be switched to use check_add_overflow?