From mboxrd@z Thu Jan 1 00:00:00 1970 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B42CDC433EF for ; Mon, 18 Oct 2021 15:10:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9712960F94 for ; Mon, 18 Oct 2021 15:10:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232201AbhJRPMl (ORCPT ); Mon, 18 Oct 2021 11:12:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233513AbhJRPMP (ORCPT ); Mon, 18 Oct 2021 11:12:15 -0400 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1F79C06176A for ; Mon, 18 Oct 2021 08:10:01 -0700 (PDT) Received: by mail-pg1-x529.google.com with SMTP id j190so9813472pgd.0 for ; Mon, 18 Oct 2021 08:10:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=7SQVc3XGar2veUYFqfy1yTOkYOpuBUWxEVpjFYKTxRc=; b=ZNn/ptCtas1mjTvGhvKxYKuEt8b+6sU57LzMgeEjbiLRpiI6Cr0dLT/KOsePcjVD0G a1U14//mjKeFDTufq1b9GGdYrJiSx+TSwKupby2HSpX+HkRts2zDAqa4bG533G7d36m4 RfFwgo6RwbESGVPkx6EiftVuu/whiS1fftuO4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=7SQVc3XGar2veUYFqfy1yTOkYOpuBUWxEVpjFYKTxRc=; b=yqiuqgqUgGAYLltDMDOgNM2WpU0Yc8MFhHFC9o/mT9MmGzQfgzFRkuYQV2liN+Ec8I jAmSxUGuIHYk979nM3B9ZHNVbVrrIkW5jhA92b3LdBDbGnKFk2IYhfxyzUk03uVc0GRp j1pOS2d5UGJxRSA56GYnyW4AB4QVo6isYDfhykWXnhk4XuUoVkQOhFmFKjnqGcoNvVKp ORQfN8qvVyKPiKTzGzjvu7A8CLvuhtsW+g6YeqC1GfD0721mU7afJwtSulYe/hF+LP82 rARHRDurZdPyCbVXEY1pOrgYqif6S55FT1zqQMkD1h/+pUsumvUizhbl3mKHLm+jTRKp 4I2w== X-Gm-Message-State: AOAM531jR0rd8g7EN6keqkitoN39tfvU99zu9OWD6A3QsGWJNgI0Js88 iTINEU4gPi9gkHVP2HsFaa99dw== X-Google-Smtp-Source: ABdhPJzoyK7RvflmQ+QSU83OWv9SX8/m+Djcb/uQZFAAsFqxaYAFYtzIE6wJc6P2mrSKwTFFKJocxw== X-Received: by 2002:a05:6a00:1901:b0:44b:e041:f07f with SMTP id y1-20020a056a00190100b0044be041f07fmr29295794pfi.52.1634569801041; Mon, 18 Oct 2021 08:10:01 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id f11sm13169823pgv.76.2021.10.18.08.10.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Oct 2021 08:10:00 -0700 (PDT) Date: Mon, 18 Oct 2021 08:09:59 -0700 From: Kees Cook To: Paolo Bonzini Cc: torvalds@linux-foundation.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, seanjc@google.com, Willy Tarreau , syzbot+e0de2333cbf95ea473e8@syzkaller.appspotmail.com Subject: Re: [PATCH] mm: allow huge kvmalloc() calls if they're accounted to memcg Message-ID: <202110180809.66AE562E97@keescook> References: <20211016065130.166128-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211016065130.166128-1-pbonzini@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Oct 16, 2021 at 02:51:30AM -0400, Paolo Bonzini wrote: > Commit 7661809d493b ("mm: don't allow oversized kvmalloc() calls") > restricted memory allocation with 'kvmalloc()' to sizes that fit > in an 'int', to protect against trivial integer conversion issues. > > However, the WARN triggers with KVM, when it allocates ancillary page > data whose size essentially depends on whatever userspace has passed to > the KVM_SET_USER_MEMORY_REGION ioctl. The warnings are easily raised by > syzkaller, but the largest allocation that KVM can do is 8 bytes per page > of guest memory; therefore, a 1 TiB memslot will cause a warning even > outside fuzzing, and those allocations are known to happen in the wild. > Google for example already has VMs that create 1.5tb memslots (12tb of > total guest memory spread across 8 virtual NUMA nodes). > > Use memcg accounting as evidence that the crazy large allocations are > expected---in which case, it is indeed a good idea to have them > properly accounted---and exempt them from the warning. Will memcg always have a "sane" upper bound? If so, yeah, this seems a better solution than dropping the WARN completely. :) Reviewed-by: Kees Cook -Kees > > Cc: Willy Tarreau > Cc: Kees Cook > Cc: Linus Torvalds > Reported-by: syzbot+e0de2333cbf95ea473e8@syzkaller.appspotmail.com > Signed-off-by: Paolo Bonzini > --- > Linus, what do you think of this? It is a bit of a hack, > but the reasoning in the commit message does make at least > some sense. > > The alternative would be to just use __vmalloc in KVM, and add > __vcalloc too. The two underscores would suggest that something > "different" is going on, but I wonder what you prefer between > this and having a __vcalloc with 2-3 uses in the whole source. > > mm/util.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/mm/util.c b/mm/util.c > index 499b6b5767ed..31fca4a999c6 100644 > --- a/mm/util.c > +++ b/mm/util.c > @@ -593,8 +593,12 @@ void *kvmalloc_node(size_t size, gfp_t flags, int node) > if (ret || size <= PAGE_SIZE) > return ret; > > - /* Don't even allow crazy sizes */ > - if (WARN_ON_ONCE(size > INT_MAX)) > + /* > + * Don't even allow crazy sizes unless memcg accounting is > + * request. We take that as a sign that huge allocations > + * are indeed expected. > + */ > + if (likely(!(flags & __GFP_ACCOUNT)) && WARN_ON_ONCE(size > INT_MAX)) > return NULL; > > return __vmalloc_node(size, 1, flags, node, > -- > 2.27.0 > -- Kees Cook