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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26E1EC433F5 for ; Thu, 2 Dec 2021 03:46:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4C1F06B0074; Wed, 1 Dec 2021 22:46:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4701B6B0075; Wed, 1 Dec 2021 22:46:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 337EC6B007B; Wed, 1 Dec 2021 22:46:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0162.hostedemail.com [216.40.44.162]) by kanga.kvack.org (Postfix) with ESMTP id 218CA6B0074 for ; Wed, 1 Dec 2021 22:46:14 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id C6E767FAC6 for ; Thu, 2 Dec 2021 03:46:03 +0000 (UTC) X-FDA: 78871465806.25.2BAC596 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) by imf29.hostedemail.com (Postfix) with ESMTP id 073389000094 for ; Thu, 2 Dec 2021 03:46:02 +0000 (UTC) Received: by mail-pj1-f53.google.com with SMTP id p18-20020a17090ad31200b001a78bb52876so1374756pju.3 for ; Wed, 01 Dec 2021 19:46:03 -0800 (PST) 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=U18hQOa1FAfUqBSBf0IHqKmw+XLYtAfpFzE91QsNYTg=; b=VvjoFCNgO7dQ9CmQz7jR1i383nSaFiLDDqkA4qXWNkaRz+ZKFTc5s2NrDuI/mZjgXl bAeS23+4XrAMvC6nEfq3CY+2iyeHbNCwpdpTesLleGSRqvwfSafC8Idh7EJfa8cS5T7b gJtxe3CKz0R44ZuyiBvczOezUDv5aFYt04Puk= 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=U18hQOa1FAfUqBSBf0IHqKmw+XLYtAfpFzE91QsNYTg=; b=6H5d5hXZqD226YfbQgfAt+uB9qi/eCv35U0jAy8zApVFgM8TAzfO4RvWt5z7mMAylR t1zpAZDVWSHkiePTPbJuVBWyHFGn1EKD8pW3mZTvU5RrVXz0Qty5TkU8kghl790KaPeu 87G/ND1zs+ZsyjY4yi1j6dabi9DzjJNQ+TFGoDOXJEA8QIDnkmgcE5DkVeHxyigIspV7 XL92pZ++ftQlZ6DK1JLjggHcIqkKVpuAQkUJ9p4E+9nOsGNHXdtl95sBmMmPfOv73/7Q YXljsqtxlGlQWQrkbTs2IpUrr7rX7bcTneDYJdjsR8swGDpuJV+5rPUCO/RiKHSUsjNG QjPw== X-Gm-Message-State: AOAM5331mTdEeFln2IbzZ9s6VAja7lat4dJj6hH1JIis+g9mqC6i000f J64j9ZzIGcscboAzRq0gxZUWAA== X-Google-Smtp-Source: ABdhPJzcpXGaQ+4r1kHUtZXRZ3AUdxl+eWulvIrGiLca5ySRdpf1O1iM5DM7H84EO2vs9Jxci2X3cA== X-Received: by 2002:a17:90a:c297:: with SMTP id f23mr3058243pjt.138.1638416762323; Wed, 01 Dec 2021 19:46:02 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id b15sm1286104pfv.48.2021.12.01.19.46.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Dec 2021 19:46:01 -0800 (PST) Date: Wed, 1 Dec 2021 19:46:01 -0800 From: Kees Cook To: Bixuan Cui Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, torvalds@linux-foundation.org, leon@kernel.org, akpm@linux-foundation.org, w@1wt.eu Subject: Re: [PATCH -next] mm: delete oversized WARN_ON() in kvmalloc() calls Message-ID: <202112011944.28EF2FC44@keescook> References: <1638410784-48646-1-git-send-email-cuibixuan@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1638410784-48646-1-git-send-email-cuibixuan@linux.alibaba.com> X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 073389000094 X-Stat-Signature: f4iegaa7seu6a9yniics1bxc4cweqpxg Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=VvjoFCNg; spf=pass (imf29.hostedemail.com: domain of keescook@chromium.org designates 209.85.216.53 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-HE-Tag: 1638416762-828377 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Dec 02, 2021 at 10:06:24AM +0800, Bixuan Cui wrote: > Delete the WARN_ON() and return NULL directly for oversized parameter > in kvmalloc() calls. > Also add unlikely(). > > Fixes: 7661809d493b ("mm: don't allow oversized kvmalloc() calls") > Signed-off-by: Bixuan Cui > --- > There are a lot of oversize warnings and patches about kvmalloc() calls > recently. Maybe these warnings are not very necessary. It seems these warnings are working, yes? i.e. we're finding the places where giant values are coming in? > > https://lore.kernel.org/all/YadOjJXMTjP85MQx@unreal > > The example of size check in __do_kmalloc_node(): > __do_kmalloc_node(size_t size, gfp_t flags, int node, unsigned long caller) > { > struct kmem_cache *cachep; > void *ret; > > if (unlikely(size > KMALLOC_MAX_CACHE_SIZE)) > return NULL; > cachep = kmalloc_slab(size, flags); > > mm/util.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/mm/util.c b/mm/util.c > index 7e433690..d26f19c 100644 > --- a/mm/util.c > +++ b/mm/util.c > @@ -587,7 +587,7 @@ void *kvmalloc_node(size_t size, gfp_t flags, int node) > return ret; > > /* Don't even allow crazy sizes */ > - if (WARN_ON_ONCE(size > INT_MAX)) > + if (unlikely(size > INT_MAX)) > return NULL; If we're rejecting the value, then it's still a pathological size, so shouldn't the check be happening in the caller? I think the WARN is doing exactly what it was supposed to do: find the places where bad sizes can reach vmalloc. -Kees > > return __vmalloc_node(size, 1, flags, node, > -- > 1.8.3.1 > -- Kees Cook