From nobody Fri Sep 19 05:39:40 2025 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 A181CC4332F for ; Mon, 28 Nov 2022 08:36:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230075AbiK1Igq (ORCPT ); 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: quoted-printable 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 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 =3D 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/vd= use_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_co= nfig *config) if (config->config_size > PAGE_SIZE) return false; =20 + if (config->vq_num > 0xffff) + return false; + if (!device_is_allowed(config->device_id)) return false; =20 --=20 2.38.1