Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp200457rwb; Mon, 28 Nov 2022 19:17:53 -0800 (PST) X-Google-Smtp-Source: AA0mqf5Y1ZG5FfWeLx4JSL5QoiHGm5YnZsjzeGfK1mdUDWbqiDnrtrj/SRFbJ0ifc7QvpCjAa9Mf X-Received: by 2002:a17:90b:3d90:b0:212:de1c:a007 with SMTP id pq16-20020a17090b3d9000b00212de1ca007mr65446825pjb.30.1669691871934; Mon, 28 Nov 2022 19:17:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669691871; cv=none; d=google.com; s=arc-20160816; b=LTCf3Hr2A2YIiaV4DkoI0xe8EDQ7Ci1lhrGgbmAmRLGzRTDMCeYluHCLEX863snDaL oU3aQj1GV2ElF7QtnZ13lI7Ff05Y/TTQmoML6X0VTjbiqEW56Vct+E28TVMcUlGfUhzS Xs/rOA7yUmMAlWdIynu9BIljUffffo1eTkv+Jl31gyV8AVcSDAAJ2fuLI61AdwU64PzT hWDSVXSG+BxZOSU2PTDZCo6ut51M9vSJmbewhdxsSJSy1tqtFWRya4RTy5CWhV+kvgxQ SJ4anZCXHJAjBUCRVWyEI7czYGH5koLITt7WmXQbK58+dSPMG7ZzuEJMDjK5TMBi9/up rizQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=jICdvc9DXcnwskTHg4NcjxqsN06Ny3H6HZZrLEpXAiY=; b=RmQe4KIpkVktm0UndUGoMMarEe2JXYVix7/LhLD+PlXK5K1yMHpTVVxu7KEKL4zYW8 kLjxjmTkS4J0Y5HBjbrYRy6VhxPVSaBloL3G1DlV5xgwgKT70NlVqcvYYxede1P3c57H i5PJilY57MFyJHYg3RdeIxJalJvpIu7Wvn2TUNIKRV9pRZISAALL1Ve8vy6F8EYBzmig vDXSROxI+mf9XdOjH3BJfs90o9AI8kWKJA2wsx2M6p4t32qgVQBtgMVFkzYMw4sm+Rel cX1hOVoOXJGLrpjusg41668S3Oz6/ga26TZ2QqXEXIGLPHw5MRu9rSx6fcEodBlEyBoJ bphw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="d/yYDA1S"; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c20-20020a6566d4000000b00478446557bdsi126721pgw.18.2022.11.28.19.17.16; Mon, 28 Nov 2022 19:17:51 -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=pass header.i=@redhat.com header.s=mimecast20190719 header.b="d/yYDA1S"; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235282AbiK2DAw (ORCPT + 82 others); Mon, 28 Nov 2022 22:00:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235205AbiK2DAs (ORCPT ); Mon, 28 Nov 2022 22:00:48 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5402F303F3 for ; Mon, 28 Nov 2022 18:59:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669690794; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=jICdvc9DXcnwskTHg4NcjxqsN06Ny3H6HZZrLEpXAiY=; b=d/yYDA1SiXj+lPrk3ZeeLFRhPtfta20OvzOVTlLl4mTuaCd6VvGb08lN6v/p1Drb4faOmE mzxIK+mRTPOeVPI57yQTx0EstqW/TALERSdFIN7/x54qhftSWM5F8m+NPFOaXgzlv69gNY 5DHK4zB5PLy0tUiNwx/QBE1r3VoBB8o= Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-435-UaTNM98mOz-PBDxtauKvDQ-1; Mon, 28 Nov 2022 21:59:47 -0500 X-MC-Unique: UaTNM98mOz-PBDxtauKvDQ-1 Received: by mail-oi1-f200.google.com with SMTP id p133-20020acaf18b000000b0035b236c8554so4718865oih.15 for ; Mon, 28 Nov 2022 18:59:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=jICdvc9DXcnwskTHg4NcjxqsN06Ny3H6HZZrLEpXAiY=; b=CT7m40Hxpy4HxWbKhdw+iSWSYQkOZpFoOeDheVJ7EiwLkHG9nXGorpTzleTk7WdGFO Yq1RIqWkXu9/M3xfBE27icaTzqCcO72dMAOlkaEXb9aDMUMn7tfJmFVmvo7r9K7H1ZgC Qs5yJ15aZam94/A56XOjTxQ7QNtCgt2bzaacGrDOISRtPxO28BVt6cMeQ230yGFrP+b/ 7QwLfQMHWpcMi1fhdzR7CztA9K+wOTGrCne959n4/PY35J+aqhe5XqWoElj0U+lGwx3i exqrUYKOcAy9QlIrt+vhHEPevP6ygwwehVwNDm/BsGobru8QF783fBiXZzm8DQR3ffmd 9KZw== X-Gm-Message-State: ANoB5plm+YzF6rVp/XhZAYG7ON3PmmiwkkjCOmQ09tYu8XjICREMmiUi hSw/82czvDsGZZmiAM2NbtxyGncHSusPZ9OYHRiecZEJRJGerqxzq22PlomrUH0m61hNWuYNPoY ZFDkoMtYFkHmZ3FR5MAqfiIfxwnFCO9htsF48Xu9s X-Received: by 2002:aca:906:0:b0:354:68aa:9c59 with SMTP id 6-20020aca0906000000b0035468aa9c59mr28156749oij.35.1669690787154; Mon, 28 Nov 2022 18:59:47 -0800 (PST) X-Received: by 2002:aca:906:0:b0:354:68aa:9c59 with SMTP id 6-20020aca0906000000b0035468aa9c59mr28156741oij.35.1669690786942; Mon, 28 Nov 2022 18:59:46 -0800 (PST) MIME-Version: 1.0 References: <20221128155717.2579992-1-harshit.m.mogalapalli@oracle.com> In-Reply-To: <20221128155717.2579992-1-harshit.m.mogalapalli@oracle.com> From: Jason Wang Date: Tue, 29 Nov 2022 10:59:36 +0800 Message-ID: Subject: Re: [PATCH v3] vduse: Validate vq_num in vduse_validate_config() To: Harshit Mogalapalli Cc: sgarzare@redhat.com, error27@gmail.com, harshit.m.mogalapalli@gmail.com, "Michael S . Tsirkin" , Xie Yongji , Gautam Dawar , Maxime Coquelin , Parav Pandit , Eli Cohen , virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 28, 2022 at 11:57 PM Harshit Mogalapalli wrote: > > Add a limit to 'config->vq_num' which is user controlled data which > comes from an vduse_ioctl to prevent large memory allocations. > > Micheal says - This limit is somewhat arbitrary. > However, currently virtio pci and ccw are limited to a 16 bit vq number. > While MMIO isn't it is also isn't used with lots of VQs due to > current lack of support for per-vq interrupts. > Thus, the 0xffff limit on number of VQs corresponding > to a 16-bit VQ number seems sufficient for now. > > This is found using static analysis with smatch. > > Suggested-by: Michael S. Tsirkin > Signed-off-by: Harshit Mogalapalli Acked-by: Jason Wang Thanks > --- > v1->v2: Change title of the commit and description, add a limit to > vq_num. > > v2->v3: Improve commit message to include reason for setting limit to > 0xffff > > 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 >