Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp14488460rwb; Mon, 28 Nov 2022 01:23:28 -0800 (PST) X-Google-Smtp-Source: AA0mqf7kxkPrbHzzcfLx2nJh6SzB3gRDuzyB3BRXNGE1mEXE4Wzxzh7FbsDMlEBjzFzNTRK0Bz4h X-Received: by 2002:a17:907:a50c:b0:7bc:98f6:35c4 with SMTP id vr12-20020a170907a50c00b007bc98f635c4mr13336048ejc.123.1669627408686; Mon, 28 Nov 2022 01:23:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669627408; cv=none; d=google.com; s=arc-20160816; b=VACHhXd3BrN1eyrV609fnxF3+LjWze6hIWOM/sZpwJGAQJjvUEXr7+PkNZ7B8tDXWI WStzJehwkhUjMhkkYUkD8ZyUI9OYQTJzLpi2EqUpPO/v2FSD/f5UB43lCwg1Mkx7dIBN Aiogl/xycob1IkK/hApsnGeJfK4wl6hdwlY8r1gEGS3DLAhpDoW7YOQm9vZ98fq/8xOE DB+Hu1TkFZNNaLc5ETlkR1cTYiutY7Y5kkMReEjuqmDZudhNgSa4Y5YkWA4uDD/1I0qC makRrYFKLkgNvIl4gibA2zLUkNotdkOt3q7i6KDpNu3mm5EeIXq+EjQcG99latoyeu63 e59w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :message-id:date:subject:cc:from:dkim-signature; bh=BlyfctjrhD2WjrvyRQMuxTcpb5Ak/tstUQ1VYEeBsUI=; b=prK2gk9VuCmJvlMxiFYq7sWZzsM4zvh6SavDTTKCFPJDjXxraveRm5FgxFZZ0HXeqC 0ploPOpMpA/1Wq32afkRmeb27COE14XP2/oSknBtpS9mTHdRSf+A38fN0338vVFsoSG1 uyuYbeWtmVMi28OasX1GJY+UtrkC87owig3WYrugAT9HfFHp+wmHmboAj5IVBXnuO92Y BA9+A96doNpl07uOh2zXGfr4DWuMbjxcnYoG2nwE/mIH6NCYJT1i8LDf+Lswn1rXLUaP vy22mqZOKA/15Ygv6DNZoJJb3pFtGxbG8ywOGV3DIgMH6IErqy713vekX3F1oZBaodZy TNzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@oracle.com header.s=corp-2022-7-12 header.b=McNpOTcU; 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=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e11-20020a50a68b000000b00467570d605dsi8284299edc.614.2022.11.28.01.23.09; Mon, 28 Nov 2022 01:23:28 -0800 (PST) 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=fail header.i=@oracle.com header.s=corp-2022-7-12 header.b=McNpOTcU; 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=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230042AbiK1Igq (ORCPT + 83 others); Mon, 28 Nov 2022 03:36:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229670AbiK1Igo (ORCPT ); Mon, 28 Nov 2022 03:36:44 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 185796257 for ; Mon, 28 Nov 2022 00:36:42 -0800 (PST) Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2AS6aSXD005159; Mon, 28 Nov 2022 08:36:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=corp-2022-7-12; bh=BlyfctjrhD2WjrvyRQMuxTcpb5Ak/tstUQ1VYEeBsUI=; b=McNpOTcUIs/413GVUQI6h+pjzHHVX8G+HPfZUCAiVC/jzyzHVIi9FNT+a+Pc5TJ+5C+A t3wlKYIl/VE+LF0+W2lxKSYYzu0X35GiCnf0EhbiLM9W+Dtk19Gt64Yv3cP6O1JfmITq B73KgMgKeD/vpvbefv1G6XTVYJXnvjYCoj+WldLG6iSMR42SAyu76xxgJVOOzo01FOxv 6p2j7zVem3c4A0ed9zoJQKS3REbe/AfPsEku/V52MjAZIkpQnwgFf9pUscBoRbJczohO hGd//kEgow5yC7/96+BZUwjTau+mRoDDrhROhxlFzPb6AlNYuLDzl+dRhDaKJ7oCxaxz Eg== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3m3adt2mx1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 28 Nov 2022 08:36:36 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 2AS82haq022363; Mon, 28 Nov 2022 08:36:36 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3m3c1swbup-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 28 Nov 2022 08:36:36 +0000 Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 2AS8Y33l040816; Mon, 28 Nov 2022 08:36:35 GMT Received: from ca-dev112.us.oracle.com (ca-dev112.us.oracle.com [10.129.136.47]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 3m3c1swbtt-1; Mon, 28 Nov 2022 08:36:35 +0000 From: Harshit Mogalapalli Cc: harshit.m.mogalapalli@oracle.com, error27@gmail.com, harshit.m.mogalapalli@gmail.com, "Michael S . Tsirkin" , Jason Wang , Xie Yongji , Gautam Dawar , Parav Pandit , Eli Cohen , virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] vduse: Validate vq_num in vduse_validate_config() Date: Mon, 28 Nov 2022 00:36:26 -0800 Message-Id: <20221128083627.1199512-1-harshit.m.mogalapalli@oracle.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-28_07,2022-11-25_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 suspectscore=0 bulkscore=0 adultscore=0 mlxlogscore=999 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211280066 X-Proofpoint-ORIG-GUID: zvnDFjPhaAWWyzLgPXFYjnWjiTSpB54y X-Proofpoint-GUID: zvnDFjPhaAWWyzLgPXFYjnWjiTSpB54y X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a limit to 'config->vq_num' which is user controlled data which comes from an vduse_ioctl to prevent large memory allocations. This is found using static analysis with smatch. Suggested-by: Michael S. Tsirkin Signed-off-by: Harshit Mogalapalli --- v1->v2: Change title of the commit and description, add a limit to vq_num. Note: I think here 0xffff is the max size of vring = no: of vqueues. Only compile and boot tested. --- drivers/vdpa/vdpa_user/vduse_dev.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c index 35dceee3ed56..31017ebc4d7c 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -1440,6 +1440,9 @@ static bool vduse_validate_config(struct vduse_dev_config *config) if (config->config_size > PAGE_SIZE) return false; + if (config->vq_num > 0xffff) + return false; + if (!device_is_allowed(config->device_id)) return false; -- 2.38.1