Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp745189pxu; Wed, 2 Dec 2020 02:11:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJxwg0z9yx6YZe1c5SLEARE7E5KT5UuWYe7hG6BW2C3NF/W6nv28ilw+913K/Z+Lw9PP10Hu X-Received: by 2002:aa7:d154:: with SMTP id r20mr1904210edo.258.1606903882386; Wed, 02 Dec 2020 02:11:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606903882; cv=none; d=google.com; s=arc-20160816; b=pHz8BphSbsngHwNYVPpTgxlunG3NQQEOkcBiyAnVOC5ITHpGy6iTJ0FKV7735QzeWL LkBT9jmHzIpUpFk2XfjtWw8fYrja3ekPj10v+RiCGGBTxx7IdBccSri+xfUJpDnjmnzQ ZCPM9mp6Oxi/77ZfWGVRK5mqZ6C21eOJIEYiMkEuhlFCQEx+ok4wDWdgNYDbkOB9CFTq 7XuXIoGA3YnpjWsb+qND3qCj0Q1aGt32zB3ysH317NvAJqd8tUn3cXk4D0n5scu0ASiF UB0n+JHmBO07IdkWSdwiBHxiO4p4AqiTVhdZDsaVtuL/5ti9rnx66h0G4pADP2w+W+gS KFKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=PbDDvGrK+lSE7MWXuh3UJq+otQmOFQID2RCDUTDFTBk=; b=RrYO8e4xl4pmQfZCWhc3fXvrXmtowHaHfSTe7SOgjrK5VP1eO8gCTPNYkZbVRO5oQu RuEbH3994JXaJ8xDKMFHXLvBpAlJ2KKyEZGrJ77AHcS71atBP+q65W4nB7w8JPnS3Y4n kQLrcRx6hCuk1JLkYr3JbxjCiXW+sPS4VJebsxXl/WDq61opIJ9IQmmJ8PhJuawAl1ZO l4vo0B4VU20TpD0ezTTnQvneBrWYKC3kDFyqX8ruCvaDNfBCtlUu8UNBfxfIbl8XMnju CQXpPDmmv9ZIcYGjbawVkyLHkezf1gJkj/BlHaW1vdXFiTLDeXscKoUYzWiHGEp6UlVD MgzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YcFs+XxJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a18si539135ejf.618.2020.12.02.02.10.58; Wed, 02 Dec 2020 02:11:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YcFs+XxJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1729366AbgLBKH2 (ORCPT + 99 others); Wed, 2 Dec 2020 05:07:28 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:60202 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729349AbgLBKH1 (ORCPT ); Wed, 2 Dec 2020 05:07:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606903560; 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=PbDDvGrK+lSE7MWXuh3UJq+otQmOFQID2RCDUTDFTBk=; b=YcFs+XxJzw4RaPVrIawLRY2H4Kon4SSNr/49OfC2Tnvp2SJ6hu7friqXtOL61LVMyO1bzC BEalWdmiafMeaXaAv36Z7H4Y/NCujN0ZJQTqz1LnXyZiJqnDdH4N6D+xAUdUicMHrf1wJo Z41GkcdasOZo1o1jcIHmbFDH2+Umm3E= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-549-4VKep3ZgOdevJprQeaD_1A-1; Wed, 02 Dec 2020 05:05:59 -0500 X-MC-Unique: 4VKep3ZgOdevJprQeaD_1A-1 Received: by mail-wr1-f70.google.com with SMTP id x16so2943513wrm.20 for ; Wed, 02 Dec 2020 02:05:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=PbDDvGrK+lSE7MWXuh3UJq+otQmOFQID2RCDUTDFTBk=; b=KqxQICFZJ4OFSuiJPfs7LppuF0Iw5LrpwSJIBH0RSXRv5b/BghLDwHrxZw/+YjzHx/ wohkRqUdB9ExeO4qrlFSREzujN9OUnRKUPkpSki3MAsPCQX2WCezy6u4746cQf6au3en tp0V5SzeIyIVZkZb+I+4KnZpEQzfJJR1CfUPfOv0IZRheR3mzElgdkuYREFarEb2Gmru MFgrh3SeFiF8rJ+uj9rNgQdYAf+DyhSUjSZQvTLMqqARB0dpT7G6ucE5XeiQMDRXS9mx jT19Q2Rh+k5FkgTpPukb5An3Ifiz54sFFCGYEIkupVyrAh2GO8k93ap5/Cb1fTUZYyoh RV8g== X-Gm-Message-State: AOAM532rc5mQyff1i7baxIqmK3NONwHWHOE16B5/TmSU++3xU1xhwKs2 L+ep2s/7aTccuo2Gnc2Ie7Xv7nWewpb5d9+ZMzTkVjxR2mqmLBsRMZzr7j+lDj9vRQMWt0mIVy+ naq+EfyEhS+OwwLJaeayHKVMf X-Received: by 2002:adf:a1c2:: with SMTP id v2mr2386526wrv.95.1606903554758; Wed, 02 Dec 2020 02:05:54 -0800 (PST) X-Received: by 2002:adf:a1c2:: with SMTP id v2mr2386355wrv.95.1606903553082; Wed, 02 Dec 2020 02:05:53 -0800 (PST) Received: from steredhat (host-79-17-248-175.retail.telecomitalia.it. [79.17.248.175]) by smtp.gmail.com with ESMTPSA id h2sm1443549wrv.76.2020.12.02.02.05.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2020 02:05:52 -0800 (PST) Date: Wed, 2 Dec 2020 11:05:50 +0100 From: Stefano Garzarella To: Norbert Slusarek , Jorgen Hansen , Arnd Bergmann Cc: gregkh , Arnd Bergmann , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH RESEND] misc/vmw_vmci: bail out earlier on too big queue allocation Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 1, 2020 at 9:21 PM Arnd Bergmann wrote: > > On Mon, Nov 23, 2020 at 10:01 PM Norbert Slusarek wrote: > > > > From: Norbert Slusarek > > Date: Mon, 23 Nov 2020 21:53:41 +0100 > > Subject: [PATCH RESEND] misc/vmw_vmci: bail out earlier on too big queue allocation > > > > For the allocation of a queue pair in qp_host_alloc_queue() an arbitrary value > > can be passed for produce_size, which can lead to miscalculation of memory we'd > > like to allocate in one take. A warning is triggered at __alloc_pages_nodemask() > > in mm/page_alloc.c:4737 which aborts the false allocation, but it results in a > > VMware machine freezing for an infinite time. > > > > Signed-off-by: Norbert Slusarek > > Thank you for sending a patch with such a detailed analysis and even > including a test case! Yeah agree, very good details! > > > diff --git a/drivers/misc/vmw_vmci/vmci_queue_pair.c b/drivers/misc/vmw_vmci/vmci_queue_pair.c > > index c49065887e8f..997ff32475b2 100644 > > --- a/drivers/misc/vmw_vmci/vmci_queue_pair.c > > +++ b/drivers/misc/vmw_vmci/vmci_queue_pair.c > > @@ -526,6 +526,7 @@ static struct vmci_queue *qp_host_alloc_queue(u64 size) > > struct vmci_queue *queue; > > size_t queue_page_size; > > u64 num_pages; > > + unsigned int order; > > const size_t queue_size = sizeof(*queue) + sizeof(*(queue->kernel_if)); > > > > if (size > SIZE_MAX - PAGE_SIZE) > > @@ -537,6 +538,10 @@ static struct vmci_queue *qp_host_alloc_queue(u64 size) > > > > queue_page_size = num_pages * sizeof(*queue->kernel_if->u.h.page); > > > > + order = get_order(queue_size + queue_page_size); > > + if (order >= MAX_ORDER) > > + return NULL; > > + > > queue = kzalloc(queue_size + queue_page_size, GFP_KERNEL); > > Calling kzalloc() with that user-provided size may still not be a great > idea, and MAX_ORDER is probably more than anyone ever needs here > (I don't know what the interface is needed for, but usually it is). > > If there is a reasonable upper bound smaller than MAX_ORDER, I > would suggest using that. It might also be helpful to use kvzalloc()/kvfree() > in this case, which can return an arbitrary number of pages > and suffers less from fragmentation. I don't know well vmw_vmci, but I took a brief look, and I saw that there is a macro (VMCI_MAX_GUEST_QP_MEMORY) used in vmci_qpair_alloc(), I'm not sure if we can use the same macro, but maybe something similar. Honestly I don't know where that limit comes from, maybe it was chosen as an arbitrary and reasonable value but I suggest to check if we can reuse the same macro here with some adjustments. I think in some way that limit is related to the max memory that the host should allocate. @Jorgen any thought? Thanks, Stefano > > Note that both kzalloc() and kvzalloc() will fail for much smaller > sizes if the kernel is low on memory, so that might have the same > problem. > > Arnd >