Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp4461266rwb; Tue, 6 Sep 2022 07:53:10 -0700 (PDT) X-Google-Smtp-Source: AA6agR7DSSnyxDpVO45b8tOHBlBpKjzzBHSgWbqMt8jz0rLBAz6WAwilfv4YjWdXEKVwtin+BPls X-Received: by 2002:a65:464a:0:b0:434:883:ea21 with SMTP id k10-20020a65464a000000b004340883ea21mr15266987pgr.152.1662475990421; Tue, 06 Sep 2022 07:53:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662475990; cv=none; d=google.com; s=arc-20160816; b=cWT6qnYVsW3Xcw0UJedT1F1AFwE+YiOHdBKSJCWI5130SsstJRCjNWNViHnNVRGJAf 7oHb+q6+in8VLZOXiitrpNjqwezOikgImrWkw1j5kpgSKY6guNrAWE/Y9BSrwNJ4HJuv nhQUi5z0YUj/P9D4M5O69BM/QTFHTsHtRC1AKCVo6C4VgF7CnhKn9shOcFzLtZ2NXlh3 cPHppFYVRZJS37tSGN118C9BfXTHjtiojaZJ0MapT/Yfh9WI1vrFaCrvckkSuJg/daB1 kmXShgxkPKi7Na+p0L1LXEy8pFe2bzVO7xGJQrRmh/fBReKgdopxb+mSqS5sXlH28kzt klTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zFO3xzdUUlNe8NLnPdT8onGLBC0BNKMWBfLYPOxO8m8=; b=UIKMKBDXoio1fotQH4sjyqFY3fy82v8HjSdaOhMQfHvD1TpuYjVLXWS7UmOJ4OYdYw oJxC6rYWc1XCdjYkRQSe3ckGLb5oRFtrL94u2vgbHRkE0EfUuqvfNET7E9kBIOhIB9C+ GguoTA2tWG90V6Bwv/seFOpcgo96T//Sez4y+4/zhpweZi92GL17I50aDedoEpF/6f7b DeKoqCYhGEMxytjku/F7+SVF6Kju4iy6aGR2qA0OBc0WEW6yhh334C/g2HSLDjp5R358 lNLtWtrTM5WaRy+t3g+jolNNoKKVQsX0NFG4eLs8TIs8NBMgBT6WrWpa++DBdJidaCDN V9Xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wIhvoYdL; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k10-20020a170902d58a00b00176afa8c818si5676157plh.470.2022.09.06.07.52.44; Tue, 06 Sep 2022 07:53:10 -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=@linuxfoundation.org header.s=korg header.b=wIhvoYdL; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241681AbiIFOPW (ORCPT + 99 others); Tue, 6 Sep 2022 10:15:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241603AbiIFONm (ORCPT ); Tue, 6 Sep 2022 10:13:42 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B902895D2; Tue, 6 Sep 2022 06:48:07 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0E5A56155D; Tue, 6 Sep 2022 13:46:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1C505C433C1; Tue, 6 Sep 2022 13:46:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662471985; bh=7Aj7WqsskOHDKxv5qNBbwA7CeSequTiwdt1G4MffOfM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wIhvoYdL7DYAbQeZWl/tNFf0Ddg+31xWGuztco+btnURaRUHN69RIz09VFbFyrcV0 CzJjQ+P4GiU4gq+78ilBJ/I9wbdQSL3u6ePVs+EO/AY8+vxjSc+f6jYZCJnLJpwu6l Y+DP5WGbQz7T4zYSbn9MJp/bT1w53HBa2v35oIf0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Juergen Gross , Sasha Levin Subject: [PATCH 5.19 100/155] xen/grants: prevent integer overflow in gnttab_dma_alloc_pages() Date: Tue, 6 Sep 2022 15:30:48 +0200 Message-Id: <20220906132833.693665030@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220906132829.417117002@linuxfoundation.org> References: <20220906132829.417117002@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 From: Dan Carpenter [ Upstream commit e9ea0b30ada008f4e65933f449db6894832cb242 ] The change from kcalloc() to kvmalloc() means that arg->nr_pages might now be large enough that the "args->nr_pages << PAGE_SHIFT" can result in an integer overflow. Fixes: b3f7931f5c61 ("xen/gntdev: switch from kcalloc() to kvcalloc()") Signed-off-by: Dan Carpenter Reviewed-by: Juergen Gross Link: https://lore.kernel.org/r/YxDROJqu/RPvR0bi@kili Signed-off-by: Juergen Gross Signed-off-by: Sasha Levin --- drivers/xen/grant-table.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c index 738029de3c672..e1ec725c2819d 100644 --- a/drivers/xen/grant-table.c +++ b/drivers/xen/grant-table.c @@ -1047,6 +1047,9 @@ int gnttab_dma_alloc_pages(struct gnttab_dma_alloc_args *args) size_t size; int i, ret; + if (args->nr_pages < 0 || args->nr_pages > (INT_MAX >> PAGE_SHIFT)) + return -ENOMEM; + size = args->nr_pages << PAGE_SHIFT; if (args->coherent) args->vaddr = dma_alloc_coherent(args->dev, size, -- 2.35.1