Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp4466550rwb; Tue, 6 Sep 2022 07:58:20 -0700 (PDT) X-Google-Smtp-Source: AA6agR4Kt4Pp3Bv7xc66KqUU4PMWCcMVpht0N/icxtzGnmcDIxaccZ43EZ1gZEi9yVjU3cbYxrab X-Received: by 2002:a17:90a:588c:b0:1fd:a1bc:ff71 with SMTP id j12-20020a17090a588c00b001fda1bcff71mr24990950pji.134.1662476300673; Tue, 06 Sep 2022 07:58:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662476300; cv=none; d=google.com; s=arc-20160816; b=SK/Y6uIl7zmqQvsJQE1+cRAqA7uvpfnm1mEvvMfYBe/ElNMwxT45s7WTgIG9FSSDy2 4kAQfj6GACV5AHrWzgPIQla8MYuI8zKdw4YjTffQZFGBplpVZQQwx1Zr8PgQM/pQTSkB etM2E0qUi7Btv2ugb14hS55FFJoJRNopo9cKmxnSb+Kq3apWzpigijYfhE00d1lZDVo0 iUnncnGzd+Kf1IrDoKiJPR7cI6NVJC4RCecxrfxMeVp0GMZRKK1Qv4T0ur7xf1u076cr tCgozlBGdYQX3Ed8E4vv2IrEoe3D5pL7JzgeBG8M9+z2978ZH2gk/Z27Kix1a1EgW5vP pieg== 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=TzNrMr5BKizYz5juQeoahHymvyvSadgriWmqOCmhxeM=; b=nxi+ayd4MONKByRAMihNelmO3g37Le/EWFljjRzAfIYsgF5TFg+56/AqT9vTCw0aMX IIpS+NlpFl2NYYi/F92K8/PpFGe8jetzwD6aPNfOt6Q6owvITcD3t5mYES8QKYiw6xSN Hbnm58Ewhx5JLTG/3Doj55EDEG3RGMb6XRV5sguXpzVkP1ct3pPRHRNC1FpeIKbEYnpN 0wxoEnQIfEF6h9RLFPDBVXU0iEi+6+njmt5UrS0o42mqTgp2Hlqt5HARjyB5smxzd4xz kD/+bbxRQO4vm7lNuplXu4B7QqSmzHZciewpqglIxm4XqzMDZPW8Hqg/JTQVff7ghJCl ssFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GGWvMZIY; 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 e2-20020a17090301c200b00176e16b0c58si160124plh.21.2022.09.06.07.58.09; Tue, 06 Sep 2022 07:58:20 -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=GGWvMZIY; 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 S240801AbiIFNg6 (ORCPT + 99 others); Tue, 6 Sep 2022 09:36:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240710AbiIFNfp (ORCPT ); Tue, 6 Sep 2022 09:35:45 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BF867AC1F; Tue, 6 Sep 2022 06:34: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 ams.source.kernel.org (Postfix) with ESMTPS id 13E84B81633; Tue, 6 Sep 2022 13:34:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B9CBC433C1; Tue, 6 Sep 2022 13:34:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662471243; bh=AH3bor9FHUfTQvRdH/pgLK4+Owq/zkRLMns2Qt34c4c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GGWvMZIYqn4kVAOvaW31njozev9pGXtNwpNhsL60ohy6UWNUdBOgJ8hdQc53MJVQR 4hkvvZOJVp8d17wn2+8tYN90bn68Wr23k0E8TlkYWJ9dTZ0na21K7+JBmzZ4D0Koa6 vAa1HdbD3mx/qnltY3R92NlsIM4bv/029NyBhtOM= 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.10 45/80] xen/grants: prevent integer overflow in gnttab_dma_alloc_pages() Date: Tue, 6 Sep 2022 15:30:42 +0200 Message-Id: <20220906132818.881170499@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220906132816.936069583@linuxfoundation.org> References: <20220906132816.936069583@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 5c83d41766c85..0a2d24d6ac6f7 100644 --- a/drivers/xen/grant-table.c +++ b/drivers/xen/grant-table.c @@ -981,6 +981,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